Skip to content

Commit f880157

Browse files
committed
fix: build --target dir doesn't work
`--dir` flag added Closes #531
1 parent 7c81164 commit f880157

File tree

4 files changed

+52
-20
lines changed

4 files changed

+52
-20
lines changed

README.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ For a production app you need to sign your application, see [Where to buy code s
6767
```json
6868
"scripts": {
6969
"postinstall": "install-app-deps",
70-
"pack": "build --target dir",
70+
"pack": "build --dir",
7171
"dist": "build"
7272
}
7373
```
74-
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`.
74+
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).
7575

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

@@ -95,21 +95,38 @@ For windows consider only [distributing 64-bit versions](https://github.com/elec
9595
# CLI Usage
9696
Execute `node_modules/.bin/build --help` to get actual CLI usage guide.
9797
```
98-
--mac, -o Build for MacOS [array]
99-
--linux, -l Build for Linux [array]
100-
--win, -w, --windows Build for Windows [array]
101-
--x64 Build for x64 [boolean]
102-
--ia32 Build for ia32 [boolean]
103-
--publish, -p Publish artifacts (to GitHub Releases), see
104-
https://goo.gl/WMlr4n
105-
[choices: "onTag", "onTagOrDraft", "always", "never"]
106-
--platform The target platform (preferred to use --mac, --win or
107-
--linux)
108-
[choices: "mac", "win", "linux", "darwin", "win32", "all"]
109-
--arch The target arch (preferred to use --x64 or --ia32)
110-
[choices: "ia32", "x64", "all"]
111-
--help Show help [boolean]
112-
--version Show version number [boolean]
98+
Building:
99+
--mac, -m, -o, --osx Build for MacOS, accepts target list (see
100+
https://goo.gl/HAnnq8). [array]
101+
--linux, -l Build for Linux, accepts target list (see
102+
https://goo.gl/O80IL2) [array]
103+
--win, -w, --windows Build for Windows, accepts target list (see
104+
https://goo.gl/dL4i8i) [array]
105+
--x64 Build for x64 [boolean]
106+
--ia32 Build for ia32 [boolean]
107+
--dir Build unpacked dir. Useful to test. [boolean]
108+
109+
Publishing:
110+
--publish, -p Publish artifacts (to GitHub Releases), see
111+
https://goo.gl/WMlr4n
112+
[choices: "onTag", "onTagOrDraft", "always", "never"]
113+
--draft Create a draft (unpublished) release [boolean]
114+
--prerelease Identify the release as a prerelease [boolean]
115+
116+
Deprecated:
117+
--platform The target platform (preferred to use --mac, --win or --linux)
118+
[choices: "mac", "osx", "win", "linux", "darwin", "win32", "all"]
119+
--arch The target arch (preferred to use --x64 or --ia32)
120+
[choices: "ia32", "x64", "all"]
121+
122+
Other:
123+
--help Show help [boolean]
124+
--version Show version number [boolean]
125+
126+
Examples:
127+
build -mwl build for MacOS, Windows and Linux
128+
build --linux deb tar.xz build deb and tar.xz for Linux
129+
build --win --ia32 build for Windows ia32
113130
```
114131
115132
# Programmatic Usage

src/builder.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { isEmptyOrSpaces } from "./util/util"
77
import { log, warn } from "./util/log"
88
import { Platform, Arch, archFromString } from "./metadata"
99
import { getRepositoryInfo } from "./repositoryInfo"
10+
import { DIR_TARGET } from "./targets/targetFactory"
1011

1112
//noinspection JSUnusedLocalSymbols
1213
const __awaiter = require("./util/awaiter")
@@ -40,6 +41,8 @@ export interface CliOptions extends PackagerOptions, PublishOptions {
4041
x64?: boolean
4142
ia32?: boolean
4243

44+
dir?: boolean
45+
4346
platform?: string
4447
}
4548

@@ -90,12 +93,13 @@ export function normalizeOptions(args: CliOptions): BuildOptions {
9093
}
9194

9295
if (types.length === 0) {
96+
const defaultTargetValue = args.dir ? [DIR_TARGET] : []
9397
if (platform === Platform.MAC) {
94-
archToType.set(Arch.x64, [])
98+
archToType.set(Arch.x64, defaultTargetValue)
9599
}
96100
else {
97101
for (let arch of commonArch()) {
98-
archToType.set(arch, [])
102+
archToType.set(arch, defaultTargetValue)
99103
}
100104
}
101105
return
@@ -138,13 +142,14 @@ export function normalizeOptions(args: CliOptions): BuildOptions {
138142
processTargets(Platform.current(), [])
139143
}
140144
else {
141-
targets = createTargets(normalizePlatforms(args.platform), null, args.arch)
145+
targets = createTargets(normalizePlatforms(args.platform), args.dir ? DIR_TARGET : null, args.arch)
142146
}
143147
}
144148

145149
const result = Object.assign({}, args)
146150
result.targets = targets
147151

152+
delete result.dir
148153
delete result.mac
149154
delete result.linux
150155
delete result.win

src/cliOptions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export function createYargs(): any {
3838
describe: "Build for ia32",
3939
type: "boolean",
4040
})
41+
.option("dir", {
42+
group: buildGroup,
43+
describe: "Build unpacked dir. Useful to test.",
44+
type: "boolean",
45+
})
4146
.option("publish", {
4247
group: publishGroup,
4348
alias: "p",

test/src/BuildTest.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ test("cli", () => {
3535
assertThat(parse("-owl --x64 --ia32")).isEqualTo(all)
3636
assertThat(parse("-mwl --x64 --ia32")).isEqualTo(all)
3737

38+
assertThat(parse("--dir")).isEqualTo(expected({targets: Platform.current().createTarget(DIR_TARGET)}))
39+
assertThat(parse("--mac --dir")).isEqualTo(expected({targets: Platform.MAC.createTarget(DIR_TARGET)}))
40+
assertThat(parse("--ia32 --dir")).isEqualTo(expected({targets: Platform.current().createTarget(DIR_TARGET, Arch.ia32)}))
41+
assertThat(parse("--platform linux --dir")).isEqualTo(expected({targets: Platform.LINUX.createTarget(DIR_TARGET)}))
42+
3843
assertThat(parse("--osx")).isEqualTo(expected({targets: Platform.MAC.createTarget()}))
3944
assertThat(parse("--arch x64")).isEqualTo(expected({targets: Platform.current().createTarget(null, Arch.x64)}))
4045
assertThat(parse("--ia32 --x64")).isEqualTo(expected({targets: Platform.current().createTarget(null, Arch.x64, Arch.ia32)}))

0 commit comments

Comments
 (0)