diff --git a/packages/app-builder-lib/src/appInfo.ts b/packages/app-builder-lib/src/appInfo.ts index 36e01f7a53..7de4172216 100644 --- a/packages/app-builder-lib/src/appInfo.ts +++ b/packages/app-builder-lib/src/appInfo.ts @@ -8,6 +8,8 @@ import { expandMacro } from "./util/macroExpander" export class AppInfo { readonly description = smarten(this.info.metadata.description || "") readonly version: string + readonly shortVersion: string | undefined + readonly shortVersionWindows: string | undefined readonly buildNumber: string | undefined readonly buildVersion: string @@ -31,6 +33,13 @@ export class AppInfo { } this.buildVersion = buildVersion + if (info.metadata.shortVersion) { + this.shortVersion = info.metadata.shortVersion + } + if (info.metadata.shortVersionWindows) { + this.shortVersionWindows = info.metadata.shortVersionWindows + } + this.productName = info.config.productName || info.metadata.productName || info.metadata.name!! this.productFilename = sanitizeFileName(this.productName) } @@ -121,7 +130,7 @@ export class AppInfo { } const info = await this.info.repositoryInfo - return info == null || info.type !== "github" ? null : `https://${info.domain}/${info.user}/${info.project}` + return info == null || info.type !== "github" ? null : `https://${info.domain}/${info.user}/${info.project}` } } diff --git a/packages/app-builder-lib/src/options/metadata.ts b/packages/app-builder-lib/src/options/metadata.ts index 0e3c5e69c2..ee9724ef1a 100644 --- a/packages/app-builder-lib/src/options/metadata.ts +++ b/packages/app-builder-lib/src/options/metadata.ts @@ -41,6 +41,10 @@ export interface Metadata { /** @private */ readonly version?: string /** @private */ + readonly shortVersion?: string | null + /** @private */ + readonly shortVersionWindows?: string | null + /** @private */ readonly productName?: string | null /** @private */ readonly main?: string | null diff --git a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts index 6cf150e745..8c90daef3d 100644 --- a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts @@ -265,8 +265,21 @@ export class NsisTarget extends Target { return } + // prepare short-version variants of defines and commands, to make an uninstaller that doesn't differ much from the previous one + const defines_uninstaller: any = { ...defines } + const commands_uninstaller: any = { ...commands} + if (appInfo.shortVersion != null) { + defines_uninstaller.VERSION = appInfo.shortVersion + commands_uninstaller.VIProductVersion = appInfo.shortVersionWindows + commands_uninstaller.VIAddVersionKey = this.computeVersionKey(true) + } + const sharedHeader = await this.computeCommonInstallerScriptHeader() - const script = isPortable ? await readFile(path.join(nsisTemplatesDir, "portable.nsi"), "utf8") : await this.computeScriptAndSignUninstaller(defines, commands, installerPath, sharedHeader) + const script = isPortable ? await readFile(path.join(nsisTemplatesDir, "portable.nsi"), "utf8") : await this.computeScriptAndSignUninstaller(defines_uninstaller, commands_uninstaller, installerPath, sharedHeader) + + // copy outfile name into main options, as the computeScriptAndSignUninstaller function was kind enough to add important data to temporary defines. + defines.UNINSTALLER_OUT_FILE = defines_uninstaller.UNINSTALLER_OUT_FILE + await this.executeMakensis(defines, commands, sharedHeader + await this.computeFinalScript(script, true)) await Promise.all([packager.sign(installerPath), defines.UNINSTALLER_OUT_FILE == null ? Promise.resolve() : unlink(defines.UNINSTALLER_OUT_FILE)]) @@ -355,7 +368,7 @@ export class NsisTarget extends Target { return script } - private computeVersionKey() { + private computeVersionKey(short: boolean = false) { // Error: invalid VIProductVersion format, should be X.X.X.X // so, we must strip beta const localeId = this.options.language || "1033" @@ -367,6 +380,10 @@ export class NsisTarget extends Target { `/LANG=${localeId} FileDescription "${appInfo.description}"`, `/LANG=${localeId} FileVersion "${appInfo.buildVersion}"`, ] + if (short) { + versionKey[1] = `/LANG=${localeId} ProductVersion "${appInfo.shortVersion}"` + versionKey[4] = `/LANG=${localeId} FileVersion "${appInfo.shortVersion}"` + } use(this.packager.platformSpecificBuildOptions.legalTrademarks, it => versionKey.push(`/LANG=${localeId} LegalTrademarks "${it}"`)) use(appInfo.companyName, it => versionKey.push(`/LANG=${localeId} CompanyName "${it}"`)) return versionKey diff --git a/packages/app-builder-lib/src/winPackager.ts b/packages/app-builder-lib/src/winPackager.ts index 71e36861ab..d7ad40ad5d 100644 --- a/packages/app-builder-lib/src/winPackager.ts +++ b/packages/app-builder-lib/src/winPackager.ts @@ -265,8 +265,8 @@ export class WinPackager extends PlatformPackager { "--set-version-string", "FileDescription", appInfo.productName, "--set-version-string", "ProductName", appInfo.productName, "--set-version-string", "LegalCopyright", appInfo.copyright, - "--set-file-version", appInfo.buildVersion, - "--set-product-version", appInfo.getVersionInWeirdWindowsForm(), + "--set-file-version", appInfo.shortVersion || appInfo.buildVersion, + "--set-product-version", appInfo.shortVersionWindows || appInfo.getVersionInWeirdWindowsForm(), ] if (internalName != null) {