Skip to content

Commit

Permalink
feat: added support for shortVersion and shortVersionWindows strings …
Browse files Browse the repository at this point in the history
…in package.json (#4517)
  • Loading branch information
SinusPi authored and develar committed Jan 16, 2020
1 parent beb2729 commit 71726a7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
11 changes: 10 additions & 1 deletion packages/app-builder-lib/src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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}`
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/app-builder-lib/src/options/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>([packager.sign(installerPath), defines.UNINSTALLER_OUT_FILE == null ? Promise.resolve() : unlink(defines.UNINSTALLER_OUT_FILE)])

Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
"--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) {
Expand Down

0 comments on commit 71726a7

Please sign in to comment.