From f880157bcc7971c6c716d7617992e9c16ad1ae73 Mon Sep 17 00:00:00 2001 From: develar Date: Wed, 22 Jun 2016 08:36:42 +0200 Subject: [PATCH] fix: `build --target dir` doesn't work `--dir` flag added Closes #531 --- README.md | 51 ++++++++++++++++++++++++++++--------------- src/builder.ts | 11 +++++++--- src/cliOptions.ts | 5 +++++ test/src/BuildTest.ts | 5 +++++ 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 3f64834990d..b595d77e4e0 100755 --- a/README.md +++ b/README.md @@ -67,11 +67,11 @@ For a production app you need to sign your application, see [Where to buy code s ```json "scripts": { "postinstall": "install-app-deps", - "pack": "build --target dir", + "pack": "build --dir", "dist": "build" } ``` - 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`. + 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` (useful to test). 5. Install [required system packages](https://github.com/electron-userland/electron-builder/wiki/Multi-Platform-Build). @@ -95,21 +95,38 @@ For windows consider only [distributing 64-bit versions](https://github.com/elec # CLI Usage Execute `node_modules/.bin/build --help` to get actual CLI usage guide. ``` ---mac, -o Build for MacOS [array] ---linux, -l Build for Linux [array] ---win, -w, --windows Build for Windows [array] ---x64 Build for x64 [boolean] ---ia32 Build for ia32 [boolean] ---publish, -p Publish artifacts (to GitHub Releases), see - https://goo.gl/WMlr4n - [choices: "onTag", "onTagOrDraft", "always", "never"] ---platform The target platform (preferred to use --mac, --win or - --linux) - [choices: "mac", "win", "linux", "darwin", "win32", "all"] ---arch The target arch (preferred to use --x64 or --ia32) - [choices: "ia32", "x64", "all"] ---help Show help [boolean] ---version Show version number [boolean] +Building: + --mac, -m, -o, --osx Build for MacOS, accepts target list (see + https://goo.gl/HAnnq8). [array] + --linux, -l Build for Linux, accepts target list (see + https://goo.gl/O80IL2) [array] + --win, -w, --windows Build for Windows, accepts target list (see + https://goo.gl/dL4i8i) [array] + --x64 Build for x64 [boolean] + --ia32 Build for ia32 [boolean] + --dir Build unpacked dir. Useful to test. [boolean] + +Publishing: + --publish, -p Publish artifacts (to GitHub Releases), see + https://goo.gl/WMlr4n + [choices: "onTag", "onTagOrDraft", "always", "never"] + --draft Create a draft (unpublished) release [boolean] + --prerelease Identify the release as a prerelease [boolean] + +Deprecated: + --platform The target platform (preferred to use --mac, --win or --linux) + [choices: "mac", "osx", "win", "linux", "darwin", "win32", "all"] + --arch The target arch (preferred to use --x64 or --ia32) + [choices: "ia32", "x64", "all"] + +Other: + --help Show help [boolean] + --version Show version number [boolean] + +Examples: + build -mwl build for MacOS, Windows and Linux + build --linux deb tar.xz build deb and tar.xz for Linux + build --win --ia32 build for Windows ia32 ``` # Programmatic Usage diff --git a/src/builder.ts b/src/builder.ts index 7bd2b566d89..213c983f971 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -7,6 +7,7 @@ import { isEmptyOrSpaces } from "./util/util" import { log, warn } from "./util/log" import { Platform, Arch, archFromString } from "./metadata" import { getRepositoryInfo } from "./repositoryInfo" +import { DIR_TARGET } from "./targets/targetFactory" //noinspection JSUnusedLocalSymbols const __awaiter = require("./util/awaiter") @@ -40,6 +41,8 @@ export interface CliOptions extends PackagerOptions, PublishOptions { x64?: boolean ia32?: boolean + dir?: boolean + platform?: string } @@ -90,12 +93,13 @@ export function normalizeOptions(args: CliOptions): BuildOptions { } if (types.length === 0) { + const defaultTargetValue = args.dir ? [DIR_TARGET] : [] if (platform === Platform.MAC) { - archToType.set(Arch.x64, []) + archToType.set(Arch.x64, defaultTargetValue) } else { for (let arch of commonArch()) { - archToType.set(arch, []) + archToType.set(arch, defaultTargetValue) } } return @@ -138,13 +142,14 @@ export function normalizeOptions(args: CliOptions): BuildOptions { processTargets(Platform.current(), []) } else { - targets = createTargets(normalizePlatforms(args.platform), null, args.arch) + targets = createTargets(normalizePlatforms(args.platform), args.dir ? DIR_TARGET : null, args.arch) } } const result = Object.assign({}, args) result.targets = targets + delete result.dir delete result.mac delete result.linux delete result.win diff --git a/src/cliOptions.ts b/src/cliOptions.ts index a4f91f9b28d..c3cf477827e 100644 --- a/src/cliOptions.ts +++ b/src/cliOptions.ts @@ -38,6 +38,11 @@ export function createYargs(): any { describe: "Build for ia32", type: "boolean", }) + .option("dir", { + group: buildGroup, + describe: "Build unpacked dir. Useful to test.", + type: "boolean", + }) .option("publish", { group: publishGroup, alias: "p", diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index 155f03d1b86..dca3227d91b 100755 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -35,6 +35,11 @@ test("cli", () => { assertThat(parse("-owl --x64 --ia32")).isEqualTo(all) assertThat(parse("-mwl --x64 --ia32")).isEqualTo(all) + assertThat(parse("--dir")).isEqualTo(expected({targets: Platform.current().createTarget(DIR_TARGET)})) + assertThat(parse("--mac --dir")).isEqualTo(expected({targets: Platform.MAC.createTarget(DIR_TARGET)})) + assertThat(parse("--ia32 --dir")).isEqualTo(expected({targets: Platform.current().createTarget(DIR_TARGET, Arch.ia32)})) + assertThat(parse("--platform linux --dir")).isEqualTo(expected({targets: Platform.LINUX.createTarget(DIR_TARGET)})) + assertThat(parse("--osx")).isEqualTo(expected({targets: Platform.MAC.createTarget()})) assertThat(parse("--arch x64")).isEqualTo(expected({targets: Platform.current().createTarget(null, Arch.x64)})) assertThat(parse("--ia32 --x64")).isEqualTo(expected({targets: Platform.current().createTarget(null, Arch.x64, Arch.ia32)}))