Skip to content

Commit a5e4571

Browse files
committed
feat: --dist by default and remove this flag in favour of `--target=dir #413
BREAKING CHANGE: `appDir` CLI is removed — use [directories.app](https://github.com/electron-userland/electron-builder/wiki/Options#MetadataDirectories-app) in the development package.json. `sign` CLI is removed — use [build.osx.identity](https://github.com/electron-userland/electron-builder/wiki/Options#OsXBuildOptions-identity) in the development package.json.
1 parent 1f8fc81 commit a5e4571

21 files changed

+308
-184
lines changed

.idea/dictionaries/develar.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,11 @@ It costs only $59 (and 2 weeks), see [Where to buy code signing certificate](htt
6363
```json
6464
"scripts": {
6565
"postinstall": "install-app-deps",
66-
"pack": "build",
66+
"pack": "build --target dir",
6767
"dist": "build"
6868
}
6969
```
70-
And then you can run `npm run pack` or `npm run dist` (to package in a distributable format (e.g. dmg, windows installer, deb package)).
71-
Both scripts are the same because If script named `dist` or name has prefix `dist:`, flag `--dist` is implied.
72-
73-
Please note — if you don't name your script `dist` or prefix it with `dist:` and you don't pass `--dist` flag, application will be not packed in a distributable format.
70+
And then you can run `npm run dist` (to package in a distributable format (e.g. dmg, windows installer, deb package)) or `npm run pack`.
7471

7572
5. Install [required system packages](https://github.com/electron-userland/electron-builder/wiki/Multi-Platform-Build).
7673

docker/Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,7 @@ ENV BUNDLE_PATH="$GEM_HOME" \
103103
ENV PATH $BUNDLE_BIN:$PATH
104104
RUN mkdir -p "$GEM_HOME" "$BUNDLE_BIN" \
105105
&& chmod 777 "$GEM_HOME" "$BUNDLE_BIN" \
106-
&& mkdir -p /tmp/fpm && curl -L https://github.com/jordansissel/fpm/archive/6e2514df27664912826b4fcd89affa19df0e713b.tar.gz | tar -xz -C /tmp/fpm --strip-components 1 && cd /tmp/fpm && bundle install && make install && cd .. && rm -rf /tmp/fpm
107-
108-
# use fpm commit https://github.com/jordansissel/fpm/commit/6e2514df27664912826b4fcd89affa19df0e713b because of some important unreleased fixes:
109-
# https://github.com/jordansissel/fpm/commit/94be82c0a23c8cd641ab9e60f3eb4a8db445fff0
110-
# https://github.com/jordansissel/fpm/commit/77b95747b9cc01ca420ee24084a449b3ac19e6d5
106+
&& mkdir -p /tmp/fpm && curl -L https://github.com/jordansissel/fpm/archive/5719990e1bbc3deeaea8a196d6aaa51421a058bd.tar.gz | tar -xz -C /tmp/fpm --strip-components 1 && cd /tmp/fpm && bundle install && make install && cd .. && rm -rf /tmp/fpm
111107

112108
# we don't use our bundled fpm because it is better to build ruby & tools for specific platform - not generic. And easy to maintain (update ruby and so on).
113109
ENV USE_SYSTEM_FPM true

docs/Options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ See all [appdmg options](https://www.npmjs.com/package/appdmg#json-specification
7171
| --- | ---
7272
| icon | <a name="OsXBuildOptions-icon"></a>The path to icon, which will be shown when mounted (default: `build/icon.icns`).
7373
| 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>
74-
| target | <a name="OsXBuildOptions-target"></a>Target package type: list of `default`, `dmg`, `zip`, `mas`, `7z`, `tar.xz`, `tar.gz`, `tar.bz2`, `tar.7z`. Defaults to `default` (dmg and zip for Squirrel.Mac).
74+
| 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).
7575
| 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>
7676
| entitlements | <a name="OsXBuildOptions-entitlements"></a><p>The path to entitlements file for signing the app. <code>build/osx.entitlements</code> will be used if exists (it is a recommended way to set). MAS entitlements is specified in the [.build.mas](#MasBuildOptions-entitlements).</p>
7777
| entitlementsInherit | <a name="OsXBuildOptions-entitlementsInherit"></a><p>The path to child entitlements which inherit the security settings for signing frameworks and bundles of a distribution. <code>build/osx.inherit.entitlements</code> will be used if exists (it is a recommended way to set). Otherwise [default](https://github.com/electron-userland/electron-osx-sign/blob/master/default.darwin.inherit.entitlements).</p> <p>This option only applies when signing with <code>entitlements</code> provided.</p>

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@
6161
"asar": "^0.11.0",
6262
"bluebird": "^3.4.0",
6363
"chalk": "^1.1.3",
64-
"command-line-args": "^2.1.6",
6564
"compare-versions": "^2.0.1",
6665
"debug": "^2.2.0",
6766
"deep-assign": "^2.0.0",
68-
"electron-osx-sign-tf": "0.4.0-beta.0",
67+
"electron-osx-sign-tf": "0.5.1",
6968
"electron-packager-tf": "~7.2.0",
7069
"electron-winstaller-fixed": "~2.9.3",
7170
"fs-extra-p": "^1.0.1",
@@ -78,7 +77,8 @@
7877
"progress-stream": "^1.2.0",
7978
"read-package-json": "^2.0.4",
8079
"signcode-tf": "~0.7.3",
81-
"source-map-support": "^0.4.0"
80+
"source-map-support": "^0.4.0",
81+
"yargs": "^4.7.1"
8282
},
8383
"optionalDependencies": {
8484
"appdmg": "^0.4.5"
@@ -102,7 +102,7 @@
102102
"path-sort": "^0.1.0",
103103
"plist": "^1.2.0",
104104
"pre-git": "^3.8.4",
105-
"semantic-release": "^6.2.2",
105+
"semantic-release": "^6.3.0",
106106
"should": "^8.4.0",
107107
"ts-babel": "^0.8.6",
108108
"tsconfig-glob": "^0.4.3",

src/build-cli.ts

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,97 @@
11
#! /usr/bin/env node
22

3-
import { PackagerOptions } from "./platformPackager"
3+
import { PackagerOptions, commonTargets } from "./platformPackager"
4+
import { normalizePlatforms } from "./packager"
45
import { build } from "./builder"
56
import { PublishOptions } from "./gitHubPublisher"
67
import { printErrorAndExit } from "./promise"
7-
import cla = require("command-line-args")
8-
import { readFileSync } from "fs"
9-
import * as path from "path"
10-
import { warn } from "./util"
8+
import yargs = require("yargs")
9+
import { underline } from "chalk"
10+
import { Platform } from "./metadata"
1111

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

1515
interface CliOptions extends PackagerOptions, PublishOptions {
16-
help: boolean
16+
osx?: Array<string>
17+
linux?: Array<string>
18+
win?: Array<string>
19+
20+
arch?: string
21+
22+
x64?: boolean
23+
ia32?: boolean
24+
}
25+
26+
const args = <CliOptions>(yargs
27+
.version()
28+
.option("osx", {
29+
alias: "o",
30+
describe: "Build for OS X",
31+
type: "array",
32+
})
33+
.option("linux", {
34+
alias: "l",
35+
describe: "Build for Linux",
36+
type: "array",
37+
})
38+
.option("win", {
39+
alias: ["w", "windows"],
40+
describe: "Build for Windows",
41+
type: "array",
42+
})
43+
.option("x64", {
44+
describe: "Build for x64",
45+
type: "boolean",
46+
})
47+
.option("ia32", {
48+
describe: "Build for ia32",
49+
type: "boolean",
50+
})
51+
.option("target", {
52+
alias: "t",
53+
describe: "Target package types",
54+
choices: commonTargets,
55+
})
56+
.option("publish", {
57+
alias: "p",
58+
describe: `Publish artifacts (to GitHub Releases), see ${underline("https://goo.gl/WMlr4n")}`,
59+
choices: ["onTag", "onTagOrDraft", "always", "never"],
60+
})
61+
.option("platform", {
62+
choices: ["osx", "win", "linux", "darwin", "win32", "all"],
63+
})
64+
.option("arch", {
65+
choices: ["ia32", "x64", "all"],
66+
})
67+
.strict()
68+
.help()
69+
.epilog(`Project home: ${underline("https://github.com/electron-userland/electron-builder")}`)
70+
.argv)
71+
72+
const platforms = normalizePlatforms(args.platform)
73+
if (args.osx != null && !platforms.includes(Platform.OSX)) {
74+
platforms.push(Platform.OSX)
1775
}
76+
if (args.linux != null && !platforms.includes(Platform.LINUX)) {
77+
platforms.push(Platform.LINUX)
78+
}
79+
if (args.win != null && !platforms.includes(Platform.WINDOWS)) {
80+
platforms.push(Platform.WINDOWS)
81+
}
82+
83+
const archAsProp = args.arch
84+
const archs = archAsProp === "all" ? ["ia32", "x64"] : (archAsProp == null ? [] : [archAsProp])
1885

19-
const cli = cla([
20-
{name: "dist", type: Boolean, alias: "d", description: "Whether to package in a distributable format (e.g. DMG, windows installer, NuGet package)."},
21-
{name: "publish", type: String, alias: "p", description: "Publish artifacts (to GitHub Releases): onTag (on tag push only) or onTagOrDraft (on tag push or if draft release exists)."},
22-
{name: "platform", type: String, multiple: true, description: "darwin, linux, win32 or all. Current platform (" + process.platform + ") by default."},
23-
{name: "arch", type: String, description: "ia32, x64 or all. Defaults to architecture you're running on."},
24-
{name: "sign", type: String},
25-
{name: "help", alias: "h", type: Boolean, description: "Display this usage guide."},
26-
{name: "appDir", type: String}
27-
])
28-
29-
const args: CliOptions = cli.parse()
30-
31-
if (args.help) {
32-
const version = process.env.npm_package_version || JSON.parse(readFileSync(path.join(__dirname, "..", "package.json"), "utf8")).version
33-
console.log(cli.getUsage({
34-
title: "electron-builder " + version,
35-
footer: "Project home: [underline]{https://github.com/electron-userland/electron-builder}",
36-
hide: ["appDir"],
37-
}))
86+
if (args.x64 && !archs.includes("x64")) {
87+
archs.push("x64")
3888
}
39-
else {
40-
if (args.appDir) {
41-
warn(`-appDir CLI parameter is deprecated, please configure build.directories.app instead
42-
See https://github.com/electron-userland/electron-builder/wiki/Options#MetadataDirectories-app`)
43-
}
44-
45-
build(args)
46-
.catch(printErrorAndExit)
47-
}
89+
if (args.ia32 && !archs.includes("ia32")) {
90+
archs.push("ia32")
91+
}
92+
93+
build(Object.assign({}, args, {
94+
platform: platforms,
95+
arch: archs,
96+
}))
97+
.catch(printErrorAndExit)

