Skip to content

Commit

Permalink
feat: Separate build config from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 15, 2017
1 parent d10ba78 commit 1f928af
Show file tree
Hide file tree
Showing 33 changed files with 393 additions and 485 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ For an app that will be shipped to production, you should sign your application.

6. Installing the [required system packages](https://github.com/electron-userland/electron-builder/wiki/Multi-Platform-Build).

Please note that everything is packaged into an asar archive [by default](https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-asar).
Please note that everything is packaged into an asar archive [by default](https://github.com/electron-userland/electron-builder/wiki/Options#Config-asar).

## Auto Update
`electron-builder` produces all required artifacts, for example, for macOS:
Expand Down
6 changes: 3 additions & 3 deletions docs/NSIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Windows requires to use registry keys (e.g. INSTALL/UNINSTALL info). Squirrel.Wi
But it is not robust — Google can use key Google Chrome SxS, because it is a Google.

So, it is better to use [GUID](http://stackoverflow.com/a/246935/1910191).
You are not forced to explicitly specify it — name-based [UUID v5](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_5_.28SHA-1_hash_.26_namespace.29) will be generated from your [appId](https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-appId) or [name](https://github.com/electron-userland/electron-builder/wiki/Options#AppMetadata-name).
You are not forced to explicitly specify it — name-based [UUID v5](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_5_.28SHA-1_hash_.26_namespace.29) will be generated from your [appId](https://github.com/electron-userland/electron-builder/wiki/Options#Config-appId) or [name](https://github.com/electron-userland/electron-builder/wiki/Options#AppMetadata-name).
It means that you **should not change appId** once your application in use (or name if `appId` was not set). Application product name (title) or description can be safely changed.

You can explicitly set guid using option [nsis.guid](https://github.com/electron-userland/electron-builder/wiki/Options#NsisOptions-guid), but it is not recommended — consider using [appId](https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-appId).
You can explicitly set guid using option [nsis.guid](https://github.com/electron-userland/electron-builder/wiki/Options#NsisOptions-guid), but it is not recommended — consider using [appId](https://github.com/electron-userland/electron-builder/wiki/Options#Config-appId).

It is also important to set the Application User Model ID (AUMID) to the [appId](https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-appId) of the application, in order for notifications on Windows 8/8.1 to function and for Window 10 notifications to display the app icon within the notifications by default. The AUIMD should be set within the Main process and before any BrowserWindows have been opened, it is normally the first piece of code executed.
It is also important to set the Application User Model ID (AUMID) to the [appId](https://github.com/electron-userland/electron-builder/wiki/Options#Config-appId) of the application, in order for notifications on Windows 8/8.1 to function and for Window 10 notifications to display the app icon within the notifications by default. The AUIMD should be set within the Main process and before any BrowserWindows have been opened, it is normally the first piece of code executed.

`app.setAppUserModelId(appId)`
228 changes: 96 additions & 132 deletions docs/Options.md

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions docs/Publishing Artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ But please consider using automatic rules instead of explicitly specifying `publ

## Publish Options

[build.publish](#PublishConfiguration) can be specified in [build](https://github.com/electron-userland/electron-builder/wiki/Options#build) or any platform- or target- specific options.
[publish](#PublishConfiguration) can be specified in the [configuration options](https://github.com/electron-userland/electron-builder/wiki/Options#Config) or any platform- or target- specific options.

```json
"win": {
Expand All @@ -56,13 +56,13 @@ But please consider using automatic rules instead of explicitly specifying `publ
```

<!-- do not edit. start of generated block -->
* [.build.publish](#PublishConfiguration)
* [.build.publish Bintray](#BintrayOptions)
* [.build.publish Generic (any https server)](#GenericServerOptions)
* [.build.publish GitHub](#GithubOptions)
* [publish](#PublishConfiguration)
* [publish Bintray](#BintrayOptions)
* [publish Generic (any https server)](#GenericServerOptions)
* [publish GitHub](#GithubOptions)

<a name="PublishConfiguration"></a>
### `.build.publish`
### `publish`

Can be specified in the [build](https://github.com/electron-userland/electron-builder/wiki/Options#build) or any platform- or target- specific options.

Expand All @@ -79,22 +79,22 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
| owner | <a name="PublishConfiguration-owner"></a>The owner.

<a name="BintrayOptions"></a>
### `.build.publish` Bintray
### `publish` Bintray
| Name | Description
| --- | ---
| package | <a name="BintrayOptions-package"></a>The Bintray package name.
| repo | <a name="BintrayOptions-repo"></a>The Bintray repository name. Defaults to `generic`.
| user | <a name="BintrayOptions-user"></a>The Bintray user account. Used in cases where the owner is an organization.

<a name="GenericServerOptions"></a>
### `.build.publish` Generic (any https server)
### `publish` Generic (any https server)
| Name | Description
| --- | ---
| **url** | <a name="GenericServerOptions-url"></a>The base url. e.g. `https://s3.amazonaws.com/bucket_name`
| channel | <a name="GenericServerOptions-channel"></a>The channel. Defaults to `latest`.

<a name="GithubOptions"></a>
### `.build.publish` GitHub
### `publish` GitHub
| Name | Description
| --- | ---
| repo | <a name="GithubOptions-repo"></a>The repository name. [Detected automatically](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#github-repository).
Expand Down
2 changes: 1 addition & 1 deletion docs/Two package.json Structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Since version 8 electron-builder rebuilds only production dependencies, so, you
Why?

1. Native npm modules (those written in C, not JavaScript) need to be compiled and here we have two different compilation targets for them. Those used within the application need to be compiled against the electron runtime and all `devDependencies` need to be compiled against your local node.js environment. Thanks to the two `package.json` structure, this is trivial (see [#39](https://github.com/electron-userland/electron-builder/issues/39)).
2. No need to specify which [files](https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files) to include in the app (because development files reside outside the `app` directory).
2. No need to specify which [files](https://github.com/electron-userland/electron-builder/wiki/Options#Config-files) to include in the app (because development files reside outside the `app` directory).

Please see [Loading App Dependencies Manually](https://github.com/electron-userland/electron-builder/wiki/Loading-App-Dependencies-Manually) and [#379](https://github.com/electron-userland/electron-builder/issues/379#issuecomment-218503881).

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"js-yaml": "^3.7.0",
"mime": "^1.3.4",
"minimatch": "^3.0.3",
"node-emoji": "^1.5.0",
"node-emoji": "^1.5.1",
"normalize-package-data": "^2.3.5",
"parse-color": "^1.0.0",
"plist": "^2.0.1",
Expand Down Expand Up @@ -72,8 +72,8 @@
"jest-cli": "^18.1.0",
"jest-environment-node-debug": "^0.0.2",
"path-sort": "^0.1.0",
"source-map-support": "^0.4.8",
"ts-babel": "^1.3.3",
"source-map-support": "^0.4.9",
"ts-babel": "^1.3.4",
"tslint": "^4.3.1",
"typescript": "^2.1.5",
"whitespace": "^2.1.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-auto-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"fs-extra-p": "^3.0.3",
"js-yaml": "^3.7.0",
"semver": "^5.3.0",
"source-map-support": "^0.4.8",
"source-map-support": "^0.4.9",
"electron-builder-http": "0.0.0-semantic-release"
},
"typings": "./out/electron-auto-updater.d.ts"
Expand Down
8 changes: 4 additions & 4 deletions packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type PublishProvider = "github" | "bintray" | "generic"
export type Publish = string | Array<string> | PublishConfiguration | GithubOptions | BintrayOptions | GenericServerOptions | Array<PublishConfiguration> | Array<GithubOptions> | Array<GenericServerOptions> | Array<BintrayOptions> | null

/*
### `.build.publish`
### `publish`
Can be specified in the [build](https://github.com/electron-userland/electron-builder/wiki/Options#build) or any platform- or target- specific options.
Expand All @@ -29,7 +29,7 @@ export interface PublishConfiguration {
}

/*
### `.build.publish` Generic (any https server)
### `publish` Generic (any https server)
*/
export interface GenericServerOptions extends PublishConfiguration {
/*
Expand All @@ -54,7 +54,7 @@ export interface UpdateInfo extends VersionInfo {
}

/*
### `.build.publish` GitHub
### `publish` GitHub
*/
export interface GithubOptions extends PublishConfiguration {
/*
Expand All @@ -69,7 +69,7 @@ export interface GithubOptions extends PublishConfiguration {
}

/*
### `.build.publish` Bintray
### `publish` Bintray
*/
export interface BintrayOptions extends PublishConfiguration {
/*
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"bluebird-lst-c": "^1.0.5",
"chalk": "^1.1.3",
"debug": "2.6.0",
"node-emoji": "^1.5.0",
"node-emoji": "^1.5.1",
"electron-builder-http": "~0.0.0-semantic-release",
"source-map-support": "^0.4.8",
"source-map-support": "^0.4.9",
"7zip-bin": "^2.0.4"
},
"typings": "./out/electron-builder-util.d.ts"
Expand Down
6 changes: 5 additions & 1 deletion packages/electron-builder-util/src/deepAssign.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function isObject(x: any) {
if (Array.isArray(x)) {
return false
}

const type = typeof x
return type === "object" || type === "function"
}
Expand All @@ -11,7 +15,7 @@ function assignKey(to: any, from: any, key: string) {
}

const prevValue = to[key]
if (prevValue == null || value === null || typeof prevValue !== "object" || !isObject(value)) {
if (prevValue == null || value === null || !isObject(prevValue) || !isObject(value)) {
to[key] = value
}
else {
Expand Down
43 changes: 0 additions & 43 deletions packages/electron-builder-util/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { execFile, spawn as _spawn, ChildProcess, SpawnOptions } from "child_pro
import BluebirdPromise from "bluebird-lst-c"
import { homedir } from "os"
import * as path from "path"
import { readJson } from "fs-extra-p"
import { yellow, red } from "chalk"
import _debug from "debug"
import { warn, log } from "./log"
Expand Down Expand Up @@ -140,48 +139,6 @@ export function handleProcess(event: string, childProcess: ChildProcess, command
})
}

export async function getElectronVersion(packageData: any, packageJsonPath: string): Promise<string> {
const build = packageData.build
// build is required, but this check is performed later, so, we should check for null
if (build != null && build.electronVersion != null) {
return build.electronVersion
}

for (const name of ["electron", "electron-prebuilt", "electron-prebuilt-compile"]) {
try {
return (await readJson(path.join(path.dirname(packageJsonPath), "node_modules", name, "package.json"))).version
}
catch (e) {
if (e.code !== "ENOENT") {
warn(`Cannot read electron version from ${name} package.json: ${e.message}`)
}
}
}

const electronPrebuiltDep = findFromElectronPrebuilt(packageData)
if (electronPrebuiltDep == null) {
throw new Error("Cannot find electron dependency to get electron version in the '" + packageJsonPath + "'")
}

const firstChar = electronPrebuiltDep[0]
return firstChar === "^" || firstChar === "~" ? electronPrebuiltDep.substring(1) : electronPrebuiltDep
}

function findFromElectronPrebuilt(packageData: any): any {
for (const name of ["electron", "electron-prebuilt", "electron-prebuilt-compile"]) {
const devDependencies = packageData.devDependencies
let dep = devDependencies == null ? null : devDependencies[name]
if (dep == null) {
const dependencies = packageData.dependencies
dep = dependencies == null ? null : dependencies[name]
}
if (dep != null) {
return dep
}
}
return null
}

export async function computeDefaultAppDirectory(projectDir: string, userAppDir: string | null | undefined): Promise<string> {
if (userAppDir != null) {
const absolutePath = path.resolve(projectDir, userAppDir)
Expand Down
14 changes: 7 additions & 7 deletions packages/electron-builder/src/appInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DevMetadata, AppMetadata, BuildMetadata } from "./metadata"
import { Config, Metadata } from "./metadata"
import { warn } from "electron-builder-util/out/log"
import { isEmptyOrSpaces, smarten } from "electron-builder-util"
import sanitizeFileName from "sanitize-filename"
Expand All @@ -14,11 +14,11 @@ export class AppInfo {
readonly productName: string
readonly productFilename: string

private get config(): BuildMetadata {
return this.devMetadata.build
private get config(): Config {
return this.info.config
}

constructor(public metadata: AppMetadata, private devMetadata: DevMetadata, private info: BuildInfo, buildVersion?: string | null) {
constructor(public metadata: Metadata, private info: BuildInfo, buildVersion?: string | null) {
this.version = metadata.version!

this.buildNumber = (<any>this.config)["build-version"] || process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM || process.env.BUILD_NUMBER
Expand All @@ -34,7 +34,7 @@ export class AppInfo {
this.buildVersion = buildVersion!
}

this.productName = this.config.productName || metadata.productName || metadata.name
this.productName = this.config.productName || metadata.productName || metadata.name!
this.productFilename = sanitizeFileName(this.productName)
}

Expand All @@ -58,7 +58,7 @@ export class AppInfo {
}

const generateDefaultAppId = () => {
return `com.electron.${this.metadata.name.toLowerCase()}`
return `com.electron.${this.metadata.name!.toLowerCase()}`
}

if (appId === "your.id" || isEmptyOrSpaces(appId)) {
Expand All @@ -71,7 +71,7 @@ export class AppInfo {
}

get name(): string {
return this.metadata.name
return this.metadata.name!
}

get copyright(): string {
Expand Down
16 changes: 6 additions & 10 deletions packages/electron-builder/src/cli/install-app-deps.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#! /usr/bin/env node

import { computeDefaultAppDirectory, getElectronVersion, use } from "electron-builder-util"
import { computeDefaultAppDirectory, use } from "electron-builder-util"
import { printErrorAndExit } from "electron-builder-util/out/promise"
import * as path from "path"
import BluebirdPromise from "bluebird-lst-c"
import { DevMetadata, getDirectoriesConfig } from "../metadata"
import yargs from "yargs"
import { readPackageJson } from "../util/readPackageJson"
import { loadConfig, getElectronVersion } from "../util/readPackageJson"
import { installOrRebuild } from "../yarn"

async function main() {
Expand All @@ -22,16 +20,14 @@ async function main() {
.argv

const projectDir = process.cwd()
const devPackageFile = path.join(projectDir, "package.json")

const devMetadata: DevMetadata = await readPackageJson(devPackageFile)
const config = await loadConfig(projectDir)
const results: Array<string> = await BluebirdPromise.all([
computeDefaultAppDirectory(projectDir, use(getDirectoriesConfig(devMetadata), it => it!.app)),
getElectronVersion(devMetadata, devPackageFile)
computeDefaultAppDirectory(projectDir, use(config.directories, it => it!.app)),
getElectronVersion(config, projectDir)
])

// if two package.json — force full install (user wants to install/update app deps in addition to dev)
await installOrRebuild(devMetadata.build, results[0], results[1], args.platform, args.arch, results[0] !== projectDir)
await installOrRebuild(config, results[0], results[1], args.platform, args.arch, results[0] !== projectDir)
}

main()
Expand Down
12 changes: 5 additions & 7 deletions packages/electron-builder/src/cli/node-gyp-rebuild.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#! /usr/bin/env node

import { getElectronVersion, exec } from "electron-builder-util"
import { exec } from "electron-builder-util"
import { printErrorAndExit } from "electron-builder-util/out/promise"
import * as path from "path"
import yargs from "yargs"
import { readPackageJson } from "../util/readPackageJson"
import { getElectronVersion, loadConfig } from "../util/readPackageJson"
import { log } from "electron-builder-util/out/log"
import { getGypEnv } from "../yarn"

Expand All @@ -18,13 +17,12 @@ const args: any = yargs
default: process.arch,
}).argv

const projectDir = process.cwd()
const devPackageFile = path.join(projectDir, "package.json")

async function main() {
const projectDir = process.cwd()
const config = await loadConfig(projectDir)
log(`Execute node-gyp rebuild for ${args.platform}:${args.arch}`)
await exec(process.platform === "win32" ? "node-gyp.cmd" : "node-gyp", ["rebuild"], {
env: getGypEnv(await getElectronVersion(await readPackageJson(devPackageFile), devPackageFile), args.platform, args.arch, true),
env: getGypEnv(await getElectronVersion(config, projectDir), args.platform, args.arch, true),
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export { PackagerOptions, ArtifactCreated, BuildInfo, SourceRepositoryInfo } fro
export { getArchSuffix, Platform, Arch, archFromString, Target } from "electron-builder-core"
export { BuildOptions, build, CliOptions, createTargets } from "./builder"
export { PublishOptions, Publisher } from "./publish/publisher"
export { AppMetadata, DevMetadata, BuildMetadata, CompressionLevel } from "./metadata"
export { Metadata, Config, CompressionLevel } from "./metadata"
export { MacOptions, DmgOptions, MasBuildOptions, MacOsTargetName } from "./options/macOptions"
export { WinBuildOptions, NsisOptions, SquirrelWindowsOptions, AppXOptions } from "./options/winOptions"
export { LinuxBuildOptions } from "./options/linuxOptions"
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
}

protected prepareAppInfo(appInfo: AppInfo): AppInfo {
return new AppInfo(appInfo.metadata, this.info.devMetadata, this.info, this.platformSpecificBuildOptions.bundleVersion)
return new AppInfo(appInfo.metadata, this.info, this.platformSpecificBuildOptions.bundleVersion)
}

async getIconPath(): Promise<string | null> {
Expand Down
Loading

0 comments on commit 1f928af

Please sign in to comment.