Skip to content

Commit

Permalink
feat: --dist by default and remove this flag in favour of `--target…
Browse files Browse the repository at this point in the history
…=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.
  • Loading branch information
develar committed May 28, 2016
1 parent 1f8fc81 commit a5e4571
Show file tree
Hide file tree
Showing 21 changed files with 308 additions and 184 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,11 @@ It costs only $59 (and 2 weeks), see [Where to buy code signing certificate](htt
```json
"scripts": {
"postinstall": "install-app-deps",
"pack": "build",
"pack": "build --target dir",
"dist": "build"
}
```
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)).
Both scripts are the same because If script named `dist` or name has prefix `dist:`, flag `--dist` is implied.

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.
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`.

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

Expand Down
6 changes: 1 addition & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ ENV BUNDLE_PATH="$GEM_HOME" \
ENV PATH $BUNDLE_BIN:$PATH
RUN mkdir -p "$GEM_HOME" "$BUNDLE_BIN" \
&& chmod 777 "$GEM_HOME" "$BUNDLE_BIN" \
&& 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

# use fpm commit https://github.com/jordansissel/fpm/commit/6e2514df27664912826b4fcd89affa19df0e713b because of some important unreleased fixes:
# https://github.com/jordansissel/fpm/commit/94be82c0a23c8cd641ab9e60f3eb4a8db445fff0
# https://github.com/jordansissel/fpm/commit/77b95747b9cc01ca420ee24084a449b3ac19e6d5
&& 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