src/builder.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,9 @@ export async function build(originalOptions?: BuildOptions): Promise<void> {
3636

3737
options.platform = normalizePlatforms(options.platform)
3838

39-
const lifecycleEvent = process.env.npm_lifecycle_event
40-
if (options.publish) {
41-
options.dist = true
42-
}
43-
else if (options.dist === undefined) {
44-
options.dist = lifecycleEvent === "dist" || lifecycleEvent === "build" || (lifecycleEvent != null && lifecycleEvent.startsWith("dist:"))
45-
}
46-
4739
let isPublishOptionGuessed = false
4840
if (options.publish === undefined) {
49-
if (lifecycleEvent === "release") {
41+
if (process.env.npm_lifecycle_event === "release") {
5042
options.publish = "always"
5143
}
5244
else if (options.githubToken != null) {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { Packager } from "./packager"
2-
export { PackagerOptions, ArtifactCreated } from "./platformPackager"
2+
export { PackagerOptions, ArtifactCreated, DIR_TARGET } from "./platformPackager"
33
export { BuildOptions, build, createPublisher } from "./builder"
44
export { PublishOptions, Publisher } from "./gitHubPublisher"
55
export { AppMetadata, DevMetadata, Platform, getProductName, BuildMetadata, OsXBuildOptions, WinBuildOptions, LinuxBuildOptions } from "./metadata"

src/install-app-deps.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@
33
import { computeDefaultAppDirectory, installDependencies, getElectronVersion, readPackageJson, use } from "./util"
44
import { printErrorAndExit } from "./promise"
55
import * as path from "path"
6-
import cla = require("command-line-args")
76
import { Promise as BluebirdPromise } from "bluebird"
8-
import { DevMetadata } from "./metadata";
7+
import { DevMetadata } from "./metadata"
8+
import yargs = require("yargs")
99

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

13-
const args = cla([{name: "arch", type: String}, {name: "appDir", type: String}]).parse()
13+
const args: any = yargs
14+
.option("arch", {
15+
choices: ["ia32", "x64", "all"],
16+
}).argv
1417

1518
const projectDir = process.cwd()
1619
const devPackageFile = path.join(projectDir, "package.json")
1720

1821
async function main() {
1922
const devMetadata: DevMetadata = await readPackageJson(devPackageFile)
2023
const results: Array<string> = await BluebirdPromise.all([
21-
computeDefaultAppDirectory(projectDir, use(devMetadata.directories, it => it!.app) || args.appDir),
24+
computeDefaultAppDirectory(projectDir, use(devMetadata.directories, it => it!.app)),
2225
getElectronVersion(devMetadata, devPackageFile)
2326
])
2427

src/linuxPackager.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
2929
description: this.metadata.description,
3030
}, this.customBuildOptions)
3131

32-
if (this.options.dist) {
32+
if (!this.hasOnlyDirTarget()) {
3333
const tempDir = path.join(tmpdir(), getTempName("electron-builder-linux"))
3434
const tempDirPromise = emptyDir(tempDir)
3535
.then(() => {
@@ -73,17 +73,15 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
7373
const appOutDir = this.computeAppOutDir(outDir, arch)
7474
await this.doPack(this.computePackOptions(outDir, appOutDir, arch), outDir, appOutDir, arch, this.customBuildOptions)
7575

76-
if (this.options.dist) {
77-
for (let target of this.targets) {
78-
if (target === "zip" || target === "7z" || target.startsWith("tar.")) {
79-
const destination = path.join(outDir, `${this.metadata.name}-${this.metadata.version}${archSuffix(arch)}.${target}`)
80-
postAsyncTasks.push(this.archiveApp(target, appOutDir, destination)
81-
.then(() => this.dispatchArtifactCreated(destination)))
82-
}
76+
for (let target of this.targets) {
77+
if (target === "zip" || target === "7z" || target.startsWith("tar.")) {
78+
const destination = path.join(outDir, `${this.metadata.name}-${this.metadata.version}${archSuffix(arch)}.${target}`)
79+
postAsyncTasks.push(this.archiveApp(target, appOutDir, destination)
80+
.then(() => this.dispatchArtifactCreated(destination)))
8381
}
84-
85-
postAsyncTasks.push(this.packageInDistributableFormat(outDir, appOutDir, arch))
8682
}
83+
84+
postAsyncTasks.push(this.packageInDistributableFormat(outDir, appOutDir, arch))
8785
}
8886

8987
private async computeDesktop(tempDir: string): Promise<Array<string>> {
@@ -196,10 +194,10 @@ Icon=${this.metadata.name}
196194
// todo fix fpm - if we run in parallel, get strange tar errors
197195
for (let target of this.targets) {
198196
target = target === "default" ? "deb" : target
199-
if (target !== "zip" && target !== "7z" && !target.startsWith("tar.")) {
197+
if (target !== "dir" && target !== "zip" && target !== "7z" && !target.startsWith("tar.")) {
200198
const destination = path.join(outDir, `${this.metadata.name}-${this.metadata.version}${archSuffix(arch)}.${target}`)
201199
await this.buildPackage(destination, target, this.buildOptions, appOutDir, arch)
202-
.then(() => this.dispatchArtifactCreated(destination))
200+
this.dispatchArtifactCreated(destination)
203201
}
204202
}
205203
}

0 commit comments

Comments
 (0)