): Array it instanceof Platform ? it : Platform.fromString(it))
}
}
+
+function checkConflictingOptions(options: any) {
+ for (let name of ["all", "out", "tmpdir", "version", "platform", "dir", "arch"]) {
+ if (name in options) {
+ throw new Error(`Option ${name} is ignored, do not specify it.`)
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/platformPackager.ts b/src/platformPackager.ts
index fa1e30d1b91..32108047c0f 100644
--- a/src/platformPackager.ts
+++ b/src/platformPackager.ts
@@ -10,6 +10,7 @@ import { statOrNull, use } from "./util"
import { Packager } from "./packager"
import deepAssign = require("deep-assign")
import { statFile } from "asar"
+import ElectronPackagerOptions = ElectronPackager.ElectronPackagerOptions
//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")
@@ -106,18 +107,20 @@ export abstract class PlatformPackager
})
}
- async pack(outDir: string, arch: string): Promise {
+ pack(outDir: string, arch: string, postAsyncTasks: Array>): Promise {
const appOutDir = this.computeAppOutDir(outDir, arch)
- await this.doPack(outDir, appOutDir, arch)
- await this.copyExtraResources(appOutDir, arch)
- return appOutDir
+ return this.doPack(this.computePackOptions(outDir, arch), outDir, appOutDir, arch, postAsyncTasks)
}
- protected beforePack(options: any): void {
- // to override
+ protected async doPack(options: ElectronPackagerOptions, outDir: string, appOutDir: string, arch: string, postAsyncTasks: Array> = null) {
+ await this.packApp(options, appOutDir)
+ await this.copyExtraResources(appOutDir, arch)
+ if (postAsyncTasks != null && this.options.dist) {
+ postAsyncTasks.push(this.packageInDistributableFormat(outDir, appOutDir, arch))
+ }
}
- protected async doPack(outDir: string, appOutDir: string, arch: string): Promise {
+ protected computePackOptions(outDir: string, arch: string): ElectronPackagerOptions {
const version = this.metadata.version
let buildVersion = version
const buildNumber = this.computeBuildNumber()
@@ -125,8 +128,6 @@ export abstract class PlatformPackager
buildVersion += "." + buildNumber
}
- checkConflictingOptions(this.devMetadata.build)
-
const options = deepAssign({
dir: this.info.appDir,
out: outDir,
@@ -153,8 +154,10 @@ export abstract class PlatformPackager
delete options.linux
// this option only for windows-installer
delete options.iconUrl
+ return options
+ }
- this.beforePack(options)
+ protected async packApp(options: ElectronPackagerOptions, appOutDir: string): Promise {
await pack(options)
await this.sanityCheckPackage(appOutDir, options.asar)
}
@@ -186,7 +189,7 @@ export abstract class PlatformPackager
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
+ protected abstract packageInDistributableFormat(outDir: string, appOutDir: string, arch: string): Promise
protected async computePackageUrl(): Promise {
const url = this.metadata.homepage || this.devMetadata.homepage
@@ -247,17 +250,18 @@ export abstract class PlatformPackager
}
}
-function checkConflictingOptions(options: any) {
- for (let name of ["all", "out", "tmpdir", "version", "platform", "dir", "arch"]) {
- if (name in options) {
- throw new Error(`Option ${name} is ignored, do not specify it.`)
- }
- }
-}
-
export interface ArtifactCreated {
readonly file: string
readonly artifactName?: string
readonly platform: Platform
+}
+
+export function normalizeTargets(targets: Array | string): Array {
+ if (targets == null) {
+ return null
+ }
+ else {
+ return (Array.isArray(targets) ? targets : [targets]).map(it => it.toLowerCase().trim())
+ }
}
\ No newline at end of file
diff --git a/src/winPackager.ts b/src/winPackager.ts
index 73c699fe893..aa7736d4c05 100644
--- a/src/winPackager.ts
+++ b/src/winPackager.ts
@@ -52,19 +52,19 @@ export class WinPackager extends PlatformPackager {
return iconPath
}
- async pack(outDir: string, arch: string): Promise {
+ async pack(outDir: string, arch: string, postAsyncTasks: Array>): Promise {
// we must check icon before pack because electron-packager uses icon and it leads to cryptic error message "spawn wine ENOENT"
await this.iconPath
if (!this.options.dist) {
- return await super.pack(outDir, arch)
+ return await super.pack(outDir, arch, postAsyncTasks)
}
const appOutDir = this.computeAppOutDir(outDir, arch)
const installerOut = computeDistOut(outDir, arch)
log("Removing %s", installerOut)
await BluebirdPromise.all([
- this.doPack(outDir, appOutDir, arch),
+ this.packApp(this.computePackOptions(outDir, arch), appOutDir),
emptyDir(installerOut)
])
@@ -80,11 +80,13 @@ export class WinPackager extends PlatformPackager {
})
}
- return appOutDir
+ if (this.options.dist) {
+ postAsyncTasks.push(this.packageInDistributableFormat(outDir, appOutDir, arch))
+ }
}
- protected async doPack(outDir: string, appOutDir: string, arch: string) {
- await super.doPack(outDir, appOutDir, arch)
+ protected async packApp(options: any, appOutDir: string) {
+ await super.packApp(options, appOutDir)
if (process.platform === "darwin" && this.options.cscLink != null && this.options.cscKeyPassword != null) {
const filename = this.appName + ".exe"
diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts
index 252af639da6..6564c918176 100755
--- a/test/src/BuildTest.ts
+++ b/test/src/BuildTest.ts
@@ -197,7 +197,10 @@ test("invalid platform", (t) => t.throws(assertPack("test-app-one", {
function allPlatformsAndCurrentArch(dist: boolean = true): PackagerOptions {
return {
platform: getPossiblePlatforms(),
- dist: dist
+ dist: dist,
+ // speed up tests
+ cscLink: null,
+ cscInstallerLink: null,
}
}
diff --git a/test/src/helpers/packTester.ts b/test/src/helpers/packTester.ts
index cf7a058fabb..3692e7fbe66 100755
--- a/test/src/helpers/packTester.ts
+++ b/test/src/helpers/packTester.ts
@@ -39,7 +39,7 @@ export async function assertPack(fixtureName: string, packagerOptions: PackagerO
const customTmpDir = process.env.TEST_APP_TMP_DIR
if (useTempDir) {
// non-osx test uses the same dir as osx test, but we cannot share node_modules (because tests executed in parallel)
- const dir = customTmpDir == null ? path.join(tmpdir(), tmpDirPrefix + fixtureName + "-" + tmpDirCounter++) : path.resolve(customTmpDir)
+ const dir = customTmpDir == null ? path.join(tmpdir(), `${tmpDirPrefix}${fixtureName}-${tmpDirCounter++}}`) : path.resolve(customTmpDir)
if (customTmpDir != null) {
console.log("Custom temp dir used: %s", customTmpDir)
}
@@ -105,7 +105,7 @@ async function packAndCheck(projectDir: string, packagerOptions: PackagerOptions
for (let platform of packagerOptions.platform) {
if (platform === Platform.OSX) {
- await checkOsXResult(packager, checkOptions, artifacts.get(Platform.OSX))
+ await checkOsXResult(packager, packagerOptions, checkOptions, artifacts.get(Platform.OSX))
}
else if (platform === Platform.LINUX) {
await checkLinuxResult(projectDir, packager, packagerOptions)
@@ -168,7 +168,7 @@ function parseDebControl(info: string): any {
return metadata
}
-async function checkOsXResult(packager: Packager, checkOptions: AssertPackOptions, artifacts: Array) {
+async function checkOsXResult(packager: Packager, packagerOptions: PackagerOptions, checkOptions: AssertPackOptions, artifacts: Array) {
const productName = getProductName(packager.metadata, packager.devMetadata)
const packedAppDir = path.join(path.dirname(artifacts[0].file), (productName || packager.metadata.name) + ".app")
const info = parsePlist(await readFile(path.join(packedAppDir, "Contents", "Info.plist"), "utf8"))
@@ -179,8 +179,10 @@ async function checkOsXResult(packager: Packager, checkOptions: AssertPackOption
CFBundleVersion: "1.1.0" + "." + (process.env.TRAVIS_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM)
})
- const result = await exec("codesign", ["--verify", packedAppDir])
- assertThat(result[0].toString()).not.match(/is not signed at all/)
+ if (packagerOptions.csaLink != null) {
+ const result = await exec("codesign", ["--verify", packedAppDir])
+ assertThat(result[0].toString()).not.match(/is not signed at all/)
+ }
const actualFiles = artifacts.map(it => path.basename(it.file)).sort()
if (checkOptions != null && checkOptions.expectedContents != null) {
diff --git a/test/src/osxPackagerTest.ts b/test/src/osxPackagerTest.ts
index 63af6045641..cd6f696e3ec 100644
--- a/test/src/osxPackagerTest.ts
+++ b/test/src/osxPackagerTest.ts
@@ -18,13 +18,13 @@ test.ifOsx("two-package", () => assertPack("test-app", {
test.ifOsx("one-package", () => assertPack("test-app-one", platform(Platform.OSX)))
-function createTargetTest(target: string, expectedContents: Array) {
+function createTargetTest(target: Array, expectedContents: Array) {
return () => assertPack("test-app-one", {
platform: [Platform.OSX],
devMetadata: {
build: {
osx: {
- target: [target]
+ target: target
}
}
}
@@ -34,11 +34,12 @@ function createTargetTest(target: string, expectedContents: Array) {
})
}
-test.ifOsx("only dmg", createTargetTest("dmg", ["TestApp-1.1.0.dmg"]))
-test.ifOsx("only zip", createTargetTest("zip", ["TestApp-1.1.0-mac.zip"]))
-test.ifOsx("invalid target", (t: any) => t.throws(createTargetTest("ttt", [])(), "Unknown target: ttt"))
+test.ifOsx("only dmg", createTargetTest(["dmg"], ["TestApp-1.1.0.dmg"]))
+test.ifOsx("only zip", createTargetTest(["zip"], ["TestApp-1.1.0-osx.zip"]))
+test.ifOsx("invalid target", (t: any) => t.throws(createTargetTest(["ttt"], [])(), "Unknown target: ttt"))
-test.ifOsx("mas", createTargetTest("mas", ["TestApp-1.1.0.pkg"]))
+test.ifOsx("mas", createTargetTest(["mas"], ["TestApp-1.1.0.pkg"]))
+test.ifOsx("mas and 7z", createTargetTest(["mas", "7z"], ["TestApp-1.1.0-osx.7z", "TestApp-1.1.0.pkg"]))
// test.ifOsx("no background", (t: any) => assertPack("test-app-one", platform(Platform.OSX), {
// tempDirCreated: projectDir => deleteFile(path.join(projectDir, "build", "background.png"))
@@ -75,12 +76,12 @@ class CheckingOsXPackager extends OsXPackager {
super(info, cleanupTasks)
}
- async pack(outDir: string, arch: string): Promise {
+ async pack(outDir: string, arch: string): Promise {
// skip pack
- return this.computeAppOutDir(outDir, arch)
+ this.effectiveDistOptions = await this.computeEffectiveDistOptions(this.computeAppOutDir(outDir, arch))
}
async packageInDistributableFormat(outDir: string, appOutDir: string, arch: string): Promise {
- this.effectiveDistOptions = await this.computeEffectiveDistOptions(appOutDir)
+ // skip
}
}
\ No newline at end of file
diff --git a/test/src/winPackagerTest.ts b/test/src/winPackagerTest.ts
index b264777bbbb..e7c36c8a864 100755
--- a/test/src/winPackagerTest.ts
+++ b/test/src/winPackagerTest.ts
@@ -78,13 +78,13 @@ class CheckingWinPackager extends WinPackager {
super(info, cleanupTasks)
}
- async pack(outDir: string, arch: string): Promise {
+ async pack(outDir: string, arch: string): Promise {
// skip pack
- return this.computeAppOutDir(outDir, arch)
+ const installerOutDir = computeDistOut(outDir, arch)
+ this.effectiveDistOptions = await this.computeEffectiveDistOptions(this.computeAppOutDir(outDir, arch), installerOutDir)
}
async packageInDistributableFormat(outDir: string, appOutDir: string, arch: string): Promise {
- const installerOutDir = computeDistOut(outDir, arch)
- this.effectiveDistOptions = await this.computeEffectiveDistOptions(appOutDir, installerOutDir)
+ // skip
}
}
\ No newline at end of file
diff --git a/tslint.json b/tslint.json
index 6dfa3d49b6a..0e88b650ef4 100644
--- a/tslint.json
+++ b/tslint.json
@@ -67,5 +67,9 @@
},
"no-debugger": true,
"no-inferrable-types": true,
- "no-shadowed-variable ": true
+ "no-shadowed-variable": true,
+ "no-invalid-this": true,
+ "no-reference": true,
+ "semicolon": "never",
+ "prefer-const": "true"
}
\ No newline at end of file
diff --git a/typings/electron-packager.d.ts b/typings/electron-packager.d.ts
index b6a167332b9..47bb2ee1a33 100644
--- a/typings/electron-packager.d.ts
+++ b/typings/electron-packager.d.ts
@@ -1,115 +1,92 @@
-// Type definitions for electron-packager v5.1.0
-// Project: https://github.com/maxogden/electron-packager
-// Definitions by: Maxime LUCE
-// Definitions: https://github.com/borisyankov/DefinitelyTyped
-
-///
-
declare namespace ElectronPackager {
- /** Electron-packager Options. */
- export interface Options {
- /** The source directory. */
- dir: string;
- /** The application name. */
- name: string;
- /**
- * Allowed values: linux, win32, darwin, all. Not required if `all` is used.
- * Arbitrary combinations of individual platforms are also supported via a comma-delimited string or array of strings.
- */
- platform?: string | string[];
- /** Allowed values: ia32, x64, all Not required if `all` is used. */
- arch?: string;
- /** Electron version (without the "v"). See https://github.com/atom/electron/releases. */
- version: string;
-
- /** Shortcut for `--arch=all --platform=all`. */
- all?: boolean;
- /** The output directory. */
- out?: string;
- /**
- * Currently you must look for conversion tools in order to supply an icon in the format required by the platform:
- * - OS X: `.icns`
- * - Windows: `.ico`
- *
- * For Linux builds, this option is not required, as the dock/window list icon is set via the icon option in the BrowserWindow contructor.
- * Setting the icon in the file manager is not currently supported.
- *
- * If the file extension is omitted, it is auto-completed to the correct extension based on the platform,
- * including when `--platform=all` is in effect.
- */
- icon?: string;
-
- /** The bundle identifier to use in the app plist. */
- "app-bundle-id"?: string;
- /** The release version to set for the app. */
- "app-version"?: string;
- /** The build version to set for the app (OS X only). */
- "build-version"?: string;
- /** The bundle identifier to use in the app helper plist. */
- "helper-bundle-id"?: string;
- /** Object hash of application metadata to embed into the executable (Windows only). */
- "version-string"?: VersionString;
+ /** Electron-packager Options. */
+ export interface ElectronPackagerOptions {
+ /** The source directory. */
+ dir: string;
+ /** The application name. */
+ name: string;
+ /**
+ * Allowed values: linux, win32, darwin, all. Not required if `all` is used.
+ * Arbitrary combinations of individual platforms are also supported via a comma-delimited string or array of strings.
+ */
+ platform?: string | string[];
+ /** Allowed values: ia32, x64, all Not required if `all` is used. */
+ arch?: string;
+ /** Electron version (without the "v"). See https://github.com/atom/electron/releases. */
+ version: string;
- /** The directory of cached electron downloads. Defaults to "$HOME/.electron". */
- cache?: string;
- /** Do not copy files into App whose filenames regex .match this string. */
- ignore?: RegExp;
- /** Runs `npm prune --production` on the app. */
- prune?: boolean;
- /** If output directory for a platform already exists, replaces it rather than skipping it. */
- overwrite?: boolean;
- /** Packages the source code within your app into an archive. */
- asar?: boolean;
- /** Unpacks the files to app.asar.unpacked directory whose filenames regex .match this string. */
- "asar-unpack"?: string;
- /** Should contain the identity to be used when running `codesign` (OS X only). */
- sign?: string;
- }
+ /** Shortcut for `--arch=all --platform=all`. */
+ all?: boolean;
+ /** The output directory. */
+ out?: string;
+ /**
+ * Currently you must look for conversion tools in order to supply an icon in the format required by the platform:
+ * - OS X: `.icns`
+ * - Windows: `.ico`
+ *
+ * For Linux builds, this option is not required, as the dock/window list icon is set via the icon option in the BrowserWindow contructor.
+ * Setting the icon in the file manager is not currently supported.
+ *
+ * If the file extension is omitted, it is auto-completed to the correct extension based on the platform,
+ * including when `--platform=all` is in effect.
+ */
+ icon?: string;
+ /** The bundle identifier to use in the app plist. */
+ "app-bundle-id"?: string;
+ /** The release version to set for the app. */
+ "app-version"?: string;
+ /** The build version to set for the app (OS X only). */
+ "build-version"?: string;
+ /** The bundle identifier to use in the app helper plist. */
+ "helper-bundle-id"?: string;
/** Object hash of application metadata to embed into the executable (Windows only). */
- export interface VersionString {
- CompanyName?: string;
- LegalCopyright?: string;
- FileDescription?: string;
- OriginalFilename?: string;
- FileVersion?: string;
- ProductVersion?: string;
- ProductName?: string;
- InternalName?: string;
- }
+ "version-string"?: VersionString;
- /** Electron-packager done callback. */
- export interface Callback {
- /**
- * Callback wich is called when electron-packager is done.
- *
- * @param err - Contains errors if any.
- * @param appPath - Path to the newly created application.
- */
- (err: Error, appPath: string): void
- }
+ /** The directory of cached electron downloads. Defaults to "$HOME/.electron". */
+ cache?: string;
+ /** Do not copy files into App whose filenames regex .match this string. */
+ ignore?: RegExp;
+ /** Runs `npm prune --production` on the app. */
+ prune?: boolean;
+ /** If output directory for a platform already exists, replaces it rather than skipping it. */
+ overwrite?: boolean;
+ /** Packages the source code within your app into an archive. */
+ asar?: boolean;
+ /** Unpacks the files to app.asar.unpacked directory whose filenames regex .match this string. */
+ "asar-unpack"?: string;
+ /** Should contain the identity to be used when running `codesign` (OS X only). */
+ sign?: string;
+ }
- /** Electron-packager function */
- export interface Packager {
- /**
- * This will:
- * - Find or download the correct release of Electron
- * - Use that version of electron to create a app in /--
- *
- * You should be able to launch the app on the platform you built for. If not, check your settings and try again.
- *
- * @param opts - Options to configure packaging.
- * @param callback - Callback which is called when packaging is done or an error occured.
- */
- (opts: Options, callback: Callback): void;
- }
-}
+ /** Object hash of application metadata to embed into the executable (Windows only). */
+ export interface VersionString {
+ CompanyName?: string;
+ LegalCopyright?: string;
+ FileDescription?: string;
+ OriginalFilename?: string;
+ FileVersion?: string;
+ ProductVersion?: string;
+ ProductName?: string;
+ InternalName?: string;
+ }
-declare module "electron-packager-tf" {
- const packager: ElectronPackager.Packager;
- export = packager;
+ export interface Packager {
+ /**
+ * This will:
+ * - Find or download the correct release of Electron
+ * - Use that version of electron to create a app in /--
+ *
+ * You should be able to launch the app on the platform you built for. If not, check your settings and try again.
+ *
+ * @param opts - Options to configure packaging.
+ * @param callback - Callback which is called when packaging is done or an error occured.
+ */
+ (opts: ElectronPackagerOptions, callback: (err: Error, appPath: string) => void): void;
+ }
}
-interface NodeRequireFunction {
- (id: "electron-packager"): ElectronPackager.Packager;
-}
+declare module "electron-packager-tf" {
+ const packager: ElectronPackager.Packager;
+ export = packager;
+}
\ No newline at end of file