diff --git a/packages/electron-builder-lib/src/configuration.ts b/packages/electron-builder-lib/src/configuration.ts index 9b87b0cb562..00027226d1a 100644 --- a/packages/electron-builder-lib/src/configuration.ts +++ b/packages/electron-builder-lib/src/configuration.ts @@ -155,7 +155,7 @@ export interface Configuration extends PlatformSpecificBuildOptions { * Whether to fail if the application is not signed (to prevent unsigned app if code signing configuration is not correct). * @default false */ - readonly forceCodeSigning?: boolean + readonly ?: boolean /** * The version of muon you are packaging for. diff --git a/packages/electron-builder-lib/src/macPackager.ts b/packages/electron-builder-lib/src/macPackager.ts index 8dc56819abb..904d247ec1c 100644 --- a/packages/electron-builder-lib/src/macPackager.ts +++ b/packages/electron-builder-lib/src/macPackager.ts @@ -1,21 +1,25 @@ import BluebirdPromise from "bluebird-lst" import { Arch, AsyncTaskManager, exec, InvalidConfigurationError, log } from "builder-util" import { signAsync, SignOptions } from "electron-osx-sign" -import { ensureDir } from "fs-extra-p" +import { ensureDir, readdir, remove } from "fs-extra-p" import { Lazy } from "lazy-val" import * as path from "path" import { deepAssign } from "read-config-file/out/deepAssign" import * as semver from "semver" +import { AsarIntegrity } from "asar-integrity" +import { asArray } from "builder-util-runtime/out" import { AppInfo } from "./appInfo" import { appleCertificatePrefixes, CertType, CodeSigningInfo, createKeychain, findIdentity, Identity, isSignAllowed, reportError } from "./codeSign" import { DIR_TARGET, Platform, Target } from "./core" import { MacConfiguration, MasConfiguration } from "./options/macOptions" import { Packager } from "./packager" +import { createMacApp } from "./packager/mac" import { PlatformPackager } from "./platformPackager" import { ArchiveTarget } from "./targets/ArchiveTarget" import { DmgTarget } from "./targets/dmg" import { PkgTarget, prepareProductBuildArgs } from "./targets/pkg" import { createCommonTarget, NoOpTarget } from "./targets/targetFactory" +import { CONCURRENCY } from "builder-util/out/fs" export default class MacPackager extends PlatformPackager { readonly codeSigningInfo: Promise @@ -255,6 +259,30 @@ export default class MacPackager extends PlatformPackager { public getElectronDestinationDir(appOutDir: string) { return path.join(appOutDir, this.electronDistMacOsAppName) } + + protected async beforeCopyExtraFiles(appOutDir: string, asarIntegrity: AsarIntegrity | null): Promise { + await createMacApp(this, appOutDir, asarIntegrity) + + const wantedLanguages = asArray(this.platformSpecificBuildOptions.electronLanguages) + if (wantedLanguages == null) { + return + } + + // noinspection SpellCheckingInspection + const langFileExt = ".lproj" + const resourcesDir = this.getResourcesDir(appOutDir) + await BluebirdPromise.map(readdir(resourcesDir), file => { + if (!file.endsWith(langFileExt)) { + return + } + + const language = file.substring(0, file.length - langFileExt.length) + if (!wantedLanguages.includes(language)) { + return remove(path.join(resourcesDir, file)) + } + return + }, CONCURRENCY) + } } function getCertificateType(isMas: boolean, isDevelopment: boolean): CertType { diff --git a/packages/electron-builder-lib/src/options/macOptions.ts b/packages/electron-builder-lib/src/options/macOptions.ts index 6fc6fec1363..501325298ea 100644 --- a/packages/electron-builder-lib/src/options/macOptions.ts +++ b/packages/electron-builder-lib/src/options/macOptions.ts @@ -93,6 +93,11 @@ export interface MacConfiguration extends PlatformSpecificBuildOptions { * 2.16.0 files */ readonly electronUpdaterCompatibility?: string | null + + /** + * The electron locales. By default Electron locales used as is. + */ + readonly electronLanguages?: Array | string } /** diff --git a/packages/electron-builder-lib/src/platformPackager.ts b/packages/electron-builder-lib/src/platformPackager.ts index 5ec88a0a409..00bbd551915 100644 --- a/packages/electron-builder-lib/src/platformPackager.ts +++ b/packages/electron-builder-lib/src/platformPackager.ts @@ -9,6 +9,7 @@ import { Lazy } from "lazy-val" import { Minimatch } from "minimatch" import * as path from "path" import { deepAssign } from "read-config-file/out/deepAssign" +import { AsarIntegrity } from "asar-integrity" import { AppInfo } from "./appInfo" import { checkFileInArchive } from "./asar/asarFileChecker" import { AsarPackager } from "./asar/asarUtil" @@ -18,7 +19,6 @@ import { createTransformer, isElectronCompileUsed } from "./fileTransformer" import { AfterPackContext, AsarOptions, Configuration, FileAssociation, PlatformSpecificBuildOptions } from "./index" import { Packager } from "./packager" import { unpackElectron, unpackMuon } from "./packager/dirPackager" -import { createMacApp } from "./packager/mac" import { PackagerOptions } from "./packagerApi" import { getAppBuilderTool } from "./targets/tools" import { copyAppFiles } from "./util/appFileCopier" @@ -198,11 +198,7 @@ export abstract class PlatformPackager } await taskManager.awaitTasks() - - if (platformName === "darwin" || platformName === "mas") { - await createMacApp(this, appOutDir, asarOptions == null ? null : await computeData(resourcesPath, asarOptions.externalAllowed ? {externalAllowed: true} : null)) - } - + await this.beforeCopyExtraFiles(appOutDir, asarOptions == null ? null : await computeData(resourcesPath, asarOptions.externalAllowed ? {externalAllowed: true} : null)) await BluebirdPromise.each([extraResourceMatchers, extraFileMatchers], it => copyFiles(it)) if (this.info.cancellationToken.cancelled) { @@ -215,6 +211,10 @@ export abstract class PlatformPackager await this.info.afterSign(packContext) } + protected async beforeCopyExtraFiles(appOutDir: string, asarIntegrity: AsarIntegrity | null) { + // empty impl + } + private copyAppFiles(taskManager: AsyncTaskManager, asarOptions: AsarOptions | null, resourcePath: string, outDir: string, platformSpecificBuildOptions: DC, excludePatterns: Array, macroExpander: ((it: string) => string)) { const appDir = this.info.appDir const config = this.config @@ -256,7 +256,7 @@ export abstract class PlatformPackager } protected signApp(packContext: AfterPackContext): Promise { - return BluebirdPromise.resolve() + return Promise.resolve() } async getIconPath(): Promise { diff --git a/test/out/mac/__snapshots__/macPackagerTest.js.snap b/test/out/mac/__snapshots__/macPackagerTest.js.snap index 3827c64c667..047512ddceb 100644 --- a/test/out/mac/__snapshots__/macPackagerTest.js.snap +++ b/test/out/mac/__snapshots__/macPackagerTest.js.snap @@ -162,3 +162,14 @@ Object { ], } `; + +exports[`two-package 2`] = ` +Array [ + "TestApp.icns", + "app-update.yml", + "app.asar", + "bn.lproj", + "electron.asar", + "en.lproj", +] +`; diff --git a/test/src/mac/macPackagerTest.ts b/test/src/mac/macPackagerTest.ts index e54c0b5b099..c2c40d8d1f1 100644 --- a/test/src/mac/macPackagerTest.ts +++ b/test/src/mac/macPackagerTest.ts @@ -1,6 +1,6 @@ import { copyOrLinkFile } from "builder-util/out/fs" import { createTargets, DIR_TARGET, Platform } from "electron-builder" -import { readJson } from "fs-extra-p" +import { readdir, readJson } from "fs-extra-p" import * as path from "path" import { assertThat } from "../helpers/fileAssert" import { app, appThrows, assertPack, convertUpdateInfo, platform } from "../helpers/packTester" @@ -13,12 +13,16 @@ test.ifMac.ifAll("two-package", () => assertPack("test-app", { }, mac: { electronUpdaterCompatibility: ">=2.16", + electronLanguages: ["bn", "en"] }, //tslint:disable-next-line:no-invalid-template-strings artifactName: "${name}-${version}-${os}.${ext}", }, }, { signed: true, + checkMacApp: async appDir => { + expect((await readdir(path.join(appDir, "Contents", "Resources"))).filter(it => !it.startsWith("."))).toMatchSnapshot() + }, })) test.ifMac("one-package", app({