Skip to content

Commit

Permalink
feat: artifact file name pattern for pkg and dmg
Browse files Browse the repository at this point in the history
Close #966
  • Loading branch information
develar committed Feb 10, 2017
1 parent f74a16c commit 22746bd
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 21 deletions.
15 changes: 14 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Most of the options accept `null` — for example, to explicitly set that DMG ic
| publish | <a name="Config-publish"></a>See [publish](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#PublishConfiguration).
| forceCodeSigning | <a name="Config-forceCodeSigning"></a>Whether to fail if application will be not signed (to prevent unsigned app if code signing configuration is not correct).
| electronVersion | <a name="Config-electronVersion"></a>The version of electron you are packaging for. Defaults to version of `electron`, `electron-prebuilt` or `electron-prebuilt-compile` dependency.
| artifactName | <a name="Config-artifactName"></a><p>The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to <code>${productName}-${version}.${ext}</code> (some target can have another defaults, see corresponding options).</p> <p>Currently supported only for <code>pkg</code>, <code>dmg</code> and <code>nsis</code>.</p>

<a name="AppXOptions"></a>
### `appx`
Expand Down Expand Up @@ -188,7 +189,7 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
| language | <a name="NsisOptions-language"></a>* [LCID Dec](https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx), defaults to `1033`(`English - United States`).
| warningsAsErrors | <a name="NsisOptions-warningsAsErrors"></a>Defaults to `true`. If `warningsAsErrors` is `true` (default): NSIS will treat warnings as errors. If `warningsAsErrors` is `false`: NSIS will allow warnings.
| menuCategory | <a name="NsisOptions-menuCategory"></a>Whether to create submenu for start menu shortcut and program files directory. Defaults to `false`. If `true`, company name will be used. Or string value.
| artifactName | <a name="NsisOptions-artifactName"></a><p>The artifact file name pattern. Defaults to <code>${productName} Setup ${version}.${ext}</code>. <code>${name}</code>, <code>${productName}</code>, <code>${version}</code>, <code>${ext}</code>, <code>${arch}</code>, <code>${os}</code> (expanded to <code>mac</code>, <code>linux</code> or <code>win</code> according to current platform) macro are supported.</p> <p>If no <code>arch</code>, macro will be removed from your pattern with leading space, <code>-</code> or <code>_</code> (so, you don’t need to worry and can reuse pattern).</p>
| artifactName | <a name="NsisOptions-artifactName"></a>The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Setup ${version}.${ext}`.

<a name="PkgOptions"></a>
### `pkg` macOS Product Archive Options
Expand Down Expand Up @@ -340,5 +341,17 @@ If `to` is given as a relative path, it is relative to the app's content directo
You can use `${os}` and `${arch}` in the `from` and `to` fields as well.
## Artifact File Name Pattern
Supported macros:
* `${name}`
* `${productName}` — [Sanitized](https://www.npmjs.com/package/sanitize-filename) product name.
* `${version}`
* `${ext}`
* `${arch}` — If no `arch`, macro will be removed from your pattern with leading space, `-` and `_` (so, you don't need to worry and can reuse pattern).
* `${os}` — expanded to `mac`, `linux` or `win` according to target platform.
## Build Version Management
`CFBundleVersion` (MacOS) and `FileVersion` (Windows) will be set automatically to `version`.`build_number` on CI server (Travis, AppVeyor and CircleCI supported).
2 changes: 1 addition & 1 deletion docs/Publishing Artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
### `publish` Generic (any https server)
| Name | Description
| --- | ---
| **url** | <a name="GenericServerOptions-url"></a>The base url. e.g. `https://s3.amazonaws.com/bucket_name`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to current platform) and `${arch}` macros.
| **url** | <a name="GenericServerOptions-url"></a>The base url. e.g. `https://s3.amazonaws.com/bucket_name`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
| channel | <a name="GenericServerOptions-channel"></a>The channel. Defaults to `latest`.

<a name="GithubOptions"></a>
Expand Down
9 changes: 9 additions & 0 deletions packages/electron-builder-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,13 @@ export abstract class Target {
finishBuild(): Promise<any> {
return Promise.resolve()
}
}

export interface TargetSpecificOptions {
/*
The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern).
*/
readonly artifactName?: string | null

readonly forceCodeSigning?: boolean
}
2 changes: 1 addition & 1 deletion packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface PublishConfiguration {
*/
export interface GenericServerOptions extends PublishConfiguration {
/*
The base url. e.g. `https://s3.amazonaws.com/bucket_name`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to current platform) and `${arch}` macros.
The base url. e.g. `https://s3.amazonaws.com/bucket_name`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
*/
url: string

Expand Down
15 changes: 10 additions & 5 deletions packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Arch, Platform } from "electron-builder-core"
import { Arch, Platform, TargetSpecificOptions } from "electron-builder-core"
import { Publish } from "electron-builder-http/out/publishOptions"
import { DebOptions, LinuxBuildOptions, SnapOptions } from "./options/linuxOptions"
import { DmgOptions, MacOptions, MasBuildOptions, PkgOptions } from "./options/macOptions"
Expand Down Expand Up @@ -83,7 +83,7 @@ export interface FilePattern {
/*
## Configuration Options
*/
export interface Config extends PlatformSpecificBuildOptions {
export interface Config extends PlatformSpecificBuildOptions, TargetSpecificOptions {
/*
The application id. Used as
[CFBundleIdentifier](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-102070) for MacOS and as
Expand Down Expand Up @@ -217,6 +217,13 @@ export interface Config extends PlatformSpecificBuildOptions {
The version of electron you are packaging for. Defaults to version of `electron`, `electron-prebuilt` or `electron-prebuilt-compile` dependency.
*/
readonly electronVersion?: string | null

/*
The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName}-${version}.${ext}` (some target can have another defaults, see corresponding options).
Currently supported only for `pkg`, `dmg` and `nsis`.
*/
readonly artifactName?: string | null
}

export interface AfterPackContext {
Expand Down Expand Up @@ -316,7 +323,7 @@ export interface MetadataDirectories {
readonly app?: string | null
}

export interface PlatformSpecificBuildOptions {
export interface PlatformSpecificBuildOptions extends TargetSpecificOptions {
readonly files?: Array<string> | string | null
readonly extraFiles?: Array<FilePattern> | FilePattern | Array<string> | string | null
readonly extraResources?: Array<FilePattern> | FilePattern | Array<string> | string | null
Expand All @@ -332,8 +339,6 @@ export interface PlatformSpecificBuildOptions {
readonly fileAssociations?: Array<FileAssociation> | FileAssociation

readonly publish?: Publish

readonly forceCodeSigning?: boolean
}

export interface Macros {
Expand Down
5 changes: 3 additions & 2 deletions packages/electron-builder/src/options/macOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PlatformSpecificBuildOptions } from "../metadata"
import { TargetSpecificOptions } from "electron-builder-core"

export type MacOsTargetName = "default" | "dmg" | "mas" | "pkg" | "7z" | "zip" | "tar.xz" | "tar.lz" | "tar.gz" | "tar.bz2" | "dir"

Expand Down Expand Up @@ -64,7 +65,7 @@ export interface MacOptions extends PlatformSpecificBuildOptions {
/*
### `pkg` macOS Product Archive Options
*/
export interface PkgOptions {
export interface PkgOptions extends TargetSpecificOptions {
/*
The scripts directory, relative to `build` (build resources directory). Defaults to `build/pkg-scripts`.
See [Scripting in installer packages](http://macinstallers.blogspot.de/2012/07/scripting-in-installer-packages.html).
Expand All @@ -88,7 +89,7 @@ export interface PkgOptions {
/*
### `dmg` macOS DMG Options
*/
export interface DmgOptions {
export interface DmgOptions extends TargetSpecificOptions {
/*
The path to background image (default: `build/background.tiff` or `build/background.png` if exists). The resolution of this file determines the resolution of the installer window.
If background is not specified, use `window.size`. Default locations expected background size to be 540x380.
Expand Down
4 changes: 1 addition & 3 deletions packages/electron-builder/src/options/winOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ export interface NsisOptions {
readonly useZip?: boolean

/*
The artifact file name pattern. Defaults to `${productName} Setup ${version}.${ext}`. `${name}`, `${productName}`, `${version}`, `${ext}`, `${arch}`, `${os}` (expanded to `mac`, `linux` or `win` according to current platform) macro are supported.
If no `arch`, macro will be removed from your pattern with leading space, `-` or `_` (so, you don't need to worry and can reuse pattern).
The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Setup ${version}.${ext}`.
*/
readonly artifactName?: string | null
}
Expand Down
17 changes: 12 additions & 5 deletions packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BluebirdPromise from "bluebird-lst-c"
import { Arch, getArchSuffix, Platform, Target } from "electron-builder-core"
import { Arch, getArchSuffix, Platform, Target, TargetSpecificOptions } from "electron-builder-core"
import { asArray, debug, isEmptyOrSpaces, use } from "electron-builder-util"
import { deepAssign } from "electron-builder-util/out/deepAssign"
import { copyDir, statOrNull, unlinkIfExists } from "electron-builder-util/out/fs"
Expand Down Expand Up @@ -394,17 +394,24 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
await this.checkFileInPackage(resourcesDir, "package.json", "Application", isAsar)
}

expandArtifactNamePattern(pattern: string, ext: string, arch: Arch | null): string {
let p = pattern
expandArtifactNamePattern(targetSpecificOptions: TargetSpecificOptions | n, ext: string, arch?: Arch | null, defaultPattern?: string): string {
let pattern = targetSpecificOptions == null ? null : targetSpecificOptions.artifactName
if (pattern == null) {
pattern = this.platformSpecificBuildOptions.artifactName
}
if (pattern == null) {
pattern = defaultPattern || "${productName}-${version}.${ext}"
}

if (arch == null) {
p = p
pattern = pattern
.replace("-${arch}", "")
.replace(" ${arch}", "")
.replace("_${arch}", "")
}

const appInfo = this.appInfo
return p.replace(/\$\{([a-zA-Z]+)\}/g, (match, p1): string => {
return pattern.replace(/\$\{([a-zA-Z]+)\}/g, (match, p1): string => {
switch (p1) {
case "name":
return appInfo.name
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/targets/dmg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class DmgTarget extends Target {
}
})

const artifactPath = path.join(appOutDir, `${appInfo.productFilename}-${appInfo.version}.dmg`)
const artifactPath = path.join(appOutDir, packager.expandArtifactNamePattern(packager.config.dmg, "dmg"))
//noinspection SpellCheckingInspection
await spawn("hdiutil", addVerboseIfNeed(["convert", tempDmg, "-format", packager.config.compression === "store" ? "UDRO" : "UDBZ", "-imagekey", "zlib-level=9", "-o", artifactPath]))
await exec("hdiutil", addVerboseIfNeed(["internet-enable", "-no"]).concat(artifactPath))
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class NsisTarget extends Target {
const appInfo = packager.appInfo
const version = appInfo.version
const options = this.options
const installerFilename = packager.expandArtifactNamePattern(options.artifactName || "${productName} Setup ${version}.${ext}", "exe", null)
const installerFilename = packager.expandArtifactNamePattern(options, "exe", null, "${productName} Setup ${version}.${ext}")
const iconPath = await packager.getResource(options.installerIcon, "installerIcon.ico") || await packager.getIconPath()
const oneClick = options.oneClick !== false

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/targets/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class PkgTarget extends Target {
const innerPackageFile = path.join(appOutDir, `${filterCFBundleIdentifier(appInfo.id)}.pkg`)
await this.buildComponentPackage(appPath, innerPackageFile)

const outFile = path.join(appOutDir, `${appInfo.productFilename}-${appInfo.version}.pkg`)
const outFile = path.join(appOutDir, packager.expandArtifactNamePattern(options, "pkg"))
const args = prepareProductBuildArgs(identity, keychainName)
args.push("--distribution", distInfo)
args.push(outFile)
Expand Down

0 comments on commit 22746bd

Please sign in to comment.