From 0f1945564e8a6203c4fa7f4566aab866db82d1b3 Mon Sep 17 00:00:00 2001 From: develar Date: Sat, 23 Apr 2016 14:42:53 +0200 Subject: [PATCH] feat: import startssl certs by default No need to define CSA_LINK explicitly --- package.json | 8 ++++---- src/codeSign.ts | 20 ++++++++++++++------ src/metadata.ts | 2 +- src/packager.ts | 16 +++++++++++----- src/promise.ts | 3 ++- src/repositoryInfo.ts | 2 +- src/winPackager.ts | 9 +++++---- 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index a75b4a0d5bd..7efd17e2eb8 100644 --- a/package.json +++ b/package.json @@ -58,10 +58,9 @@ "chalk": "^1.1.3", "command-line-args": "^2.1.6", "deep-assign": "^2.0.0", - "electron-packager": "^7.0.0", + "electron-packager": "^7.0.1", "electron-winstaller-fixed": "~2.3.0-beta.4", - "fs-extra": "^0.28.0", - "fs-extra-p": "^0.2.0", + "fs-extra-p": "^0.3.0", "globby": "^4.0.0", "hosted-git-info": "^2.1.4", "image-size": "^0.5.0", @@ -72,7 +71,8 @@ "read-package-json": "^2.0.3", "signcode": "^0.4.0", "source-map-support": "^0.4.0", - "tmp": "0.0.28" + "tmp": "0.0.28", + "typescript": "^1.9.0-dev.20160423" }, "optionalDependencies": { "appdmg": "^0.3.7" diff --git a/src/codeSign.ts b/src/codeSign.ts index 707bef2ca3d..f639e32ea4a 100644 --- a/src/codeSign.ts +++ b/src/codeSign.ts @@ -24,12 +24,17 @@ export function generateKeychainName(): string { } export function createKeychain(keychainName: string, cscLink: string, cscKeyPassword: string, csaLink?: string): Promise { - const authorityCertPath = path.join(tmpdir(), randomString() + ".cer") + const authorityCerts = [csaLink || "https://developer.apple.com/certificationauthority/AppleWWDRCA.cer"] + if (csaLink == null) { + authorityCerts.push("https://startssl.com/certs/sca.code2.crt", "https://startssl.com/certs/sca.code3.crt") + } + const authorityCertPaths = authorityCerts.map(() => path.join(tmpdir(), randomString() + ".cer")) + const developerCertPath = path.join(tmpdir(), randomString() + ".p12") const keychainPassword = randomString() return executeFinally(BluebirdPromise.all([ - download(csaLink || "https://developer.apple.com/certificationauthority/AppleWWDRCA.cer", authorityCertPath), + BluebirdPromise.map(authorityCertPaths, (p, i) => download(authorityCerts[i], p)), download(cscLink, developerCertPath), BluebirdPromise.mapSeries([ ["create-keychain", "-p", keychainPassword, keychainName], @@ -37,9 +42,10 @@ export function createKeychain(keychainName: string, cscLink: string, cscKeyPass ["set-keychain-settings", "-t", "3600", "-u", keychainName] ], it => exec("security", it)) ]) - .then(() => importCerts(keychainName, authorityCertPath, developerCertPath, cscKeyPassword)), + .then(() => importCerts(keychainName, authorityCertPaths, developerCertPath, cscKeyPassword)), errorOccurred => { - const tasks = [deleteFile(authorityCertPath, true), deleteFile(developerCertPath, true)] + const tasks = authorityCertPaths.map(it => deleteFile(it, true)) + tasks.push(deleteFile(developerCertPath, true)) if (errorOccurred) { tasks.push(deleteKeychain(keychainName)) } @@ -47,8 +53,10 @@ export function createKeychain(keychainName: string, cscLink: string, cscKeyPass }) } -async function importCerts(keychainName: string, authorityCertPath: string, developerCertPath: string, cscKeyPassword: string): Promise { - await exec("security", ["import", authorityCertPath, "-k", keychainName, "-T", "/usr/bin/codesign"]) +async function importCerts(keychainName: string, authorityCertPaths: Array, developerCertPath: string, cscKeyPassword: string): Promise { + for (let p of authorityCertPaths) { + await exec("security", ["import", p, "-k", keychainName, "-T", "/usr/bin/codesign"]) + } await exec("security", ["import", developerCertPath, "-k", keychainName, "-T", "/usr/bin/codesign", "-P", cscKeyPassword]) let cscName = await extractCommonName(cscKeyPassword, developerCertPath) return { diff --git a/src/metadata.ts b/src/metadata.ts index 043e5d3b012..b81e2fd8da9 100755 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -98,7 +98,7 @@ export interface BuildMetadata { Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http. * If you don't plan to build windows installer, you can omit it. - * If your project repository is public on GitHub, it will be `https://raw.githubusercontent.com/${user}/${project}/master/build/icon.ico` by default. + * If your project repository is public on GitHub, it will be `https://raw.githubusercontent.com/${u}/${p}/master/build/icon.ico` by default. */ readonly iconUrl?: string diff --git a/src/packager.ts b/src/packager.ts index 72415205a69..9942ee7a44e 100644 --- a/src/packager.ts +++ b/src/packager.ts @@ -72,7 +72,7 @@ export class Packager implements BuildInfo { for (let platform of platforms) { const helper = this.createHelper(platform, cleanupTasks) for (let arch of normalizeArchs(platform, this.options.arch)) { - await this.installAppDependencies(arch) + await this.installAppDependencies(platform, arch) // electron-packager uses productName in the directory name const appOutDir = path.join(outDir, `${helper.appName}-${platform.nodeName}-${arch}`) await helper.pack(outDir, appOutDir, arch) @@ -153,14 +153,20 @@ export class Packager implements BuildInfo { } } - private installAppDependencies(arch: string): Promise { + private installAppDependencies(platform: Platform, arch: string): Promise { if (this.isTwoPackageJsonProjectLayoutUsed) { - return installDependencies(this.appDir, this.electronVersion, arch, "rebuild") + if (platform.nodeName === process.platform) { + return installDependencies(this.appDir, this.electronVersion, arch, "rebuild") + } + else { + log("Skip app dependencies rebuild because platform is different") + } } else { - log("Skipping app dependencies installation because dev and app dependencies are not separated") - return BluebirdPromise.resolve() + log("Skip app dependencies rebuild because dev and app dependencies are not separated") } + + return BluebirdPromise.resolve() } } diff --git a/src/promise.ts b/src/promise.ts index 0b81edea1d0..254431b8f3c 100644 --- a/src/promise.ts +++ b/src/promise.ts @@ -1,10 +1,11 @@ import { Promise as BluebirdPromise } from "bluebird" +import { red } from "chalk" //noinspection JSUnusedLocalSymbols const __awaiter = require("./awaiter") export function printErrorAndExit(error: Error) { - console.error(error.stack || error.message || error) + console.error(red(error.stack.toString() || error.message || error.toString())) process.exit(-1) } diff --git a/src/repositoryInfo.ts b/src/repositoryInfo.ts index 9d3d838ec93..4cd4ee6005d 100644 --- a/src/repositoryInfo.ts +++ b/src/repositoryInfo.ts @@ -3,8 +3,8 @@ import { readFile } from "fs-extra-p" import { AppMetadata, Metadata } from "./metadata" import * as path from "path" +//noinspection JSUnusedLocalSymbols const __awaiter = require("./awaiter") -Array.isArray(__awaiter) export interface ProjectMetadataProvider { metadata: AppMetadata diff --git a/src/winPackager.ts b/src/winPackager.ts index 491aeccc68b..2d9a150c8dc 100644 --- a/src/winPackager.ts +++ b/src/winPackager.ts @@ -103,10 +103,11 @@ export class WinPackager extends PlatformPackager { if (!iconUrl) { use(this.customBuildOptions, it => iconUrl = it.iconUrl) - if (!iconUrl) { - use(this.info.repositoryInfo, async(it) => - use(await it.getInfo(this), it => - iconUrl = `https://raw.githubusercontent.com/${it.user}/${it.project}/master/${this.relativeBuildResourcesDirname}/icon.ico`)) + if (!iconUrl && this.info.repositoryInfo != null) { + const info = await this.info.repositoryInfo.getInfo(this) + if (info != null) { + iconUrl = `https://raw.githubusercontent.com/${info.user}/${info.project}/master/${this.relativeBuildResourcesDirname}/icon.ico` + } } if (!iconUrl) {