diff --git a/packages/builder-util/src/api.ts b/packages/builder-util/src/api.ts index 6a0dc432172..3d0f266e9f0 100644 --- a/packages/builder-util/src/api.ts +++ b/packages/builder-util/src/api.ts @@ -8,4 +8,6 @@ export interface PackageBuilder { readonly resourceList: Promise> getTempFile(suffix: string): Promise + + getResource(custom: string | null | undefined, ...names: Array): Promise } \ No newline at end of file diff --git a/packages/builder-util/src/license.ts b/packages/builder-util/src/license.ts index 96376ad1c2e..cb14add53b4 100644 --- a/packages/builder-util/src/license.ts +++ b/packages/builder-util/src/license.ts @@ -23,6 +23,20 @@ export function getLicenseAssets(fileNames: Array, packager: PackageBuil }) } +export async function getNotLocalizedLicenseFiles(custom: string | null | undefined, packager: PackageBuilder): Promise { + const possibleFiles: Array = [] + for (const name of ["license", "eula"]) { + for (const ext of ["rtf", "txt", "html"]) { + possibleFiles.push(`${name}.${ext}`) + possibleFiles.push(`${name.toUpperCase()}.${ext}`) + possibleFiles.push(`${name}.${ext.toUpperCase()}`) + possibleFiles.push(`${name.toUpperCase()}.${ext.toUpperCase()}`) + } + } + + return await packager.getResource(custom, ...possibleFiles) +} + export async function getLicenseFiles(packager: PackageBuilder): Promise> { return getLicenseAssets((await packager.resourceList) .filter(it => { diff --git a/packages/electron-builder/src/options/macOptions.ts b/packages/electron-builder/src/options/macOptions.ts index 04e4dc6f73b..10a1288e69b 100644 --- a/packages/electron-builder/src/options/macOptions.ts +++ b/packages/electron-builder/src/options/macOptions.ts @@ -137,6 +137,11 @@ export interface PkgOptions extends TargetSpecificOptions { * The name of certificate to use when signing. Consider using environment variables [CSC_LINK or CSC_NAME](../code-signing.md) instead of specifying this option. */ readonly identity?: string | null + + /** + * The path to EULA license file. Defaults to `license.txt` or `eula.txt` (or uppercase variants). In addition to `txt, `rtf` and `html` supported (don't forget to use `target="_blank"` for links). + */ + readonly license?: string | null } export interface DmgOptions extends TargetSpecificOptions { diff --git a/packages/electron-builder/src/targets/nsis/nsisLicense.ts b/packages/electron-builder/src/targets/nsis/nsisLicense.ts index f0e7c18d979..7ac6c2d19f2 100644 --- a/packages/electron-builder/src/targets/nsis/nsisLicense.ts +++ b/packages/electron-builder/src/targets/nsis/nsisLicense.ts @@ -1,5 +1,5 @@ import { lcid } from "builder-util/out/langs" -import { getLicenseFiles } from "builder-util/out/license" +import { getLicenseFiles, getNotLocalizedLicenseFiles } from "builder-util/out/license" import * as path from "path" import { WinPackager } from "../../winPackager" import { NsisOptions } from "./nsisOptions" @@ -7,17 +7,7 @@ import { NsisScriptGenerator } from "./nsisScriptGenerator" import { nsisTemplatesDir } from "./nsisUtil" export async function computeLicensePage(packager: WinPackager, options: NsisOptions, scriptGenerator: NsisScriptGenerator, languages: Array): Promise { - const possibleFiles: Array = [] - for (const name of ["license", "eula"]) { - for (const ext of ["rtf", "txt", "html"]) { - possibleFiles.push(`${name}.${ext}`) - possibleFiles.push(`${name.toUpperCase()}.${ext}`) - possibleFiles.push(`${name}.${ext.toUpperCase()}`) - possibleFiles.push(`${name.toUpperCase()}.${ext.toUpperCase()}`) - } - } - - const license = await packager.getResource(options.license, ...possibleFiles) + const license = await getNotLocalizedLicenseFiles(options.license, packager) if (license != null) { let licensePage: Array if (license.endsWith(".html")) { diff --git a/packages/electron-builder/src/targets/pkg.ts b/packages/electron-builder/src/targets/pkg.ts index 589f68e6f35..b3ddf202a2d 100644 --- a/packages/electron-builder/src/targets/pkg.ts +++ b/packages/electron-builder/src/targets/pkg.ts @@ -8,6 +8,7 @@ import { Target } from "../core" import MacPackager from "../macPackager" import { PkgOptions } from "../options/macOptions" import { filterCFBundleIdentifier } from "../packager/mac" +import { getNotLocalizedLicenseFiles } from "builder-util/out/license" const certType = "Developer ID Installer" @@ -19,7 +20,9 @@ export class PkgTarget extends Target { readonly options: PkgOptions = { allowAnywhere: true, allowCurrentUserHome: true, - allowRootDirectory: true, ...this.packager.config.pkg} + allowRootDirectory: true, + ...this.packager.config.pkg, + } constructor(private readonly packager: MacPackager, readonly outDir: string) { super("pkg") @@ -70,6 +73,12 @@ export class PkgTarget extends Target { let distInfo = await readFile(distInfoFile, "utf-8") const insertIndex = distInfo.lastIndexOf("") distInfo = distInfo.substring(0, insertIndex) + ` \n` + distInfo.substring(insertIndex) + + const license = await getNotLocalizedLicenseFiles(options.license, this.packager) + if (license != null) { + distInfo = distInfo.substring(0, insertIndex) + ` \n` + distInfo.substring(insertIndex) + } + debug(distInfo) await writeFile(distInfoFile, distInfo) } diff --git a/test/src/mac/macArchiveTest.ts b/test/src/mac/macArchiveTest.ts index 302f33a249f..0fb28c83ea5 100644 --- a/test/src/mac/macArchiveTest.ts +++ b/test/src/mac/macArchiveTest.ts @@ -6,7 +6,7 @@ import { readFile, symlink } from "fs-extra-p" import * as path from "path" import pathSorter from "path-sort" import { assertThat } from "../helpers/fileAssert" -import { app, createMacTargetTest, getFixtureDir, parseFileList } from "../helpers/packTester" +import { app, copyTestAsset, createMacTargetTest, getFixtureDir, parseFileList } from "../helpers/packTester" test.ifMac("invalid target", () => assertThat(createMacTargetTest(["ttt" as any])()).throws()) @@ -27,6 +27,11 @@ test.ifAll.ifMac("empty installLocation", app({ } }, { signed: false, + projectDirCreated: projectDir => { + return BluebirdPromise.all([ + copyTestAsset("license.txt", path.join(projectDir, "build", "license.txt")), + ]) + }, })) test.ifAll.ifMac("pkg scripts", app({