Skip to content

Commit b9d0139

Browse files
committed
feat: Changing build attributes for different environment
Closes #639
1 parent 8008734 commit b9d0139

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

src/packager.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,30 @@ export class Packager implements BuildInfo {
5858
async build(): Promise<Map<Platform, Map<String, Target>>> {
5959
const devPackageFile = this.devPackageFile
6060

61+
const extraMetadata = this.options.extraMetadata
62+
6163
this.devMetadata = deepAssign(await readPackageJson(devPackageFile), this.options.devMetadata)
6264
this.appDir = await computeDefaultAppDirectory(this.projectDir, use(this.devMetadata.directories, it => it!.app))
6365

6466
this.isTwoPackageJsonProjectLayoutUsed = this.appDir !== this.projectDir
6567

66-
const appPackageFile = this.projectDir === this.appDir ? devPackageFile : path.join(this.appDir, "package.json")
67-
if (appPackageFile === devPackageFile) {
68-
if (this.options.appMetadata != null) {
69-
this.devMetadata = deepAssign(this.devMetadata, this.options.appMetadata)
68+
const appPackageFile = this.isTwoPackageJsonProjectLayoutUsed ? path.join(this.appDir, "package.json") : devPackageFile
69+
if (this.isTwoPackageJsonProjectLayoutUsed) {
70+
if (extraMetadata != null && extraMetadata.build != null) {
71+
deepAssign(this.devMetadata, {build: extraMetadata.build})
72+
delete extraMetadata.build
7073
}
71-
this.metadata = <any>this.devMetadata
74+
75+
this.metadata = deepAssign(await readPackageJson(appPackageFile), this.options.appMetadata, extraMetadata)
7276
}
7377
else {
74-
this.metadata = deepAssign(await readPackageJson(appPackageFile), this.options.appMetadata)
78+
if (this.options.appMetadata != null) {
79+
deepAssign(this.devMetadata, this.options.appMetadata)
80+
}
81+
if (extraMetadata != null) {
82+
deepAssign(this.devMetadata, extraMetadata)
83+
}
84+
this.metadata = <any>this.devMetadata
7585
}
7686

7787
this.checkMetadata(appPackageFile, devPackageFile)

test/src/BuildTest.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ test.ifDevOrLinuxCi("extra metadata", () => {
216216
const extraMetadata = {
217217
foo: {
218218
bar: 12,
219-
}
219+
},
220+
productName: "NewName"
220221
}
221222
return assertPack("test-app-one", {
222223
targets: Platform.LINUX.createTarget(DIR_TARGET),
@@ -228,18 +229,53 @@ test.ifDevOrLinuxCi("extra metadata", () => {
228229
existingProp: 22,
229230
}
230231
}),
231-
packed: projectDir => {
232-
assertThat(JSON.parse(extractFile(path.join(projectDir, "dist", "linux", "resources", "app.asar"), "package.json").toString())).hasProperties({
232+
packed: async (projectDir) => {
233+
const out = path.join(projectDir, "dist", "linux")
234+
await assertThat(path.join(out, "NewName")).isFile()
235+
assertThat(JSON.parse(extractFile(path.join(out, "resources", "app.asar"), "package.json").toString())).hasProperties({
233236
foo: {
234237
bar: 12,
235238
existingProp: 22,
236239
}
237240
})
238-
return BluebirdPromise.resolve()
239241
}
240242
})
241243
})
242244

245+
test.ifDevOrLinuxCi("extra metadata - two", () => {
246+
const extraMetadata = {
247+
productName: "NewName"
248+
}
249+
return assertPack("test-app", {
250+
targets: Platform.LINUX.createTarget(DIR_TARGET),
251+
extraMetadata: extraMetadata,
252+
}, {
253+
packed: async (projectDir) => {
254+
const out = path.join(projectDir, "dist", "linux")
255+
await assertThat(path.join(out, "NewName")).isFile()
256+
}
257+
})
258+
})
259+
260+
test.ifOsx("extra metadata - override icon", t => t.throws((() => {
261+
const extraMetadata = {
262+
build: {
263+
mac: {
264+
icon: "dev"
265+
}
266+
},
267+
}
268+
return assertPack("test-app", {
269+
targets: Platform.OSX.createTarget(DIR_TARGET),
270+
extraMetadata: extraMetadata,
271+
}, {
272+
packed: async (projectDir) => {
273+
const out = path.join(projectDir, "dist", "linux")
274+
await assertThat(path.join(out, "NewName")).isFile()
275+
}
276+
})
277+
})(), /ENOENT: no such file or directory/))
278+
243279
test.ifOsx("app-executable-deps", () => {
244280
return assertPack("app-executable-deps", {
245281
targets: Platform.current().createTarget(DIR_TARGET),
@@ -275,7 +311,7 @@ test.ifDevOrLinuxCi("smart unpack", () => {
275311
})
276312
})
277313

278-
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.+/))
314+
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.+/))
279315

280316
function allPlatforms(dist: boolean = true): PackagerOptions {
281317
return {

0 commit comments

Comments
 (0)