Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prefix dist: as marker to package in a distributable format #268

Merged
merged 1 commit into from
Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/runConfigurations/osxPackagerTest.xml

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

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ See [options](./docs/options.md), but consider to follow simple 4-step guide out
}
```
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)).
Both scripts are the same because If script named `dist` or name has prefix `dist:`, flag `--dist` is implied.

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

Expand Down
4 changes: 1 addition & 3 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ Here documented only `electron-builder` specific options:
| --- | ---
| <a class="anchor" href="#AppMetadata-name" aria-hidden="true"></a>name | The application name.
| <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>

<a class="anchor" href="#DevMetadata" aria-hidden="true"></a>
# Development `package.json`
| Name | Description
| --- | ---
| <a class="anchor" href="#DevMetadata-build" aria-hidden="true"></a>build | See [build](#BuildMetadata).

| <a class="anchor" href="#DevMetadata-build" aria-hidden="true"></a>build | See [BuildMetadata](#BuildMetadata).
<a class="anchor" href="#BuildMetadata" aria-hidden="true"></a>
## `.build`
| Name | Description
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@
"pre-commit": "^1.1.2",
"semantic-release": "^4.3.5",
"should": "^8.3.0",
"ts-babel": "^0.6.3",
"ts-babel": "^0.6.4",
"tsconfig-glob": "^0.4.2",
"tslint": "next",
"typescript": "^1.9.0-dev.20160323",
"typescript": "^1.9.0-dev.20160325",
"validate-commit-msg": "^2.4.1"
},
"babel": {
Expand Down
4 changes: 2 additions & 2 deletions src/build-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const cli = cla(commonArgs.concat(
{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 (by default)."},
{name: "target", type: String, multiple: true, description: "Installer or package type. For win32: squirrel (default) or nsis (deprecated)."},
{name: "arch", type: String, description: "ia32, x64 or all. Defaults to architecture you're running on."},
{name: "target", type: String, multiple: true, description: "Installer or package type."},
{name: "sign", type: String},
{name: "help", alias: "h", type: Boolean, description: "Display this usage guide."}
))
Expand Down
2 changes: 1 addition & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function build(originalOptions?: BuildOptions): Promise<void> {
options.dist = true
}
else if (options.dist === undefined) {
options.dist = lifecycleEvent === "dist" || lifecycleEvent === "build"
options.dist = lifecycleEvent === "dist" || lifecycleEvent === "build" || lifecycleEvent.startsWith("dist:")
}

let isPublishOptionGuessed = false
Expand Down
6 changes: 3 additions & 3 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface Metadata {
}

/**
Application `package.json`
# Application `package.json`
*/
export interface AppMetadata extends Metadata {
readonly version: string
Expand All @@ -25,7 +25,7 @@ export interface AppMetadata extends Metadata {
}

/**
Development `package.json`
# Development `package.json`
*/
export interface DevMetadata extends Metadata {
/**
Expand All @@ -50,7 +50,7 @@ export interface MetadataDirectories {
}

/**
Development `package.json` `.build`
## `.build`
*/
export interface BuildMetadata {
readonly "app-bundle-id": string
Expand Down
7 changes: 6 additions & 1 deletion src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ export class Packager implements BuildInfo {
}

export function normalizeArchs(platform: string, arch?: string) {
return platform === "darwin" ? ["x64"] : (arch == null || arch === "all" ? ["ia32", "x64"] : [arch])
if (platform === "darwin") {
return ["x64"]
}
else {
return arch == null ? [process.arch] : (arch === "all" ? ["ia32", "x64"] : [arch])
}
}

export function normalizePlatforms(platforms: Array<string>): Array<string> {
Expand Down
20 changes: 2 additions & 18 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "./helpers/avaEx"
import { assertPack, modifyPackageJson, platform } from "./helpers/packTester"
import { assertPack, modifyPackageJson } from "./helpers/packTester"
import { move, outputFile, outputJson } from "fs-extra-p"
import { Promise as BluebirdPromise } from "bluebird"
import * as path from "path"
Expand All @@ -9,19 +9,6 @@ import { Platform, PackagerOptions } from "out"
//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/awaiter")

if (process.env.TRAVIS !== "true") {
// we don't use CircleCI, so, we can safely set this env
process.env.CIRCLE_BUILD_NUM = 42
}

test.ifOsx("mac: two-package.json", async () => {
await assertPack("test-app", platform("darwin"))
})

test.ifOsx("mac: one-package.json", async () => {
await assertPack("test-app-one", platform("darwin"))
})

test("custom app dir", async () => {
await assertPack("test-app-one", allPlatformsAndCurrentArch(), {
tempDirCreated: (projectDir) => {
Expand Down Expand Up @@ -62,7 +49,6 @@ test("build in the app package.json", t => {
test("version from electron-prebuilt dependency", async() => {
await assertPack("test-app-one", {
platform: [process.platform],
arch: process.arch,
dist: false
}, {
tempDirCreated: projectDir => {
Expand All @@ -82,9 +68,9 @@ test("copy extra resource", async () => {
for (let platform of getPossiblePlatforms()) {
const osName = Platform.fromNodePlatform(platform).buildConfigurationKey

//noinspection SpellCheckingInspection
await assertPack("test-app", {
platform: [platform],
arch: process.arch,
// to check NuGet package
dist: platform === "win32"
}, {
Expand Down Expand Up @@ -166,8 +152,6 @@ test("copy extra resource", async () => {
function allPlatformsAndCurrentArch(): PackagerOptions {
return {
platform: getPossiblePlatforms(),
// speed up tests, we don't need check every arch
arch: process.arch,
}
}

Expand Down
13 changes: 9 additions & 4 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const __awaiter = require("out/awaiter")
const tmpDirPrefix = "electron-builder-test-" + process.pid + "-"
let tmpDirCounter = 0

if (process.env.TRAVIS !== "true") {
// we don't use CircleCI, so, we can safely set this env
process.env.CIRCLE_BUILD_NUM = 42
}

interface AssertPackOptions {
readonly tempDirCreated?: (projectDir: string) => Promise<any>
readonly packed?: (projectDir: string) => Promise<any>
Expand All @@ -27,7 +32,7 @@ interface AssertPackOptions {

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

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

assertThat(await getContents(projectDir + "/dist/TestApp-1.0.0-amd64.deb", productName)).deepEqual(expectedContents)
if (packagerOptions == null || packagerOptions.arch === null || packagerOptions.arch === "ia32") {
if (packagerOptions.arch === "all" || packagerOptions.arch === "ia32") {
assertThat(await getContents(projectDir + "/dist/TestApp-1.0.0-i386.deb", productName)).deepEqual(expectedContents)
}
}
else if (platform === "win32" && (packagerOptions == null || packagerOptions.target == null)) {
else if (platform === "win32") {
await checkWindowsResult(packager, packagerOptions, checkOptions, artifacts.get(Platform.WINDOWS))
}
}
Expand Down Expand Up @@ -164,7 +169,7 @@ async function checkWindowsResult(packager: Packager, packagerOptions: PackagerO
]
}

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

const filenames = artifacts.map(it => path.basename(it.file))
Expand Down
1 change: 0 additions & 1 deletion test/src/linuxPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ test.ifNotWindows("linux", async () => {
test.ifNotWindows("linux - icons from ICNS", async () => {
await assertPack("test-app-one", {
platform: ["linux"],
arch: process.arch,
}, {tempDirCreated: (projectDir) => remove(path.join(projectDir, "build", "icons"))})
})

Expand Down
16 changes: 16 additions & 0 deletions test/src/osxPackagerTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import test from "./helpers/avaEx"
import { assertPack, platform } from "./helpers/packTester"

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

test.ifOsx("mac: two-package.json", () => {
return assertPack("test-app", {
platform: ["darwin"],
arch: "all",
})
})

test.ifOsx("mac: one-package.json", () => {
return assertPack("test-app-one", platform("darwin"))
})
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"src/helpers/packTester.ts",
"src/helpers/runTests.ts",
"src/linuxPackagerTest.ts",
"src/osxPackagerTest.ts",
"src/RepoSlugTest.ts",
"src/winPackagerTest.ts"
]
Expand Down