diff --git a/docs/Options.md b/docs/Options.md index 2f51ccda21b..68a1c9a4cde 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -70,6 +70,7 @@ Most of the options accept `null` — for example, to explicitly set that DMG ic | publish | See [publish](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#PublishConfiguration). | forceCodeSigning | Whether to fail if application will be not signed (to prevent unsigned app if code signing configuration is not correct). | electronVersion | The version of electron you are packaging for. Defaults to version of `electron`, `electron-prebuilt` or `electron-prebuilt-compile` dependency. +| artifactName |

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.

### `appx` @@ -188,7 +189,7 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi | language | * [LCID Dec](https://msdn.microsoft.com/en-au/goglobal/bb964664.aspx), defaults to `1033`(`English - United States`). | warningsAsErrors | Defaults to `true`. If `warningsAsErrors` is `true` (default): NSIS will treat warnings as errors. If `warningsAsErrors` is `false`: NSIS will allow warnings. | menuCategory | 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 |

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).

+| artifactName | The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Setup ${version}.${ext}`. ### `pkg` macOS Product Archive Options @@ -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). \ No newline at end of file diff --git a/docs/Publishing Artifacts.md b/docs/Publishing Artifacts.md index 1a8109bfcd5..dd9798c19c8 100644 --- a/docs/Publishing Artifacts.md +++ b/docs/Publishing Artifacts.md @@ -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** | 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** | 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 | The channel. Defaults to `latest`. diff --git a/packages/electron-builder-core/src/core.ts b/packages/electron-builder-core/src/core.ts index 01d19fd3750..c29b7fa2989 100644 --- a/packages/electron-builder-core/src/core.ts +++ b/packages/electron-builder-core/src/core.ts @@ -86,4 +86,13 @@ export abstract class Target { finishBuild(): Promise { 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 } \ No newline at end of file diff --git a/packages/electron-builder-http/src/publishOptions.ts b/packages/electron-builder-http/src/publishOptions.ts index db06d76584b..260dba3e24e 100644 --- a/packages/electron-builder-http/src/publishOptions.ts +++ b/packages/electron-builder-http/src/publishOptions.ts @@ -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 diff --git a/packages/electron-builder/src/metadata.ts b/packages/electron-builder/src/metadata.ts index ab0a9e2a7a8..e76ee96a934 100755 --- a/packages/electron-builder/src/metadata.ts +++ b/packages/electron-builder/src/metadata.ts @@ -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" @@ -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 @@ -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 { @@ -316,7 +323,7 @@ export interface MetadataDirectories { readonly app?: string | null } -export interface PlatformSpecificBuildOptions { +export interface PlatformSpecificBuildOptions extends TargetSpecificOptions { readonly files?: Array | string | null readonly extraFiles?: Array | FilePattern | Array | string | null readonly extraResources?: Array | FilePattern | Array | string | null @@ -332,8 +339,6 @@ export interface PlatformSpecificBuildOptions { readonly fileAssociations?: Array | FileAssociation readonly publish?: Publish - - readonly forceCodeSigning?: boolean } export interface Macros { diff --git a/packages/electron-builder/src/options/macOptions.ts b/packages/electron-builder/src/options/macOptions.ts index fb22828193f..ecf09ac01dd 100644 --- a/packages/electron-builder/src/options/macOptions.ts +++ b/packages/electron-builder/src/options/macOptions.ts @@ -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" @@ -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). @@ -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. diff --git a/packages/electron-builder/src/options/winOptions.ts b/packages/electron-builder/src/options/winOptions.ts index e56cc105f08..788c4070ea8 100644 --- a/packages/electron-builder/src/options/winOptions.ts +++ b/packages/electron-builder/src/options/winOptions.ts @@ -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 } diff --git a/packages/electron-builder/src/platformPackager.ts b/packages/electron-builder/src/platformPackager.ts index 48597e228e6..87d38d7201b 100644 --- a/packages/electron-builder/src/platformPackager.ts +++ b/packages/electron-builder/src/platformPackager.ts @@ -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" @@ -394,17 +394,24 @@ export abstract class PlatformPackager 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 diff --git a/packages/electron-builder/src/targets/dmg.ts b/packages/electron-builder/src/targets/dmg.ts index 888092fe305..d0025ac46a8 100644 --- a/packages/electron-builder/src/targets/dmg.ts +++ b/packages/electron-builder/src/targets/dmg.ts @@ -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)) diff --git a/packages/electron-builder/src/targets/nsis.ts b/packages/electron-builder/src/targets/nsis.ts index 1d5fdf102a2..75297291d43 100644 --- a/packages/electron-builder/src/targets/nsis.ts +++ b/packages/electron-builder/src/targets/nsis.ts @@ -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 diff --git a/packages/electron-builder/src/targets/pkg.ts b/packages/electron-builder/src/targets/pkg.ts index cf120aca8eb..936edafc8d8 100644 --- a/packages/electron-builder/src/targets/pkg.ts +++ b/packages/electron-builder/src/targets/pkg.ts @@ -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)