Skip to content

Commit fa7cc85

Browse files
committed
feat: prefix dist: as marker to package in a distributable format
Closes #267
1 parent 92f7a38 commit fa7cc85

File tree

13 files changed

+52
-35
lines changed

13 files changed

+52
-35
lines changed

.idea/runConfigurations/osxPackagerTest.xml

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ See [options](./docs/options.md), but consider to follow simple 4-step guide out
6565
}
6666
```
6767
And then you can run `npm run pack` or `npm run dist` (to package in a distributable format (e.g. DMG, windows installer, NuGet package)).
68+
Both scripts are the same because If script named `dist` or name has prefix `dist:`, flag `--dist` is implied.
6869

6970
4. Install [required system packages](./docs/multi-platform-build.md).
7071

docs/options.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ Here documented only `electron-builder` specific options:
4141
| --- | ---
4242
| <a class="anchor" href="#AppMetadata-name" aria-hidden="true"></a>name | The application name.
4343
| <a class="anchor" href="#AppMetadata-productName" aria-hidden="true"></a>productName | <p>As [name](#AppMetadata-name), but allows you to specify a product name for your executable which contains spaces and other special characters not allowed in the [name property](https://docs.npmjs.com/files/package.json#name}).</p>
44-
4544
<a class="anchor" href="#DevMetadata" aria-hidden="true"></a>
4645
# Development `package.json`
4746
| Name | Description
4847
| --- | ---
49-
| <a class="anchor" href="#DevMetadata-build" aria-hidden="true"></a>build | See [build](#BuildMetadata).
50-
48+
| <a class="anchor" href="#DevMetadata-build" aria-hidden="true"></a>build | See [BuildMetadata](#BuildMetadata).
5149
<a class="anchor" href="#BuildMetadata" aria-hidden="true"></a>
5250
## `.build`
5351
| Name | Description

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@
8484
"pre-commit": "^1.1.2",
8585
"semantic-release": "^4.3.5",
8686
"should": "^8.3.0",
87-
"ts-babel": "^0.6.3",
87+
"ts-babel": "^0.6.4",
8888
"tsconfig-glob": "^0.4.2",
8989
"tslint": "next",
90-
"typescript": "^1.9.0-dev.20160323",
90+
"typescript": "^1.9.0-dev.20160325",
9191
"validate-commit-msg": "^2.4.1"
9292
},
9393
"babel": {

src/build-cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const cli = cla(commonArgs.concat(
2020
{name: "dist", type: Boolean, alias: "d", description: "Whether to package in a distributable format (e.g. DMG, windows installer, NuGet package)."},
2121
{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)."},
2222
{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 (by default)."},
24-
{name: "target", type: String, multiple: true, description: "Installer or package type. For win32: squirrel (default) or nsis (deprecated)."},
23+
{name: "arch", type: String, description: "ia32, x64 or all. Defaults to architecture you're running on."},
24+
{name: "target", type: String, multiple: true, description: "Installer or package type."},
2525
{name: "sign", type: String},
2626
{name: "help", alias: "h", type: Boolean, description: "Display this usage guide."}
2727
))

src/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function build(originalOptions?: BuildOptions): Promise<void> {
4040
options.dist = true
4141
}
4242
else if (options.dist === undefined) {
43-
options.dist = lifecycleEvent === "dist" || lifecycleEvent === "build"
43+
options.dist = lifecycleEvent === "dist" || lifecycleEvent === "build" || lifecycleEvent.startsWith("dist:")
4444
}
4545

4646
let isPublishOptionGuessed = false

src/metadata.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export interface Metadata {
33
}
44

55
/**
6-
Application `package.json`
6+
# Application `package.json`
77
*/
88
export interface AppMetadata extends Metadata {
99
readonly version: string
@@ -25,7 +25,7 @@ export interface AppMetadata extends Metadata {
2525
}
2626

2727
/**
28-
Development `package.json`
28+
# Development `package.json`
2929
*/
3030
export interface DevMetadata extends Metadata {
3131
/**
@@ -50,7 +50,7 @@ export interface MetadataDirectories {
5050
}
5151

5252
/**
53-
Development `package.json` `.build`
53+
## `.build`
5454
*/
5555
export interface BuildMetadata {
5656
readonly "app-bundle-id": string

src/packager.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,12 @@ export class Packager implements BuildInfo {
177177
}
178178

179179
export function normalizeArchs(platform: string, arch?: string) {
180-
return platform === "darwin" ? ["x64"] : (arch == null || arch === "all" ? ["ia32", "x64"] : [arch])
180+
if (platform === "darwin") {
181+
return ["x64"]
182+
}
183+
else {
184+
return arch == null ? [process.arch] : (arch === "all" ? ["ia32", "x64"] : [arch])
185+
}
181186
}
182187

183188
export function normalizePlatforms(platforms: Array<string>): Array<string> {

test/src/BuildTest.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from "./helpers/avaEx"
2-
import { assertPack, modifyPackageJson, platform } from "./helpers/packTester"
2+
import { assertPack, modifyPackageJson } from "./helpers/packTester"
33
import { move, outputFile, outputJson } from "fs-extra-p"
44
import { Promise as BluebirdPromise } from "bluebird"
55
import * as path from "path"
@@ -9,19 +9,6 @@ import { Platform, PackagerOptions } from "out"
99
//noinspection JSUnusedLocalSymbols
1010
const __awaiter = require("out/awaiter")
1111

12-
if (process.env.TRAVIS !== "true") {
13-
// we don't use CircleCI, so, we can safely set this env
14-
process.env.CIRCLE_BUILD_NUM = 42
15-
}
16-
17-
test.ifOsx("mac: two-package.json", async () => {
18-
await assertPack("test-app", platform("darwin"))
19-
})
20-
21-
test.ifOsx("mac: one-package.json", async () => {
22-
await assertPack("test-app-one", platform("darwin"))
23-
})
24-
2512
test("custom app dir", async () => {
2613
await assertPack("test-app-one", allPlatformsAndCurrentArch(), {
2714
tempDirCreated: (projectDir) => {
@@ -62,7 +49,6 @@ test("build in the app package.json", t => {
6249
test("version from electron-prebuilt dependency", async() => {
6350
await assertPack("test-app-one", {
6451
platform: [process.platform],
65-
arch: process.arch,
6652
dist: false
6753
}, {
6854
tempDirCreated: projectDir => {
@@ -82,9 +68,9 @@ test("copy extra resource", async () => {
8268
for (let platform of getPossiblePlatforms()) {
8369
const osName = Platform.fromNodePlatform(platform).buildConfigurationKey
8470

71+
//noinspection SpellCheckingInspection
8572
await assertPack("test-app", {
8673
platform: [platform],
87-
arch: process.arch,
8874
// to check NuGet package
8975
dist: platform === "win32"
9076
}, {
@@ -166,8 +152,6 @@ test("copy extra resource", async () => {
166152
function allPlatformsAndCurrentArch(): PackagerOptions {
167153
return {
168154
platform: getPossiblePlatforms(),
169-
// speed up tests, we don't need check every arch
170-
arch: process.arch,
171155
}
172156
}
173157

test/src/helpers/packTester.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const __awaiter = require("out/awaiter")
1919
const tmpDirPrefix = "electron-builder-test-" + process.pid + "-"
2020
let tmpDirCounter = 0
2121

22+
if (process.env.TRAVIS !== "true") {
23+
// we don't use CircleCI, so, we can safely set this env
24+
process.env.CIRCLE_BUILD_NUM = 42
25+
}
26+
2227
interface AssertPackOptions {
2328
readonly tempDirCreated?: (projectDir: string) => Promise<any>
2429
readonly packed?: (projectDir: string) => Promise<any>
@@ -27,7 +32,7 @@ interface AssertPackOptions {
2732

2833
export async function assertPack(fixtureName: string, packagerOptions: PackagerOptions, checkOptions?: AssertPackOptions): Promise<void> {
2934
const tempDirCreated = checkOptions == null ? null : checkOptions.tempDirCreated
30-
const useTempDir = tempDirCreated != null || (packagerOptions != null && packagerOptions.target != null)
35+
const useTempDir = tempDirCreated != null || packagerOptions.target != null
3136

3237
let projectDir = path.join(__dirname, "..", "..", "fixtures", fixtureName)
3338
// const isDoNotUseTempDir = platform === "darwin"
@@ -118,11 +123,11 @@ async function packAndCheck(projectDir: string, packagerOptions: PackagerOptions
118123
// console.log(JSON.stringify(await getContents(projectDir + "/dist/TestApp-1.0.0-i386.deb", productName), null, 2))
119124

120125
assertThat(await getContents(projectDir + "/dist/TestApp-1.0.0-amd64.deb", productName)).deepEqual(expectedContents)
121-
if (packagerOptions == null || packagerOptions.arch === null || packagerOptions.arch === "ia32") {
126+
if (packagerOptions.arch === "all" || packagerOptions.arch === "ia32") {
122127
assertThat(await getContents(projectDir + "/dist/TestApp-1.0.0-i386.deb", productName)).deepEqual(expectedContents)
123128
}
124129
}
125-
else if (platform === "win32" && (packagerOptions == null || packagerOptions.target == null)) {
130+
else if (platform === "win32") {
126131
await checkWindowsResult(packager, packagerOptions, checkOptions, artifacts.get(Platform.WINDOWS))
127132
}
128133
}
@@ -164,7 +169,7 @@ async function checkWindowsResult(packager: Packager, packagerOptions: PackagerO
164169
]
165170
}
166171

167-
const archSuffix = packagerOptions != null && packagerOptions.arch === "x64" ? "" : "-ia32"
172+
const archSuffix = (packagerOptions.arch || process.arch) === "x64" ? "" : "-ia32"
168173
const expected = archSuffix == "" ? getWinExpected(archSuffix) : getWinExpected(archSuffix).concat(getWinExpected(""))
169174

170175
const filenames = artifacts.map(it => path.basename(it.file))

0 commit comments

Comments
 (0)