From b9d01397f22ba9293075d6e8b0952e9478f9f385 Mon Sep 17 00:00:00 2001 From: develar Date: Fri, 12 Aug 2016 17:01:47 +0200 Subject: [PATCH] feat: Changing build attributes for different environment Closes #639 --- src/packager.ts | 22 +++++++++++++++------ test/src/BuildTest.ts | 46 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/packager.ts b/src/packager.ts index c04a8c8d695..3b98d818cd2 100644 --- a/src/packager.ts +++ b/src/packager.ts @@ -58,20 +58,30 @@ export class Packager implements BuildInfo { async build(): Promise>> { const devPackageFile = this.devPackageFile + const extraMetadata = this.options.extraMetadata + this.devMetadata = deepAssign(await readPackageJson(devPackageFile), this.options.devMetadata) this.appDir = await computeDefaultAppDirectory(this.projectDir, use(this.devMetadata.directories, it => it!.app)) this.isTwoPackageJsonProjectLayoutUsed = this.appDir !== this.projectDir - const appPackageFile = this.projectDir === this.appDir ? devPackageFile : path.join(this.appDir, "package.json") - if (appPackageFile === devPackageFile) { - if (this.options.appMetadata != null) { - this.devMetadata = deepAssign(this.devMetadata, this.options.appMetadata) + const appPackageFile = this.isTwoPackageJsonProjectLayoutUsed ? path.join(this.appDir, "package.json") : devPackageFile + if (this.isTwoPackageJsonProjectLayoutUsed) { + if (extraMetadata != null && extraMetadata.build != null) { + deepAssign(this.devMetadata, {build: extraMetadata.build}) + delete extraMetadata.build } - this.metadata = this.devMetadata + + this.metadata = deepAssign(await readPackageJson(appPackageFile), this.options.appMetadata, extraMetadata) } else { - this.metadata = deepAssign(await readPackageJson(appPackageFile), this.options.appMetadata) + if (this.options.appMetadata != null) { + deepAssign(this.devMetadata, this.options.appMetadata) + } + if (extraMetadata != null) { + deepAssign(this.devMetadata, extraMetadata) + } + this.metadata = this.devMetadata } this.checkMetadata(appPackageFile, devPackageFile) diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index d7c6097748c..24da7740502 100755 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -216,7 +216,8 @@ test.ifDevOrLinuxCi("extra metadata", () => { const extraMetadata = { foo: { bar: 12, - } + }, + productName: "NewName" } return assertPack("test-app-one", { targets: Platform.LINUX.createTarget(DIR_TARGET), @@ -228,18 +229,53 @@ test.ifDevOrLinuxCi("extra metadata", () => { existingProp: 22, } }), - packed: projectDir => { - assertThat(JSON.parse(extractFile(path.join(projectDir, "dist", "linux", "resources", "app.asar"), "package.json").toString())).hasProperties({ + packed: async (projectDir) => { + const out = path.join(projectDir, "dist", "linux") + await assertThat(path.join(out, "NewName")).isFile() + assertThat(JSON.parse(extractFile(path.join(out, "resources", "app.asar"), "package.json").toString())).hasProperties({ foo: { bar: 12, existingProp: 22, } }) - return BluebirdPromise.resolve() } }) }) +test.ifDevOrLinuxCi("extra metadata - two", () => { + const extraMetadata = { + productName: "NewName" + } + return assertPack("test-app", { + targets: Platform.LINUX.createTarget(DIR_TARGET), + extraMetadata: extraMetadata, + }, { + packed: async (projectDir) => { + const out = path.join(projectDir, "dist", "linux") + await assertThat(path.join(out, "NewName")).isFile() + } + }) +}) + +test.ifOsx("extra metadata - override icon", t => t.throws((() => { + const extraMetadata = { + build: { + mac: { + icon: "dev" + } + }, + } + return assertPack("test-app", { + targets: Platform.OSX.createTarget(DIR_TARGET), + extraMetadata: extraMetadata, + }, { + packed: async (projectDir) => { + const out = path.join(projectDir, "dist", "linux") + await assertThat(path.join(out, "NewName")).isFile() + } + }) +})(), /ENOENT: no such file or directory/)) + test.ifOsx("app-executable-deps", () => { return assertPack("app-executable-deps", { targets: Platform.current().createTarget(DIR_TARGET), @@ -275,7 +311,7 @@ test.ifDevOrLinuxCi("smart unpack", () => { }) }) -test.ifWinCi("Build MacOS on Windows is not supported", (t: any) => t.throws(assertPack("test-app-one", platform(Platform.MAC)), /Build for MacOS is supported only on MacOS.+/)) +test.ifWinCi("Build MacOS on Windows is not supported", t => t.throws(assertPack("test-app-one", platform(Platform.MAC)), /Build for MacOS is supported only on MacOS.+/)) function allPlatforms(dist: boolean = true): PackagerOptions { return {