Skip to content

Commit

Permalink
fix: move npmRebuild to build
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 1, 2016
1 parent 1f4f621 commit 1110596
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 82 deletions.
3 changes: 2 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Here documented only `electron-builder` specific options:
| linux | <a name="BuildMetadata-linux"></a>See [.build.linux](#LinuxBuildOptions).
| compression | <a name="BuildMetadata-compression"></a>The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
| afterPack | <a name="BuildMetadata-afterPack"></a>*programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
| npmRebuild | <a name="BuildMetadata-npmRebuild"></a>Whether to rebuild native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.

<a name="OsXBuildOptions"></a>
### `.build.osx`
Expand All @@ -70,7 +71,7 @@ See all [appdmg options](https://www.npmjs.com/package/appdmg#json-specification

| Name | Description
| --- | ---
| icon | <a name="OsXBuildOptions-icon"></a>The path to icon, which will be shown when mounted (default: `build/icon.icns`).
| icon | <a name="OsXBuildOptions-icon"></a>The path to DMG icon, which will be shown when mounted. Defaults to `build/icon.icns`.
| background | <a name="OsXBuildOptions-background"></a><p>The path to background (default: <code>build/background.png</code> if exists). The resolution of this file determines the resolution of the installer window. If background is not specified, use <code>window.size</code>, see [specification](https://github.com/LinusU/node-appdmg#json-specification).</p>
| target | <a name="OsXBuildOptions-target"></a>Target package type: list of `default`, `dmg`, `mas`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `default` (dmg and zip for Squirrel.Mac).
| identity | <a name="OsXBuildOptions-identity"></a><p>The name of certificate to use when signing. Consider using environment variables [CSC_LINK or CSC_NAME](https://github.com/electron-userland/electron-builder/wiki/Code-Signing). MAS installer identity is specified in the [.build.mas](#MasBuildOptions-identity).</p>
Expand Down
65 changes: 3 additions & 62 deletions src/build-cli.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,8 @@
#! /usr/bin/env node

// import { commonTargets } from "./platformPackager"
import { build, CliOptions } from "./builder"
import { printErrorAndExit } from "./promise"
import { underline } from "chalk"
import yargs = require("yargs")
import { createYargs } from "./cliOptions"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")

export function createYargs(): any {
return yargs
.version()
.option("osx", {
alias: "o",
describe: "Build for OS X",
type: "array",
})
.option("linux", {
alias: "l",
describe: "Build for Linux",
type: "array",
})
.option("win", {
alias: ["w", "windows"],
describe: "Build for Windows",
type: "array",
})
.option("x64", {
describe: "Build for x64",
type: "boolean",
})
.option("ia32", {
describe: "Build for ia32",
type: "boolean",
})
// .option("target", {
// alias: "t",
// describe: "Target package types",
// choices: commonTargets,
// })
.option("publish", {
alias: "p",
describe: `Publish artifacts (to GitHub Releases), see ${underline("https://goo.gl/WMlr4n")}`,
choices: ["onTag", "onTagOrDraft", "always", "never"],
})
.option("platform", {
choices: ["osx", "win", "linux", "darwin", "win32", "all"],
})
.option("arch", {
choices: ["ia32", "x64", "all"],
})
.option("npmRebuild", {
describe: "Runs npm rebuild before starting to package the app.",
default: true,
type: "boolean",
})
.strict()
.help()
.epilog(`Project home: ${underline("https://github.com/electron-userland/electron-builder")}`)
}

if (!module.parent) {
build(<CliOptions>(createYargs().argv))
.catch(printErrorAndExit)
}
build(<CliOptions>(createYargs().argv))
.catch(printErrorAndExit)
4 changes: 2 additions & 2 deletions src/builder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Packager, normalizePlatforms, isEmptyOrSpaces } from "./packager"
import { Packager, normalizePlatforms } from "./packager"
import { PackagerOptions } from "./platformPackager"
import { PublishOptions, Publisher, GitHubPublisher } from "./gitHubPublisher"
import { executeFinally } from "./promise"
import { Promise as BluebirdPromise } from "bluebird"
import { InfoRetriever } from "./repositoryInfo"
import { log, warn } from "./util"
import { log, warn, isEmptyOrSpaces } from "./util"
import { Platform, Arch, archFromString } from "./metadata"

//noinspection JSUnusedLocalSymbols
Expand Down
49 changes: 49 additions & 0 deletions src/cliOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { underline } from "chalk"
import yargs = require("yargs")

export function createYargs(): any {
return yargs
.version()
.option("osx", {
alias: "o",
describe: "Build for OS X",
type: "array",
})
.option("linux", {
alias: "l",
describe: "Build for Linux",
type: "array",
})
.option("win", {
alias: ["w", "windows"],
describe: "Build for Windows",
type: "array",
})
.option("x64", {
describe: "Build for x64",
type: "boolean",
})
.option("ia32", {
describe: "Build for ia32",
type: "boolean",
})
// .option("target", {
// alias: "t",
// describe: "Target package types",
// choices: commonTargets,
// })
.option("publish", {
alias: "p",
describe: `Publish artifacts (to GitHub Releases), see ${underline("https://goo.gl/WMlr4n")}`,
choices: ["onTag", "onTagOrDraft", "always", "never"],
})
.option("platform", {
choices: ["osx", "win", "linux", "darwin", "win32", "all"],
})
.option("arch", {
choices: ["ia32", "x64", "all"],
})
.strict()
.help()
.epilog(`Project home: ${underline("https://github.com/electron-userland/electron-builder")}`)
}
7 changes: 6 additions & 1 deletion src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ export interface BuildMetadata {
*programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
*/
readonly afterPack?: (context: AfterPackContext) => Promise<any> | null

/*
Whether to rebuild native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
*/
readonly npmRebuild?: boolean
}

export interface AfterPackContext {
Expand All @@ -165,7 +170,7 @@ export interface AfterPackContext {
*/
export interface OsXBuildOptions extends PlatformSpecificBuildOptions {
/*
The path to icon, which will be shown when mounted (default: `build/icon.icns`).
The path to DMG icon, which will be shown when mounted. Defaults to `build/icon.icns`.
*/
readonly icon?: string | null

Expand Down
4 changes: 2 additions & 2 deletions src/osxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PlatformPackager, BuildInfo } from "./platformPackager"
import { Platform, OsXBuildOptions, MasBuildOptions, Arch } from "./metadata"
import * as path from "path"
import { Promise as BluebirdPromise } from "bluebird"
import { log, debug, warn } from "./util"
import { log, debug, warn, isEmptyOrSpaces } from "./util"
import { createKeychain, deleteKeychain, CodeSigningInfo, generateKeychainName, findIdentity } from "./codeSign"
import deepAssign = require("deep-assign")
import { sign, flat, BaseSignOptions, SignOptions, FlatOptions } from "electron-osx-sign-tf"
Expand Down Expand Up @@ -65,7 +65,7 @@ export default class OsXPackager extends PlatformPackager<OsXBuildOptions> {

private static async findIdentity(certType: string, name?: string | null): Promise<string | null> {
let identity = process.env.CSC_NAME || name
if (identity == null || identity.trim().length === 0) {
if (isEmptyOrSpaces(identity)) {
return await findIdentity(certType)
}
else {
Expand Down
8 changes: 2 additions & 6 deletions src/packager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from "path"
import {
computeDefaultAppDirectory, installDependencies, log, getElectronVersion, readPackageJson, use, warn,
exec
exec, isEmptyOrSpaces
} from "./util"
import { all, executeFinally } from "./promise"
import { EventEmitter } from "events"
Expand Down Expand Up @@ -174,7 +174,7 @@ export class Packager implements BuildInfo {

private installAppDependencies(platform: Platform, arch: Arch): Promise<any> {
if (this.isTwoPackageJsonProjectLayoutUsed) {
if (this.options.npmRebuild === false) {
if (this.devMetadata.build.npmRebuild === false) {
log("Skip app dependencies rebuild because npmRebuild is set to false")
}
else if (platform.nodeName === process.platform) {
Expand Down Expand Up @@ -247,8 +247,4 @@ async function checkWineVersion(checkPromise: Promise<string>) {
if (compareVersions(wineVersion, "1.8") === -1) {
throw new Error(wineError(`wine 1.8+ is required, but your version is ${wineVersion}`))
}
}

export function isEmptyOrSpaces(s: string | n) {
return s == null || s.trim().length === 0
}
2 changes: 0 additions & 2 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export interface PackagerOptions {
* Development `package.json` will be still read, but options specified in this object will override.
*/
readonly devMetadata?: DevMetadata

readonly npmRebuild?: boolean
}

export interface BuildInfo extends ProjectMetadataProvider {
Expand Down
4 changes: 4 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,8 @@ const pidAsString = process.pid.toString(36)

export function getTempName(prefix?: string | n): string {
return `${prefix == null ? "" : prefix + "-"}${pidAsString}-${tmpDirCounter++}-${Date.now().toString(36)}`
}

export function isEmptyOrSpaces(s: string | n) {
return s == null || s.trim().length === 0
}
7 changes: 2 additions & 5 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { move, outputFile, outputJson } from "fs-extra-p"
import { Promise as BluebirdPromise } from "bluebird"
import * as path from "path"
import { assertThat } from "./helpers/fileAssert"
import { Platform, Arch, PackagerOptions, DIR_TARGET, createTargets } from "out"
import { archFromString, BuildOptions, Platform, Arch, PackagerOptions, DIR_TARGET, createTargets } from "out"
import pathSorter = require("path-sort")
import { normalizeOptions } from "out/builder"
import { createYargs } from "out/build-cli"
import { BuildOptions } from "out/builder"
import { archFromString } from "out/metadata"
import { createYargs } from "out/cliOptions"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/awaiter")
Expand All @@ -20,7 +18,6 @@ test("cli", (t) => {

const base = {
publish: <string>undefined,
npmRebuild: true,
}

function expected(opt: PackagerOptions): any {
Expand Down
1 change: 0 additions & 1 deletion test/src/helpers/avaEx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Object.defineProperties(test, {
},
"ifDevOrWinCi": {
get: function () {
console.log(process.env)
return process.env.CI == null || process.platform === "win32" ? this : this.skip
}
},
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"src/build-cli.ts",
"src/builder.ts",
"src/cleanup.ts",
"src/cliOptions.ts",
"src/codeSign.ts",
"src/errorMessages.ts",
"src/fpmDownload.ts",
Expand Down

0 comments on commit 1110596

Please sign in to comment.