// SPDX-License-Identifier: AGPL-3.0-or-later // Stamps a release version into the installers' metadata before packaging: // node build/set-version.mjs 1.2.3 // (Windows file info and NSIS, the macOS Info.plist, the Linux packages and // build/config.yml). The binary's own version comes from -ldflags main.version. import { readFileSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const version = process.argv[2]?.replace(/^v/, ""); if (!version || !/^\d+\.\d+\.\d+([-.+][0-9A-Za-z.-]+)?$/.test(version)) { console.error("usage: node build/set-version.mjs "); process.exit(1); } // Windows file versions are four numbers; pre-release suffixes are left out. const numeric = version.match(/^\d+\.\d+\.\d+/)[0]; const dir = dirname(fileURLToPath(import.meta.url)); const edits = [ ["config.yml", /(version: )"[^"]*"( # The application version)/, `$1"${version}"$2`], ["windows/info.json", /("file_version": )"[^"]*"/, `$1"${numeric}"`], ["windows/info.json", /("ProductVersion": )"[^"]*"/, `$1"${version}"`], ["windows/nsis/wails_tools.nsh", /(!define INFO_PRODUCTVERSION )"[^"]*"/, `$1"${numeric}"`], ["linux/nfpm/nfpm.yaml", /^version: "[^"]*"/m, `version: "${version}"`], [ "darwin/Info.plist", /(CFBundleShortVersionString<\/key>\s*)[^<]*(<\/string>)/, `$1${version}$2`, ], ["darwin/Info.plist", /(CFBundleVersion<\/key>\s*)[^<]*(<\/string>)/, `$1${numeric}$2`], ]; for (const [file, pattern, replacement] of edits) { const path = join(dir, file); const before = readFileSync(path, "utf8"); const after = before.replace(pattern, replacement); if (after === before && !before.match(pattern)) { console.error(`${file}: version field not found`); process.exit(1); } writeFileSync(path, after); } console.log(`version ${version} set`);