Skip to content

Commit

Permalink
fix: build --target dir doesn't work
Browse files Browse the repository at this point in the history
`--dir` flag added

Closes #531
  • Loading branch information
develar committed Jun 22, 2016
1 parent 7c81164 commit f880157
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
51 changes: 34 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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
Expand Down
11 changes: 8 additions & 3 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -40,6 +41,8 @@ export interface CliOptions extends PackagerOptions, PublishOptions {
x64?: boolean
ia32?: boolean

dir?: boolean

platform?: string
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/cliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}))
Expand Down

0 comments on commit f880157

Please sign in to comment.