Skip to content

Commit

Permalink
feat: Changing build attributes for different environment
Browse files Browse the repository at this point in the history
Closes #639
  • Loading branch information
develar committed Aug 12, 2016
1 parent 8008734 commit b9d0139
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
22 changes: 16 additions & 6 deletions src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,30 @@ export class Packager implements BuildInfo {
async build(): Promise<Map<Platform, Map<String, Target>>> {
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 = <any>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 = <any>this.devMetadata
}

this.checkMetadata(appPackageFile, devPackageFile)
Expand Down
46 changes: 41 additions & 5 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b9d0139

Please sign in to comment.