# 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).
ENV USE_SYSTEM_FPM true
Expand Down
2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ See all [appdmg options](https://www.npmjs.com/package/appdmg#json-specification
| --- | ---
| icon | <a name="OsXBuildOptions-icon"></a>The path to icon, which will be shown when mounted (default: `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`, `zip`, `mas`, `7z`, `tar.xz`, `tar.gz`, `tar.bz2`, `tar.7z`. Defaults to `default` (dmg and zip for Squirrel.Mac).
| 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>
| 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>
| 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>
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@
"asar": "^0.11.0",
"bluebird": "^3.4.0",
"chalk": "^1.1.3",
"command-line-args": "^2.1.6",
"compare-versions": "^2.0.1",
"debug": "^2.2.0",
"deep-assign": "^2.0.0",
"electron-osx-sign-tf": "0.4.0-beta.0",
"electron-osx-sign-tf": "0.5.1",
"electron-packager-tf": "~7.2.0",
"electron-winstaller-fixed": "~2.9.3",
"fs-extra-p": "^1.0.1",
Expand All @@ -78,7 +77,8 @@
"progress-stream": "^1.2.0",
"read-package-json": "^2.0.4",
"signcode-tf": "~0.7.3",
"source-map-support": "^0.4.0"
"source-map-support": "^0.4.0",
"yargs": "^4.7.1"
},
"optionalDependencies": {
"appdmg": "^0.4.5"
Expand All @@ -102,7 +102,7 @@
"path-sort": "^0.1.0",
"plist": "^1.2.0",
"pre-git": "^3.8.4",
"semantic-release": "^6.2.2",
"semantic-release": "^6.3.0",
"should": "^8.4.0",
"ts-babel": "^0.8.6",
"tsconfig-glob": "^0.4.3",
Expand Down
118 changes: 84 additions & 34 deletions src/build-cli.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,97 @@
#! /usr/bin/env node

import { PackagerOptions } from "./platformPackager"
import { PackagerOptions, commonTargets } from "./platformPackager"
import { normalizePlatforms } from "./packager"
import { build } from "./builder"
import { PublishOptions } from "./gitHubPublisher"
import { printErrorAndExit } from "./promise"
import cla = require("command-line-args")
import { readFileSync } from "fs"
import * as path from "path"
import { warn } from "./util"
import yargs = require("yargs")
import { underline } from "chalk"
import { Platform } from "./metadata"

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

interface CliOptions extends PackagerOptions, PublishOptions {
help: boolean
osx?: Array<string>
linux?: Array<string>
win?: Array<string>

arch?: string

x64?: boolean
ia32?: boolean
}

const args = <CliOptions>(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")}`)
.argv)

const platforms = normalizePlatforms(args.platform)
if (args.osx != null && !platforms.includes(Platform.OSX)) {
platforms.push(Platform.OSX)
}
if (args.linux != null && !platforms.includes(Platform.LINUX)) {
platforms.push(Platform.LINUX)
}
if (args.win != null && !platforms.includes(Platform.WINDOWS)) {
platforms.push(Platform.WINDOWS)
}

const archAsProp = args.arch
const archs = archAsProp === "all" ? ["ia32", "x64"] : (archAsProp == null ? [] : [archAsProp])

const cli = cla([
{name: "dist", type: Boolean, alias: "d", description: "Whether to package in a distributable format (e.g. DMG, windows installer, NuGet package)."},
{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)."},
{name: "platform", type: String, multiple: true, description: "darwin, linux, win32 or all. Current platform (" + process.platform + ") by default."},
{name: "arch", type: String, description: "ia32, x64 or all. Defaults to architecture you're running on."},
{name: "sign", type: String},
{name: "help", alias: "h", type: Boolean, description: "Display this usage guide."},
{name: "appDir", type: String}
])

const args: CliOptions = cli.parse()

if (args.help) {
const version = process.env.npm_package_version || JSON.parse(readFileSync(path.join(__dirname, "..", "package.json"), "utf8")).version
console.log(cli.getUsage({
title: "electron-builder " + version,
footer: "Project home: [underline]{https://github.com/electron-userland/electron-builder}",
hide: ["appDir"],
}))
if (args.x64 && !archs.includes("x64")) {
archs.push("x64")
}
else {
if (args.appDir) {
warn(`-appDir CLI parameter is deprecated, please configure build.directories.app instead
See https://github.com/electron-userland/electron-builder/wiki/Options#MetadataDirectories-app`)
}

build(args)
.catch(printErrorAndExit)
}
if (args.ia32 && !archs.includes("ia32")) {
archs.push("ia32")
}

build(Object.assign({}, args, {
platform: platforms,
arch: archs,
}))
.catch(printErrorAndExit)
10 changes: 1 addition & 9 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,9 @@ export async function build(originalOptions?: BuildOptions): Promise<void> {

options.platform = normalizePlatforms(options.platform)

const lifecycleEvent = process.env.npm_lifecycle_event
if (options.publish) {
options.dist = true
}
else if (options.dist === undefined) {
options.dist = lifecycleEvent === "dist" || lifecycleEvent === "build" || (lifecycleEvent != null && lifecycleEvent.startsWith("dist:"))
}

let isPublishOptionGuessed = false
if (options.publish === undefined) {
if (lifecycleEvent === "release") {
if (process.env.npm_lifecycle_event === "release") {
options.publish = "always"
}
else if (options.githubToken != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { Packager } from "./packager"
export { PackagerOptions, ArtifactCreated } from "./platformPackager"
export { PackagerOptions, ArtifactCreated, DIR_TARGET } from "./platformPackager"
export { BuildOptions, build, createPublisher } from "./builder"
export { PublishOptions, Publisher } from "./gitHubPublisher"
export { AppMetadata, DevMetadata, Platform, getProductName, BuildMetadata, OsXBuildOptions, WinBuildOptions, LinuxBuildOptions } from "./metadata"
11 changes: 7 additions & 4 deletions src/install-app-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
import { computeDefaultAppDirectory, installDependencies, getElectronVersion, readPackageJson, use } from "./util"
import { printErrorAndExit } from "./promise"
import * as path from "path"
import cla = require("command-line-args")
import { Promise as BluebirdPromise } from "bluebird"
import { DevMetadata } from "./metadata";
import { DevMetadata } from "./metadata"
import yargs = require("yargs")

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

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

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

async function main() {
const devMetadata: DevMetadata = await readPackageJson(devPackageFile)
const results: Array<string> = await BluebirdPromise.all([
computeDefaultAppDirectory(projectDir, use(devMetadata.directories, it => it!.app) || args.appDir),
computeDefaultAppDirectory(projectDir, use(devMetadata.directories, it => it!.app)),
getElectronVersion(devMetadata, devPackageFile)
])

Expand Down
22 changes: 10 additions & 12 deletions src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
description: this.metadata.description,
}, this.customBuildOptions)

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

if (this.options.dist) {
for (let target of this.targets) {
if (target === "zip" || target === "7z" || target.startsWith("tar.")) {
const destination = path.join(outDir, `${this.metadata.name}-${this.metadata.version}${archSuffix(arch)}.${target}`)
postAsyncTasks.push(this.archiveApp(target, appOutDir, destination)
.then(() => this.dispatchArtifactCreated(destination)))
}
for (let target of this.targets) {
if (target === "zip" || target === "7z" || target.startsWith("tar.")) {
const destination = path.join(outDir, `${this.metadata.name}-${this.metadata.version}${archSuffix(arch)}.${target}`)
postAsyncTasks.push(this.archiveApp(target, appOutDir, destination)
.then(() => this.dispatchArtifactCreated(destination)))
}

postAsyncTasks.push(this.packageInDistributableFormat(outDir, appOutDir, arch))
}

postAsyncTasks.push(this.packageInDistributableFormat(outDir, appOutDir, arch))
}

private async computeDesktop(tempDir: string): Promise<Array<string>> {
Expand Down Expand Up @@ -196,10 +194,10 @@ Icon=${this.metadata.name}
// todo fix fpm - if we run in parallel, get strange tar errors
for (let target of this.targets) {
target = target === "default" ? "deb" : target
if (target !== "zip" && target !== "7z" && !target.startsWith("tar.")) {
if (target !== "dir" && target !== "zip" && target !== "7z" && !target.startsWith("tar.")) {
const destination = path.join(outDir, `${this.metadata.name}-${this.metadata.version}${archSuffix(arch)}.${target}`)
await this.buildPackage(destination, target, this.buildOptions, appOutDir, arch)
.then(() => this.dispatchArtifactCreated(destination))
this.dispatchArtifactCreated(destination)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export interface OsXBuildOptions extends PlatformSpecificBuildOptions {
readonly background?: string | null

/*
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).
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).
*/
readonly target?: Array<string> | null

Expand Down
Loading

0 comments on commit a5e4571

Please sign in to comment.