Skip to content

Commit

Permalink
fix: copy extra resources to NuGet package
Browse files Browse the repository at this point in the history
Closes #230
  • Loading branch information
develar committed Mar 24, 2016
1 parent 274c47f commit 65d8126
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 116 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"bluebird": "^3.3.4",
"command-line-args": "^2.1.6",
"electron-packager-tf": "^5.2.4-beta.1",
"electron-winstaller-fixed": "^2.0.6-beta.2",
"electron-winstaller-fixed": "^2.0.6-beta.4",
"fs-extra": "^0.26.7",
"fs-extra-p": "^0.1.0",
"globby": "^4.0.0",
Expand All @@ -76,6 +76,7 @@
"ava-tf": "^0.12.4-beta.6",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-es2015-parameters": "^6.7.0",
"decompress-zip": "^0.2.0",
"electron-download": "^2.1.0",
"json-parse-helpfulerror": "^1.0.3",
"path-sort": "^0.1.0",
Expand Down
6 changes: 3 additions & 3 deletions src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export default class MacPackager extends PlatformPackager<OsXBuildOptions> {
return Platform.OSX
}

async pack(platform: string, outDir: string, appOutDir: string, arch: string): Promise<any> {
await super.pack(platform, outDir, appOutDir, arch)
let codeSigningInfo = await this.codeSigningInfo
async pack(outDir: string, appOutDir: string, arch: string): Promise<any> {
await super.pack(outDir, appOutDir, arch)
const codeSigningInfo = await this.codeSigningInfo
return await this.signMac(path.join(appOutDir, this.appName + ".app"), codeSigningInfo)
}

Expand Down
14 changes: 7 additions & 7 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ export interface PlatformSpecificBuildOptions {
}

export class Platform {
public static OSX = new Platform("osx", "osx")
public static LINUX = new Platform("linux", "linux")
public static WINDOWS = new Platform("windows", "win")
public static OSX = new Platform("osx", "osx", "darwin")
public static LINUX = new Platform("linux", "linux", "linux")
public static WINDOWS = new Platform("windows", "win", "win32")

constructor(public name: string, public buildConfigurationKey: string) {
constructor(public name: string, public buildConfigurationKey: string, public nodeName: string) {
}

toString() {
Expand All @@ -82,9 +82,9 @@ export class Platform {

public static fromNodePlatform(name: string): Platform {
switch (name) {
case "darwin": return Platform.OSX
case "win32": return Platform.WINDOWS
case "linux": return Platform.LINUX
case Platform.OSX.nodeName: return Platform.OSX
case Platform.WINDOWS.nodeName: return Platform.WINDOWS
case Platform.LINUX.nodeName: return Platform.LINUX
}

throw new Error("Unknown platform: " + name)
Expand Down
2 changes: 1 addition & 1 deletion src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Packager implements BuildInfo {
const outDir = path.join(this.projectDir, "dist")
// electron-packager uses productName in the directory name
const appOutDir = path.join(outDir, helper.appName + "-" + platform + "-" + arch)
await helper.pack(platform, outDir, appOutDir, arch)
await helper.pack(outDir, appOutDir, arch)
if (this.options.dist) {
distTasks.push(helper.packageInDistributableFormat(outDir, appOutDir, arch))
}
Expand Down
40 changes: 26 additions & 14 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
})
}

async pack(platform: string, outDir: string, appOutDir: string, arch: string): Promise<any> {
async pack(outDir: string, appOutDir: string, arch: string): Promise<any> {
await this.doPack(outDir, arch)
await this.copyExtraResources(appOutDir, arch)
}

protected async doPack(outDir: string, arch: string) {
const version = this.metadata.version
let buildVersion = version
const buildNumber = process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM
Expand All @@ -103,7 +108,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
dir: this.info.appDir,
out: outDir,
name: this.appName,
platform: platform,
platform: this.platform.nodeName,
arch: arch,
version: this.info.electronVersion,
icon: path.join(this.buildResourcesDir, "icon"),
Expand All @@ -123,11 +128,13 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
delete options.osx
delete options.win
delete options.linux

// this option only for windows-installer
delete options.iconUrl

await pack(options)
}

protected getExtraResources(arch: string): Promise<Array<string>> {
const buildMetadata: any = this.devMetadata.build
let extraResources: Array<string> = buildMetadata == null ? null : buildMetadata.extraResources

Expand All @@ -136,18 +143,23 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
extraResources = extraResources == null ? platformSpecificExtraResources : extraResources.concat(platformSpecificExtraResources)
}

if (extraResources != null) {
const expandedPatterns = extraResources.map(it => it
.replace(/\$\{arch}/g, arch)
.replace(/\$\{os}/g, this.platform.buildConfigurationKey))
await BluebirdPromise.map(await globby(expandedPatterns, {cwd: this.projectDir}), it => {
let resourcesDir = appOutDir
if (platform === "darwin") {
resourcesDir = path.join(resourcesDir, this.appName + ".app", "Contents", "Resources")
}
return copy(path.join(this.projectDir, it), path.join(resourcesDir, it))
})
if (extraResources == null) {
return BluebirdPromise.resolve([])
}

const expandedPatterns = extraResources.map(it => it
.replace(/\$\{arch}/g, arch)
.replace(/\$\{os}/g, this.platform.buildConfigurationKey))
return globby(expandedPatterns, {cwd: this.projectDir})
}

protected async copyExtraResources(appOutDir: string, arch: string): Promise<Array<string>> {
let resourcesDir = appOutDir
if (this.platform === Platform.OSX) {
resourcesDir = path.join(resourcesDir, this.appName + ".app", "Contents", "Resources")
}

return await BluebirdPromise.map(await this.getExtraResources(arch), it => copy(path.join(this.projectDir, it), path.join(resourcesDir, it)))
}

abstract packageInDistributableFormat(outDir: string, appOutDir: string, arch: string): Promise<any>
Expand Down
23 changes: 19 additions & 4 deletions src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface WinBuildOptions extends PlatformSpecificBuildOptions {
export default class WinPackager extends PlatformPackager<WinBuildOptions> {
certFilePromise: Promise<string>

extraNuGetFileSources: Promise<Array<string>>

constructor(info: BuildInfo, cleanupTasks: Array<() => Promise<any>>) {
super(info)

Expand All @@ -46,17 +48,29 @@ export default class WinPackager extends PlatformPackager<WinBuildOptions> {
return Platform.WINDOWS
}

pack(platform: string, outDir: string, appOutDir: string, arch: string): Promise<any> {
async pack(outDir: string, appOutDir: string, arch: string): Promise<any> {
if (this.options.dist) {
const installerOut = WinPackager.computeDistOut(outDir, arch)
log("Removing %s", installerOut)
return BluebirdPromise.all([
super.pack(platform, outDir, appOutDir, arch),
await BluebirdPromise.all([
this.doPack(outDir, arch),
emptyDir(installerOut)
])

let extraResources = await this.copyExtraResources(appOutDir, arch)
if (extraResources.length > 0) {
this.extraNuGetFileSources = BluebirdPromise.map(extraResources, file => {
return stat(file)
.then(it => {
const relativePath = path.relative(appOutDir, file)
const src = it.isDirectory() ? `${relativePath}${path.sep}**` : relativePath
return `<file src="${src}" target="lib\\net45\\${relativePath.replace(/\//g, "\\")}"/>`
})
})
}
}
else {
return super.pack(platform, outDir, appOutDir, arch)
return super.pack(outDir, appOutDir, arch)
}
}

Expand Down Expand Up @@ -105,6 +119,7 @@ export default class WinPackager extends PlatformPackager<WinBuildOptions> {
fixUpPaths: false,
usePackageJson: false,
noMsi: true,
extraFileSpecs: this.extraNuGetFileSources == null ? null : ("\n" + (await this.extraNuGetFileSources).join("\n"))
}, this.customBuildOptions)

try {
Expand Down
Loading

0 comments on commit 65d8126

Please sign in to comment.