diff --git a/README.md b/README.md index bcf5cdb4afd..c1a2a64e52a 100755 --- a/README.md +++ b/README.md @@ -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: diff --git a/docs/NSIS.md b/docs/NSIS.md index 64e575507b9..15c090e3423 100644 --- a/docs/NSIS.md +++ b/docs/NSIS.md @@ -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)` diff --git a/docs/Options.md b/docs/Options.md index 901d7bfd1be..6578f0318cb 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -1,6 +1,7 @@ -# Options +electron-builder configuration can be defined in the `package.json` file of your project or through the `--config ` option (defaults to `electron-builder.yml`). +If you'd like to use your package.json to store config, the `build` key should be used on the top level. -In the development `package.json` custom `build` field can be specified to customize format. For example, to change icon locations for DMG: +For example, to change icon location for DMG: ```json "build": { "dmg": { @@ -24,78 +25,49 @@ As you can see, you need to customize MacOS options only if you want to provide Don't customize paths to background and icon, — just follow conventions. -* [Application package.json](#AppMetadata) -* [Development package.json](#DevMetadata) - * [.build](#BuildMetadata) - * [.build.appx](#AppXOptions) - * [.build.directories](#MetadataDirectories) - * [.build.dmg](#DmgOptions) - * [.build.dmg.window](#DmgWindow) - * [.build.fileAssociations](#FileAssociation) - * [.build.linux](#LinuxBuildOptions) - * [.build.mac](#MacOptions) - * [.build.mas](#MasBuildOptions) - * [.build.nsis](#NsisOptions) - * [.build.protocols](#Protocol) - * [.build.snap](#SnapOptions) - * [.build.squirrelWindows](#SquirrelWindowsOptions) - * [.build.win](#WinBuildOptions) - - -# Application `package.json` +* [Configuration Options](#Config) + * [appx](#AppXOptions) + * [directories](#MetadataDirectories) + * [dmg macOS DMG Options](#DmgOptions) + * [fileAssociations File Associations](#FileAssociation) + * [linux Linux Specific Options](#LinuxBuildOptions) + * [mac macOS Specific Options](#MacOptions) + * [mas MAS (Mac Application Store) Specific Options](#MasBuildOptions) + * [nsis](#NsisOptions) + * [protocols URL Protocol Schemes](#Protocol) + * [squirrelWindows](#SquirrelWindowsOptions) + * [win Windows Specific Options](#WinBuildOptions) + * [dmg.window DMG Windows Position and Size](#DmgWindow) + * [snap [Snap](http://snapcraft.io) Specific Options](#SnapOptions) +* [Fields in the package.json](#Metadata) + + +## Configuration Options | Name | Description | --- | --- -| **name** | The application name. -| productName |

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

-| description | The application description. -| homepage |

The url to the project [homepage](https://docs.npmjs.com/files/package.json#homepage) (NuGet Package projectUrl (optional) or Linux Package URL (required)).

If not specified and your project repository is public on GitHub, it will be https://github.com/${user}/${project} by default.

-| license | *linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name. - - -# Development `package.json` -| Name | Description -| --- | --- -| **build** | See [.build](#BuildMetadata). - - -## `.build` -| Name | Description -| --- | --- -| appId |

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 [Application User Model ID](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx) for Windows (NSIS target only, Squirrel.Windows not supported).

Defaults to com.electron.${name}. It is strongly recommended that an explicit ID be set.

-| copyright | The human-readable copyright line for the app. Defaults to `Copyright © year author`. -| productName | See [AppMetadata.productName](#AppMetadata-productName). -| files |

A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the [app directory](#MetadataDirectories-app), which specifies which files to include when copying files to create the package.

See [File Patterns](#multiple-glob-patterns).

-| extraResources |

A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the project directory, when specified, copy the file or directory with matching names directly into the app’s resources directory (Contents/Resources for MacOS, resources for Linux/Windows).

Glob rules the same as for [files](#multiple-glob-patterns).

-| extraFiles | The same as [extraResources](#BuildMetadata-extraResources) but copy into the app's content directory (`Contents` for MacOS, root directory for Linux/Windows). -| asar |

Whether to package the application’s source code into an archive, using [Electron’s archive format](http://electron.atom.io/docs/tutorial/application-packaging/). Defaults to true. Node modules, that must be unpacked, will be detected automatically, you don’t need to explicitly set [asarUnpack](#BuildMetadata-asarUnpack) - please file issue if this doesn’t work.

-| asarUnpack | A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the [app directory](#MetadataDirectories-app), which specifies which files to unpack when creating the [asar](http://electron.atom.io/docs/tutorial/application-packaging/) archive. -| fileAssociations | The file associations. See [.build.fileAssociations](#FileAssociation). -| protocols | The URL protocol scheme(s) to associate the app with. See [.build.protocol](#Protocol). -| mac | See [.build.mac](#MacOptions). -| dmg | See [.build.dmg](#DmgOptions). -| mas | See [.build.mas](#MasBuildOptions). -| win | See [.build.win](#WinBuildOptions). -| nsis | See [.build.nsis](#NsisOptions). -| squirrelWindows | See [.build.squirrelWindows](#SquirrelWindowsOptions). -| appx | See [.build.appx](#AppXOptions). -| linux | See [.build.linux](#LinuxBuildOptions). -| snap | See [.build.snap](#SnapOptions). -| compression | The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly. -| afterPack | *programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned. -| beforeBuild | *programmatic API only* The function to be run before dependencies are installed or rebuilt. Works when `npmRebuild` is set to `true`. Promise must be returned. Resolving to `false` will skip dependencies install or rebuild. -| npmRebuild | Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`. -| npmSkipBuildFromSource | Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`. -| npmArgs | Additional command line arguments to use when installing app native deps. Defaults to `null`. -| nodeGypRebuild | Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`. -| electronDist | The path to custom Electron build (e.g. `~/electron/out/R`). Only macOS supported, file issue if need for Linux or Windows. -| electronDownload | The [electron-download](https://github.com/electron-userland/electron-download#usage) options. -| publish | See [.build.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). -| directories | See [.directories](#MetadataDirectories) -| electronVersion | The version of electron you are packaging for. Defaults to version of `electron`, `electron-prebuilt` or `electron-prebuilt-compile` dependency. +| appId |

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 [Application User Model ID](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx) for Windows (NSIS target only, Squirrel.Windows not supported).

Defaults to com.electron.${name}. It is strongly recommended that an explicit ID be set.

+| copyright | The human-readable copyright line for the app. Defaults to `Copyright © year author`. +| productName | See [AppMetadata.productName](#AppMetadata-productName). +| files |

A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the [app directory](#MetadataDirectories-app), which specifies which files to include when copying files to create the package.

See [File Patterns](#multiple-glob-patterns).

+| extraResources |

A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the project directory, when specified, copy the file or directory with matching names directly into the app’s resources directory (Contents/Resources for MacOS, resources for Linux/Windows).

Glob rules the same as for [files](#multiple-glob-patterns).

+| extraFiles | The same as [extraResources](#Config-extraResources) but copy into the app's content directory (`Contents` for MacOS, root directory for Linux/Windows). +| asar |

Whether to package the application’s source code into an archive, using [Electron’s archive format](http://electron.atom.io/docs/tutorial/application-packaging/). Defaults to true. Node modules, that must be unpacked, will be detected automatically, you don’t need to explicitly set [asarUnpack](#Config-asarUnpack) - please file issue if this doesn’t work.

+| asarUnpack | A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the [app directory](#MetadataDirectories-app), which specifies which files to unpack when creating the [asar](http://electron.atom.io/docs/tutorial/application-packaging/) archive. +| compression | The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly. +| afterPack | *programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned. +| beforeBuild | *programmatic API only* The function to be run before dependencies are installed or rebuilt. Works when `npmRebuild` is set to `true`. Promise must be returned. Resolving to `false` will skip dependencies install or rebuild. +| npmRebuild | Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`. +| npmSkipBuildFromSource | Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`. +| npmArgs | Additional command line arguments to use when installing app native deps. Defaults to `null`. +| nodeGypRebuild | Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`. +| electronDist | The path to custom Electron build (e.g. `~/electron/out/R`). Only macOS supported, file issue if need for Linux or Windows. +| electronDownload | The [electron-download](https://github.com/electron-userland/electron-download#usage) options. +| 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. -### `.build.appx` +### `appx` Please see [Windows AppX docs](https://msdn.microsoft.com/en-us/library/windows/apps/br211453.aspx). @@ -108,7 +80,7 @@ Please see [Windows AppX docs](https://msdn.microsoft.com/en-us/library/windows/ | identityName | Describes the contents of the package. The Name attribute is case-sensitive. Corresponds to [Identity.Name](https://msdn.microsoft.com/en-us/library/windows/apps/br211441.aspx). -### `.build.directories` +### `directories` | Name | Description | --- | --- | buildResources | The path to build resources, defaults to `build`. @@ -116,10 +88,7 @@ Please see [Windows AppX docs](https://msdn.microsoft.com/en-us/library/windows/ | app | The application directory (containing the application package.json), defaults to `app`, `www` or working directory. -### `.build.dmg` - -macOS DMG specific options. - +### `dmg` macOS DMG Options | Name | Description | --- | --- | background |

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.

See [DMG with Retina background support](http://stackoverflow.com/a/11204769/1910191).

@@ -130,24 +99,12 @@ macOS DMG specific options. | title |

The title of the produced DMG, which will be shown when mounted (volume name). Defaults to ${productName} ${version}

Macro ${productName}, ${version} and ${name} are supported.

| contents | The content — to customize icon locations. | format | The disk image format, one of `UDRW`, `UDRO`, `UDCO`, `UDZO`, `UDBZ`, `ULFO` (lzfse-compressed image (OS X 10.11+ only)). Defaults to `UDBZ` (bzip2-compressed image). -| window | The DMG windows position and size. See [.build.dmg.window](#DmgWindow). - - -### `.build.dmg.window` - -The DMG windows position and size. - -| Name | Description -| --- | --- -| x | The X position relative to left of the screen. Defaults to 400. -| y | The Y position relative to top of the screen. Defaults to 100. -| width | * The width. Defaults to background image width or 540. -| height | * The height. Defaults to background image height or 380. +| window | The DMG windows position and size. See [dmg.window](#DmgWindow). -### `.build.fileAssociations` +### `fileAssociations` File Associations -macOS and NSIS only. Array of option objects. +macOS (corresponds to [CFBundleDocumentTypes](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-101685)) and NSIS only. Array of option objects. | Name | Description | --- | --- @@ -159,10 +116,7 @@ macOS and NSIS only. Array of option objects. | isPackage | *macOS-only* Whether the document is distributed as a bundle. If set to true, the bundle directory is treated as a file. Corresponds to `LSTypeIsPackage`. -### `.build.linux` - -Linux specific build options. - +### `linux` Linux Specific Options | Name | Description | --- | --- | category | The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry). @@ -175,36 +129,30 @@ Linux specific build options. | desktop | The [Desktop file](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en) entries (name to value). | compression | *deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. Defaults to `xz`. | depends | Package dependencies. Defaults to `["gconf2", "gconf-service", "libnotify4", "libappindicator1", "libxtst6", "libnss3"]` for `deb`. -| executableName |

The executable name. Defaults to productName.

Cannot be specified per target, allowed only in the .build.linux.

+| executableName |

The executable name. Defaults to productName.

Cannot be specified per target, allowed only in the linux.

-### `.build.mac` - -MacOS specific build options. - +### `mac` macOS Specific Options | Name | Description | --- | --- | category |

The application category type, as shown in the Finder via *View -> Arrange by Application Category* when viewing the Applications directory.

For example, "category": "public.app-category.developer-tools" will set the application category to *Developer Tools*.

Valid values are listed in [Apple’s documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).

| target | The target package type: list of `default`, `dmg`, `mas`, `pkg`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `default` (dmg and zip for Squirrel.Mac). -| identity |

The name of certificate to use when signing. Consider using environment variables [CSC_LINK or CSC_NAME](https://github.com/electron-userland/electron-builder/wiki/Code-Signing) instead of specifying this option. MAS installer identity is specified in the [.build.mas](#MasBuildOptions-identity).

+| identity |

The name of certificate to use when signing. Consider using environment variables [CSC_LINK or CSC_NAME](https://github.com/electron-userland/electron-builder/wiki/Code-Signing) instead of specifying this option. MAS installer identity is specified in the [mas](#MasBuildOptions-identity).

| icon | The path to application icon. Defaults to `build/icon.icns` (consider using this convention instead of complicating your configuration). -| entitlements |

The path to entitlements file for signing the app. build/entitlements.mac.plist will be used if exists (it is a recommended way to set). MAS entitlements is specified in the [.build.mas](#MasBuildOptions-entitlements).

+| entitlements |

The path to entitlements file for signing the app. build/entitlements.mac.plist will be used if exists (it is a recommended way to set). MAS entitlements is specified in the [mas](#MasBuildOptions-entitlements).

| entitlementsInherit |

The path to child entitlements which inherit the security settings for signing frameworks and bundles of a distribution. build/entitlements.mac.inherit.plist will be used if exists (it is a recommended way to set). Otherwise [default](https://github.com/electron-userland/electron-osx-sign/blob/master/default.entitlements.darwin.inherit.plist).

This option only applies when signing with entitlements provided.

| bundleVersion | The `CFBundleVersion`. Do not use it unless [you need to](see (https://github.com/electron-userland/electron-builder/issues/565#issuecomment-230678643)). | helperBundleId | The bundle identifier to use in the application helper's plist. Defaults to `${appBundleIdentifier}.helper`. -### `.build.mas` - -MAS (Mac Application Store) specific options (in addition to `build.mac`). - +### `mas` MAS (Mac Application Store) Specific Options | Name | Description | --- | --- | entitlements |

The path to entitlements file for signing the app. build/entitlements.mas.plist will be used if exists (it is a recommended way to set). Otherwise [default](https://github.com/electron-userland/electron-osx-sign/blob/master/default.entitlements.mas.plist).

| entitlementsInherit |

The path to child entitlements which inherit the security settings for signing frameworks and bundles of a distribution. build/entitlements.mas.inherit.plist will be used if exists (it is a recommended way to set). Otherwise [default](https://github.com/electron-userland/electron-osx-sign/blob/master/default.entitlements.mas.inherit.plist).

-### `.build.nsis` +### `nsis` See [NSIS target notes](https://github.com/electron-userland/electron-builder/wiki/NSIS). @@ -227,9 +175,9 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi | 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. -### `.build.protocols` +### `protocols` URL Protocol Schemes -macOS only. +Protocols to associate the app with. macOS only. Please note — on macOS [you need to register an `open-url` event handler](http://electron.atom.io/docs/api/app/#event-open-url-macos). @@ -239,22 +187,8 @@ Please note — on macOS [you need to register an `open-url` event handler](http | role | *macOS-only* The app’s role with respect to the type. The value can be `Editor`, `Viewer`, `Shell`, or `None`. Defaults to `Editor`. | **schemes** | The schemes. e.g. `["irc", "ircs"]`. - -### `.build.snap` - -[Snaps](http://snapcraft.io) specific build options. - -| Name | Description -| --- | --- -| confinement | The type of confinement supported by the snap. Can be either `devmode` (i.e. this snap doesn’t support running under confinement) or `strict` (i.e. full confinement supported via interfaces). Defaults to `strict`. -| summary | The 78 character long summary. Defaults to [productName](#AppMetadata-productName). -| grade |

The quality grade of the snap. It can be either devel (i.e. a development version of the snap, so not to be published to the “stable” or “candidate” channels) or “stable” (i.e. a stable release or release candidate, which can be released to all channels). Defaults to stable.

-| assumes | The list of features that must be supported by the core in order for this snap to install. -| stagePackages |

The list of Ubuntu packages to use that are needed to support the app part creation. Like depends for deb. Defaults to ["libnotify4", "libappindicator1", "libxtst6", "libnss3", "libxss1", "fontconfig-config", "gconf2", "libasound2"].

-| ubuntuAppPlatformContent |

Specify ubuntu-app-platform1 to use [ubuntu-app-platform](https://insights.ubuntu.com/2016/11/17/how-to-create-snap-packages-on-qt-applications/). Snap size will be greatly reduced, but it is not recommended for now because “the snaps must be connected before running uitk-gallery for the first time”.

- -### `.build.squirrelWindows` +### `squirrelWindows` To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency. @@ -268,10 +202,7 @@ To use Squirrel.Windows please install `electron-builder-squirrel-windows` depen | useAppIdAsId | Use `appId` to identify package instead of `name`. -### `.build.win` - -Windows specific build options. - +### `win` Windows Specific Options | Name | Description | --- | --- | target |

Target package type: list of nsis, appx, squirrel, 7z, zip, tar.xz, tar.lz, tar.gz, tar.bz2, dir. Defaults to nsis.

AppX package can be built only on Windows 10.

To use Squirrel.Windows please install electron-builder-squirrel-windows dependency.

@@ -284,11 +215,44 @@ Windows specific build options. | rfc3161TimeStampServer | The URL of the RFC 3161 time stamp server. Defaults to `http://timestamp.comodoca.com/rfc3161`. | timeStampServer | The URL of the time stamp server. Defaults to `http://timestamp.verisign.com/scripts/timstamp.dll`. + +### `dmg.window` DMG Windows Position and Size +| Name | Description +| --- | --- +| x | The X position relative to left of the screen. Defaults to 400. +| y | The Y position relative to top of the screen. Defaults to 100. +| width | * The width. Defaults to background image width or 540. +| height | * The height. Defaults to background image height or 380. + + +### `snap` [Snap](http://snapcraft.io) Specific Options +| Name | Description +| --- | --- +| confinement | The type of confinement supported by the snap. Can be either `devmode` (i.e. this snap doesn’t support running under confinement) or `strict` (i.e. full confinement supported via interfaces). Defaults to `strict`. +| summary | The 78 character long summary. Defaults to [productName](#AppMetadata-productName). +| grade |

The quality grade of the snap. It can be either devel (i.e. a development version of the snap, so not to be published to the “stable” or “candidate” channels) or “stable” (i.e. a stable release or release candidate, which can be released to all channels). Defaults to stable.

+| assumes | The list of features that must be supported by the core in order for this snap to install. +| stagePackages |

The list of Ubuntu packages to use that are needed to support the app part creation. Like depends for deb. Defaults to ["libnotify4", "libappindicator1", "libxtst6", "libnss3", "libxss1", "fontconfig-config", "gconf2", "libasound2"].

+| ubuntuAppPlatformContent |

Specify ubuntu-app-platform1 to use [ubuntu-app-platform](https://insights.ubuntu.com/2016/11/17/how-to-create-snap-packages-on-qt-applications/). Snap size will be greatly reduced, but it is not recommended for now because “the snaps must be connected before running uitk-gallery for the first time”.

+ + +## Fields in the package.json + +Some standard fields should be defined in the `package.json`. + +| Name | Description +| --- | --- +| **name** | The application name. +| productName |

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

+| description | The application description. +| homepage |

The url to the project [homepage](https://docs.npmjs.com/files/package.json#homepage) (NuGet Package projectUrl (optional) or Linux Package URL (required)).

If not specified and your project repository is public on GitHub, it will be https://github.com/${user}/${project} by default.

+| license | *linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name. + -# File Patterns +## File Patterns -[build.files](#BuildMetadata-files) defaults to: +[files](#Config-files) defaults to: * `**/*` * `!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}` * `!**/node_modules/.bin` @@ -306,7 +270,7 @@ If directory matched, all contents are copied. So, you can just specify `foo` to Remember that default pattern `**/*` **is not added to your custom** if some of your patterns is not ignore (i.e. not starts with `!`). `package.json` is added to your custom in any case. All default ignores are added in any case — you don't need to repeat it if you configure own patterns. -May be specified in the platform options (e.g. in the `build.mac`). +May be specified in the platform options (e.g. in the [mac](#MacOptions)). ## Multiple Glob Patterns ```js @@ -322,7 +286,7 @@ May be specified in the platform options (e.g. in the `build.mac`). ] ``` -## Excluding directories +### Excluding directories Remember that `!doNotCopyMe/**/*` would match the files *in* the `doNotCopyMe` directory, but not the directory itself, so the [empty directory](https://github.com/gulpjs/gulp/issues/165#issuecomment-32613179) would be created. Solution — use macro `${/*}`, e.g. `!doNotCopyMe${/*}`. @@ -344,5 +308,5 @@ If `to` is given as a relative path, it is relative to the app's content directo You can you `${os}` and `${arch}` in the `from` and `to` fields as well. -# Build Version Management +## 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 3c1209117e0..b0c07d25556 100644 --- a/docs/Publishing Artifacts.md +++ b/docs/Publishing Artifacts.md @@ -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": { @@ -56,13 +56,13 @@ But please consider using automatic rules instead of explicitly specifying `publ ``` -* [.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) -### `.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. @@ -79,7 +79,7 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f | owner | The owner. -### `.build.publish` Bintray +### `publish` Bintray | Name | Description | --- | --- | package | The Bintray package name. @@ -87,14 +87,14 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f | user | The Bintray user account. Used in cases where the owner is an organization. -### `.build.publish` Generic (any https server) +### `publish` Generic (any https server) | Name | Description | --- | --- | **url** | The base url. e.g. `https://s3.amazonaws.com/bucket_name` | channel | The channel. Defaults to `latest`. -### `.build.publish` GitHub +### `publish` GitHub | Name | Description | --- | --- | repo | The repository name. [Detected automatically](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#github-repository). diff --git a/docs/Two package.json Structure.md b/docs/Two package.json Structure.md index b37996de8e9..0499b24e638 100644 --- a/docs/Two package.json Structure.md +++ b/docs/Two package.json Structure.md @@ -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). diff --git a/package.json b/package.json index aab3465f488..380db61ca30 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/packages/electron-auto-updater/package.json b/packages/electron-auto-updater/package.json index 0ba2c14b171..37fa2fffbee 100644 --- a/packages/electron-auto-updater/package.json +++ b/packages/electron-auto-updater/package.json @@ -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" diff --git a/packages/electron-builder-http/src/publishOptions.ts b/packages/electron-builder-http/src/publishOptions.ts index f7cdb91ec81..04ca1f23f77 100644 --- a/packages/electron-builder-http/src/publishOptions.ts +++ b/packages/electron-builder-http/src/publishOptions.ts @@ -3,7 +3,7 @@ export type PublishProvider = "github" | "bintray" | "generic" export type Publish = string | Array | PublishConfiguration | GithubOptions | BintrayOptions | GenericServerOptions | Array | Array | Array | Array | 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. @@ -29,7 +29,7 @@ export interface PublishConfiguration { } /* -### `.build.publish` Generic (any https server) +### `publish` Generic (any https server) */ export interface GenericServerOptions extends PublishConfiguration { /* @@ -54,7 +54,7 @@ export interface UpdateInfo extends VersionInfo { } /* -### `.build.publish` GitHub +### `publish` GitHub */ export interface GithubOptions extends PublishConfiguration { /* @@ -69,7 +69,7 @@ export interface GithubOptions extends PublishConfiguration { } /* -### `.build.publish` Bintray +### `publish` Bintray */ export interface BintrayOptions extends PublishConfiguration { /* diff --git a/packages/electron-builder-util/package.json b/packages/electron-builder-util/package.json index a1f379ace68..c90e8d02aa3 100644 --- a/packages/electron-builder-util/package.json +++ b/packages/electron-builder-util/package.json @@ -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" diff --git a/packages/electron-builder-util/src/deepAssign.ts b/packages/electron-builder-util/src/deepAssign.ts index daa52c61ff1..3a5474ce45c 100644 --- a/packages/electron-builder-util/src/deepAssign.ts +++ b/packages/electron-builder-util/src/deepAssign.ts @@ -1,4 +1,8 @@ function isObject(x: any) { + if (Array.isArray(x)) { + return false + } + const type = typeof x return type === "object" || type === "function" } @@ -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 { diff --git a/packages/electron-builder-util/src/util.ts b/packages/electron-builder-util/src/util.ts index 10eced75846..6f8d1fb1f3c 100644 --- a/packages/electron-builder-util/src/util.ts +++ b/packages/electron-builder-util/src/util.ts @@ -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" @@ -140,48 +139,6 @@ export function handleProcess(event: string, childProcess: ChildProcess, command }) } -export async function getElectronVersion(packageData: any, packageJsonPath: string): Promise { - 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 { if (userAppDir != null) { const absolutePath = path.resolve(projectDir, userAppDir) diff --git a/packages/electron-builder/src/appInfo.ts b/packages/electron-builder/src/appInfo.ts index 80c25419d44..2e9cf05a250 100644 --- a/packages/electron-builder/src/appInfo.ts +++ b/packages/electron-builder/src/appInfo.ts @@ -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" @@ -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 = (this.config)["build-version"] || process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM || process.env.BUILD_NUMBER @@ -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) } @@ -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)) { @@ -71,7 +71,7 @@ export class AppInfo { } get name(): string { - return this.metadata.name + return this.metadata.name! } get copyright(): string { diff --git a/packages/electron-builder/src/cli/install-app-deps.ts b/packages/electron-builder/src/cli/install-app-deps.ts index bc582bb81e9..07cd9802981 100644 --- a/packages/electron-builder/src/cli/install-app-deps.ts +++ b/packages/electron-builder/src/cli/install-app-deps.ts @@ -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() { @@ -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 = 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() diff --git a/packages/electron-builder/src/cli/node-gyp-rebuild.ts b/packages/electron-builder/src/cli/node-gyp-rebuild.ts index 096fb37e71a..e7b1a206aab 100644 --- a/packages/electron-builder/src/cli/node-gyp-rebuild.ts +++ b/packages/electron-builder/src/cli/node-gyp-rebuild.ts @@ -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" @@ -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), }) } diff --git a/packages/electron-builder/src/index.ts b/packages/electron-builder/src/index.ts index 655366a0fa1..525e8bdd392 100644 --- a/packages/electron-builder/src/index.ts +++ b/packages/electron-builder/src/index.ts @@ -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" diff --git a/packages/electron-builder/src/macPackager.ts b/packages/electron-builder/src/macPackager.ts index 243c4b849e7..dc93ce80858 100644 --- a/packages/electron-builder/src/macPackager.ts +++ b/packages/electron-builder/src/macPackager.ts @@ -33,7 +33,7 @@ export default class MacPackager extends PlatformPackager { } 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 { diff --git a/packages/electron-builder/src/metadata.ts b/packages/electron-builder/src/metadata.ts index ad161505832..6e62a6a15d2 100755 --- a/packages/electron-builder/src/metadata.ts +++ b/packages/electron-builder/src/metadata.ts @@ -6,22 +6,23 @@ import { WinBuildOptions, NsisOptions, SquirrelWindowsOptions, AppXOptions } fro import { LinuxBuildOptions, SnapOptions } from "./options/linuxOptions" import { Platform } from "electron-builder-core" +/* +## Fields in the package.json + +Some standard fields should be defined in the `package.json`. + */ export interface Metadata { readonly repository?: string | RepositoryInfo | null - dependencies?: { [key: string]: string } -} + readonly dependencies?: { [key: string]: string } -/* - # Application `package.json` - */ -export interface AppMetadata extends Metadata { readonly version?: string /* The application name. + @required */ - readonly name: string + readonly name?: string /* As [name](#AppMetadata-name), but allows you to specify a product name for your executable which contains spaces and other special characters @@ -49,16 +50,8 @@ export interface AppMetadata extends Metadata { *linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name. */ readonly license?: string | null -} -/* - # Development `package.json` - */ -export interface DevMetadata extends Metadata { - /* - See [.build](#BuildMetadata). - */ - readonly build: BuildMetadata + readonly build?: Config } export interface RepositoryInfo { @@ -73,9 +66,9 @@ export interface AuthorMetadata { export type CompressionLevel = "store" | "normal" | "maximum" /* - ## `.build` + ## Configuration Options */ -export interface BuildMetadata extends PlatformSpecificBuildOptions { +export interface Config extends PlatformSpecificBuildOptions { /* 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 @@ -113,13 +106,13 @@ export interface BuildMetadata extends PlatformSpecificBuildOptions { readonly extraResources?: Array | string | null /* - The same as [extraResources](#BuildMetadata-extraResources) but copy into the app's content directory (`Contents` for MacOS, root directory for Linux/Windows). + The same as [extraResources](#Config-extraResources) but copy into the app's content directory (`Contents` for MacOS, root directory for Linux/Windows). */ readonly extraFiles?: Array | string | null /* Whether to package the application's source code into an archive, using [Electron's archive format](http://electron.atom.io/docs/tutorial/application-packaging/). Defaults to `true`. - Node modules, that must be unpacked, will be detected automatically, you don't need to explicitly set [asarUnpack](#BuildMetadata-asarUnpack) - please file issue if this doesn't work. + Node modules, that must be unpacked, will be detected automatically, you don't need to explicitly set [asarUnpack](#Config-asarUnpack) - please file issue if this doesn't work. */ readonly asar?: AsarOptions | boolean | null @@ -128,61 +121,21 @@ export interface BuildMetadata extends PlatformSpecificBuildOptions { */ readonly asarUnpack?: Array | string | null - /* - The file associations. See [.build.fileAssociations](#FileAssociation). - */ readonly fileAssociations?: Array | FileAssociation - /* - The URL protocol scheme(s) to associate the app with. See [.build.protocol](#Protocol). - */ readonly protocols?: Array | Protocol - /* - See [.build.mac](#MacOptions). - */ readonly mac?: MacOptions | null - - /* - See [.build.dmg](#DmgOptions). - */ readonly dmg?: DmgOptions | null - - /* - See [.build.mas](#MasBuildOptions). - */ readonly mas?: MasBuildOptions | null - /* - See [.build.win](#WinBuildOptions). - */ readonly win?: WinBuildOptions | null - - /* - See [.build.nsis](#NsisOptions). - */ readonly nsis?: NsisOptions | null - - /* - See [.build.squirrelWindows](#SquirrelWindowsOptions). - */ readonly squirrelWindows?: SquirrelWindowsOptions | null - - /* - See [.build.appx](#AppXOptions). - */ readonly appx?: AppXOptions | null - /* - See [.build.linux](#LinuxBuildOptions). - */ readonly linux?: LinuxBuildOptions | null - readonly deb?: LinuxBuildOptions | null - - /* - See [.build.snap](#SnapOptions). - */ readonly snap?: SnapOptions | null /* @@ -233,7 +186,7 @@ export interface BuildMetadata extends PlatformSpecificBuildOptions { readonly icon?: string | null /* - See [.build.publish](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#PublishConfiguration). + See [publish](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#PublishConfiguration). */ readonly publish?: Publish @@ -242,9 +195,6 @@ export interface BuildMetadata extends PlatformSpecificBuildOptions { */ readonly forceCodeSigning?: boolean - /* - See [.directories](#MetadataDirectories) - */ readonly directories?: MetadataDirectories | null /* @@ -267,9 +217,9 @@ export interface BeforeBuildContext { } /* - ### `.build.fileAssociations` + ### `fileAssociations` File Associations - macOS and NSIS only. Array of option objects. + macOS (corresponds to [CFBundleDocumentTypes](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-101685)) and NSIS only. Array of option objects. */ export interface FileAssociation { /* @@ -304,9 +254,9 @@ export interface FileAssociation { } /* - ### `.build.protocols` + ### `protocols` URL Protocol Schemes - macOS only. + Protocols to associate the app with. macOS only. Please note — on macOS [you need to register an `open-url` event handler](http://electron.atom.io/docs/api/app/#event-open-url-macos). */ @@ -328,7 +278,7 @@ export interface Protocol { } /* - ### `.build.directories` + ### `directories` */ export interface MetadataDirectories { /* @@ -365,8 +315,4 @@ export interface PlatformSpecificBuildOptions { readonly publish?: Publish readonly forceCodeSigning?: boolean -} - -export function getDirectoriesConfig(m: DevMetadata) { - return m.build.directories || (m).directories } \ No newline at end of file diff --git a/packages/electron-builder/src/options/linuxOptions.ts b/packages/electron-builder/src/options/linuxOptions.ts index b205790b25b..b08bdec2762 100644 --- a/packages/electron-builder/src/options/linuxOptions.ts +++ b/packages/electron-builder/src/options/linuxOptions.ts @@ -1,9 +1,7 @@ import { PlatformSpecificBuildOptions } from "../metadata" /* - ### `.build.linux` - - Linux specific build options. + ### `linux` Linux Specific Options */ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions { /* @@ -67,15 +65,13 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions { /* The executable name. Defaults to `productName`. - Cannot be specified per target, allowed only in the `.build.linux`. + Cannot be specified per target, allowed only in the `linux`. */ readonly executableName?: string | null } /* - ### `.build.snap` - - [Snaps](http://snapcraft.io) specific build options. + ### `snap` [Snap](http://snapcraft.io) Specific Options */ export interface SnapOptions extends LinuxBuildOptions { /* diff --git a/packages/electron-builder/src/options/macOptions.ts b/packages/electron-builder/src/options/macOptions.ts index 46f5f47f4e1..cb7ab8d501d 100644 --- a/packages/electron-builder/src/options/macOptions.ts +++ b/packages/electron-builder/src/options/macOptions.ts @@ -3,9 +3,7 @@ import { PlatformSpecificBuildOptions } from "../metadata" export type MacOsTargetName = "default" | "dmg" | "mas" | "pkg" | "7z" | "zip" | "tar.xz" | "tar.lz" | "tar.gz" | "tar.bz2" | "dir" /* - ### `.build.mac` - - MacOS specific build options. + ### `mac` macOS Specific Options */ export interface MacOptions extends PlatformSpecificBuildOptions { /* @@ -24,7 +22,7 @@ export interface MacOptions extends PlatformSpecificBuildOptions { /* The name of certificate to use when signing. Consider using environment variables [CSC_LINK or CSC_NAME](https://github.com/electron-userland/electron-builder/wiki/Code-Signing) instead of specifying this option. - MAS installer identity is specified in the [.build.mas](#MasBuildOptions-identity). + MAS installer identity is specified in the [mas](#MasBuildOptions-identity). */ readonly identity?: string | null @@ -35,7 +33,7 @@ export interface MacOptions extends PlatformSpecificBuildOptions { /* The path to entitlements file for signing the app. `build/entitlements.mac.plist` will be used if exists (it is a recommended way to set). - MAS entitlements is specified in the [.build.mas](#MasBuildOptions-entitlements). + MAS entitlements is specified in the [mas](#MasBuildOptions-entitlements). */ readonly entitlements?: string | null @@ -59,9 +57,7 @@ export interface MacOptions extends PlatformSpecificBuildOptions { } /* - ### `.build.dmg` - - macOS DMG specific options. + ### `dmg` macOS DMG Options */ export interface DmgOptions { /* @@ -110,15 +106,13 @@ export interface DmgOptions { readonly format?: string /* - The DMG windows position and size. See [.build.dmg.window](#DmgWindow). + The DMG windows position and size. See [dmg.window](#DmgWindow). */ window?: DmgWindow } /* - ### `.build.dmg.window` - - The DMG windows position and size. + ### `dmg.window` DMG Windows Position and Size */ export interface DmgWindow { /* @@ -151,9 +145,7 @@ export interface DmgContent { } /* - ### `.build.mas` - - MAS (Mac Application Store) specific options (in addition to `build.mac`). + ### `mas` MAS (Mac Application Store) Specific Options */ export interface MasBuildOptions extends MacOptions { /* diff --git a/packages/electron-builder/src/options/winOptions.ts b/packages/electron-builder/src/options/winOptions.ts index f451db036bc..8ea1f9e39a6 100644 --- a/packages/electron-builder/src/options/winOptions.ts +++ b/packages/electron-builder/src/options/winOptions.ts @@ -1,9 +1,7 @@ import { PlatformSpecificBuildOptions } from "../metadata" /* - ### `.build.win` - - Windows specific build options. + ### `win` Windows Specific Options */ export interface WinBuildOptions extends PlatformSpecificBuildOptions { /* @@ -61,7 +59,7 @@ export interface WinBuildOptions extends PlatformSpecificBuildOptions { } /* - ### `.build.nsis` + ### `nsis` See [NSIS target notes](https://github.com/electron-userland/electron-builder/wiki/NSIS). */ @@ -147,7 +145,7 @@ export interface NsisOptions { } /* - ### `.build.squirrelWindows` + ### `squirrelWindows` To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency. */ @@ -190,7 +188,7 @@ export interface SquirrelWindowsOptions extends WinBuildOptions { } /* - ### `.build.appx` + ### `appx` Please see [Windows AppX docs](https://msdn.microsoft.com/en-us/library/windows/apps/br211453.aspx). */ diff --git a/packages/electron-builder/src/packager.ts b/packages/electron-builder/src/packager.ts index a1098ac036b..cea6ee5d883 100644 --- a/packages/electron-builder/src/packager.ts +++ b/packages/electron-builder/src/packager.ts @@ -1,9 +1,9 @@ import * as path from "path" -import { computeDefaultAppDirectory, getElectronVersion, use, exec, isEmptyOrSpaces } from "electron-builder-util" +import { computeDefaultAppDirectory, use, exec, isEmptyOrSpaces } from "electron-builder-util" import { all, executeFinally } from "electron-builder-util/out/promise" import { EventEmitter } from "events" import BluebirdPromise from "bluebird-lst-c" -import { AppMetadata, DevMetadata, BuildMetadata, getDirectoriesConfig, AfterPackContext } from "./metadata" +import { Metadata, Config, AfterPackContext } from "./metadata" import { PlatformPackager } from "./platformPackager" import { WinPackager } from "./winPackager" import * as errorMessages from "./errorMessages" @@ -14,7 +14,7 @@ import { warn, log } from "electron-builder-util/out/log" import { AppInfo } from "./appInfo" import MacPackager from "./macPackager" import { createTargets } from "./targets/targetFactory" -import { readPackageJson } from "./util/readPackageJson" +import { readPackageJson, getElectronVersion, loadConfig } from "./util/readPackageJson" import { TmpDir } from "electron-builder-util/out/tmp" import { getGypEnv, installOrRebuild } from "./yarn" import { Platform, Arch, Target } from "electron-builder-core" @@ -29,12 +29,14 @@ export class Packager implements BuildInfo { readonly projectDir: string appDir: string - metadata: AppMetadata + metadata: Metadata - devMetadata: DevMetadata + private devMetadata: Metadata - get config(): BuildMetadata { - return this.devMetadata.build + private _config: Config + + get config(): Config { + return this._config } isTwoPackageJsonProjectLayoutUsed = true @@ -76,68 +78,74 @@ export class Packager implements BuildInfo { this.eventEmitter.emit("artifactCreated", event) } - get devPackageFile(): string { - return path.join(this.projectDir, "package.json") - } - async build(): Promise>> { - const extraMetadata = this.options.extraMetadata - const extraBuildMetadata = extraMetadata == null ? null : extraMetadata.build + //noinspection JSDeprecatedSymbols + const devMetadataFromOptions = this.options.devMetadata + if (devMetadataFromOptions != null) { + warn("devMetadata is deprecated, please use config instead") + } - let devMetadataFromOptions = this.options.devMetadata - const buildConfigFromOptions = this.options.config - if (buildConfigFromOptions != null) { - if (devMetadataFromOptions != null) { + let configFromOptions = this.options.config + if (devMetadataFromOptions != null) { + if (configFromOptions != null) { throw new Error("devMetadata and config cannot be used in conjunction") } - devMetadataFromOptions = {build: buildConfigFromOptions} + configFromOptions = devMetadataFromOptions.build } - const devPackageFile = this.devPackageFile - this.devMetadata = deepAssign(await readPackageJson(devPackageFile), devMetadataFromOptions) + const config = deepAssign(await loadConfig(this.projectDir), configFromOptions) + const extraMetadata = this.options.extraMetadata if (extraMetadata != null) { + const extraBuildMetadata = extraMetadata.build if (extraBuildMetadata != null) { - deepAssign(this.devMetadata, {build: extraBuildMetadata}) + deepAssign(config, extraBuildMetadata) delete extraMetadata.build } if (extraMetadata.directories != null) { - deepAssign(this.devMetadata, {directories: extraMetadata.directories}) + warn(`--em.directories is deprecated, please specify as --em.build.directories"`) + deepAssign(config, {directories: extraMetadata.directories}) delete extraMetadata.directories } } - this.appDir = await computeDefaultAppDirectory(this.projectDir, use(getDirectoriesConfig(this.devMetadata), it => it!.app)) + this._config = config + this.appDir = await computeDefaultAppDirectory(this.projectDir, use(config.directories, it => it!.app)) this.isTwoPackageJsonProjectLayoutUsed = this.appDir !== this.projectDir + if (this.isTwoPackageJsonProjectLayoutUsed) { + } + + const devPackageFile = path.join(this.projectDir, "package.json") const appPackageFile = this.isTwoPackageJsonProjectLayoutUsed ? path.join(this.appDir, "package.json") : devPackageFile + this.metadata = deepAssign(await readPackageJson(appPackageFile), this.options.appMetadata, extraMetadata) if (this.isTwoPackageJsonProjectLayoutUsed) { - this.metadata = deepAssign(await readPackageJson(appPackageFile), this.options.appMetadata, extraMetadata) + this.devMetadata = deepAssign(await readPackageJson(devPackageFile), devMetadataFromOptions) } else { + this.devMetadata = this.metadata if (this.options.appMetadata != null) { deepAssign(this.devMetadata, this.options.appMetadata) } if (extraMetadata != null) { deepAssign(this.devMetadata, extraMetadata) } - this.metadata = this.devMetadata } this.checkMetadata(appPackageFile, devPackageFile) checkConflictingOptions(this.config) - this.electronVersion = await getElectronVersion(this.devMetadata, devPackageFile) + this.electronVersion = await getElectronVersion(this.config, this.projectDir) - this.appInfo = new AppInfo(this.metadata, this.devMetadata, this) + this.appInfo = new AppInfo(this.metadata, this) const cleanupTasks: Array<() => Promise> = [] return await executeFinally(this.doBuild(cleanupTasks), () => all(cleanupTasks.map(it => it()).concat(this.tempDirManager.cleanup()))) } private async doBuild(cleanupTasks: Array<() => Promise>): Promise>> { const distTasks: Array> = [] - const outDir = path.resolve(this.projectDir, use(getDirectoriesConfig(this.devMetadata), it => it!.output) || "dist") + const outDir = path.resolve(this.projectDir, use(this.config.directories, it => it!.output) || "dist") const platformToTarget: Map> = new Map() // custom packager - don't check wine @@ -391,4 +399,4 @@ function checkDependencies(dependencies?: { [key: string]: string }) { + `Please remove it from the "dependencies" section in your package.json.`) } } -} +} \ No newline at end of file diff --git a/packages/electron-builder/src/packagerApi.ts b/packages/electron-builder/src/packagerApi.ts index 9707ba52f77..881d623d277 100644 --- a/packages/electron-builder/src/packagerApi.ts +++ b/packages/electron-builder/src/packagerApi.ts @@ -1,6 +1,6 @@ import { Platform, Arch, Target } from "electron-builder-core" import { PlatformPackager } from "./platformPackager" -import { DevMetadata, BuildMetadata, AppMetadata, AfterPackContext } from "./metadata" +import { Metadata, Config, AfterPackContext } from "./metadata" import { PublishConfiguration } from "electron-builder-http/out/publishOptions" import { TmpDir } from "electron-builder-util/out/tmp" import { AppInfo } from "./appInfo" @@ -19,23 +19,18 @@ export interface PackagerOptions { platformPackagerFactory?: ((info: BuildInfo, platform: Platform, cleanupTasks: Array<() => Promise>) => PlatformPackager) | null /** - * The same as [development package.json](https://github.com/electron-userland/electron-builder/wiki/Options#development-packagejson). - * - * Development `package.json` will be still read, but options specified in this object will override. + * @deprecated Use {@link PackagerOptions#config} instead. */ - readonly devMetadata?: DevMetadata + readonly devMetadata?: Metadata - /* - See [.build](#BuildMetadata). - */ - readonly config?: BuildMetadata + readonly config?: Config /** * The same as [application package.json](https://github.com/electron-userland/electron-builder/wiki/Options#AppMetadata). * * Application `package.json` will be still read, but options specified in this object will override. */ - readonly appMetadata?: AppMetadata + readonly appMetadata?: Metadata readonly effectiveOptionComputed?: (options: any) => Promise @@ -47,15 +42,12 @@ export interface PackagerOptions { export interface BuildInfo { options: PackagerOptions - metadata: AppMetadata - - devMetadata: DevMetadata + metadata: Metadata - config: BuildMetadata + config: Config projectDir: string appDir: string - devPackageFile: string electronVersion: string diff --git a/packages/electron-builder/src/platformPackager.ts b/packages/electron-builder/src/platformPackager.ts index af460194bfa..879ef73b2fb 100644 --- a/packages/electron-builder/src/platformPackager.ts +++ b/packages/electron-builder/src/platformPackager.ts @@ -1,4 +1,4 @@ -import { PlatformSpecificBuildOptions, FileAssociation, BuildMetadata, getDirectoriesConfig } from "./metadata" +import { PlatformSpecificBuildOptions, FileAssociation, Config } from "./metadata" import BluebirdPromise from "bluebird-lst-c" import * as path from "path" import { readdir, remove, rename } from "fs-extra-p" @@ -24,7 +24,7 @@ export abstract class PlatformPackager readonly projectDir: string readonly buildResourcesDir: string - readonly config: BuildMetadata + readonly config: Config readonly platformSpecificBuildOptions: DC @@ -80,7 +80,7 @@ export abstract class PlatformPackager } get relativeBuildResourcesDirname() { - return use(getDirectoriesConfig(this.info.devMetadata), it => it!.buildResources) || "build" + return use(this.config.directories, it => it!.buildResources) || "build" } protected computeAppOutDir(outDir: string, arch: Arch): string { @@ -169,10 +169,10 @@ export abstract class PlatformPackager const deprecatedIgnore = (this.config).ignore if (deprecatedIgnore != null) { if (typeof deprecatedIgnore === "function") { - warn(`"ignore" is specified as function, may be new "files" option will be suit your needs? Please see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`) + warn(`"ignore" is specified as function, may be new "files" option will be suit your needs? Please see https://github.com/electron-userland/electron-builder/wiki/Options#Config-files`) } else { - warn(`"ignore" is deprecated, please use "files", see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`) + warn(`"ignore" is deprecated, please use "files", see https://github.com/electron-userland/electron-builder/wiki/Options#Config-files`) } rawFilter = deprecatedUserIgnoreFilter(deprecatedIgnore, appDir) } diff --git a/packages/electron-builder/src/publish/publisher.ts b/packages/electron-builder/src/publish/publisher.ts index 5ab5a4ea2ea..36241496f60 100644 --- a/packages/electron-builder/src/publish/publisher.ts +++ b/packages/electron-builder/src/publish/publisher.ts @@ -4,7 +4,6 @@ import { stat } from "fs-extra-p" import { basename } from "path" import { BuildInfo } from "../packagerApi" import { PublishConfiguration, GithubOptions, BintrayOptions, GenericServerOptions } from "electron-builder-http/out/publishOptions" -import { warn } from "electron-builder-util/out/log" export type PublishPolicy = "onTag" | "onTagOrDraft" | "always" | "never" @@ -50,8 +49,7 @@ export async function getResolvedPublishConfig(packager: BuildInfo, publishConfi return null } - warn("Cannot detect repository by .git/config") - throw new Error(`Please specify "repository" in the dev package.json ('${packager.devPackageFile}').\nPlease see https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts`) + throw new Error(`Cannot detect repository by .git/config. Please specify "repository" in the package.json (https://docs.npmjs.com/files/package.json#repository).\nPlease see https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts`) } let owner = publishConfig.owner diff --git a/packages/electron-builder/src/repositoryInfo.ts b/packages/electron-builder/src/repositoryInfo.ts index ad5e2a5b287..cd1a3683e84 100644 --- a/packages/electron-builder/src/repositoryInfo.ts +++ b/packages/electron-builder/src/repositoryInfo.ts @@ -1,6 +1,6 @@ import { fromUrl as parseRepositoryUrl, Info } from "hosted-git-info" import { readFile } from "fs-extra-p" -import { AppMetadata, Metadata, RepositoryInfo } from "./metadata" +import { Metadata, RepositoryInfo } from "./metadata" import * as path from "path" export interface RepositorySlug { @@ -8,7 +8,7 @@ export interface RepositorySlug { project: string } -export function getRepositoryInfo(metadata?: AppMetadata, devMetadata?: Metadata): Promise { +export function getRepositoryInfo(metadata?: Metadata, devMetadata?: Metadata): Promise { return _getInfo((devMetadata == null ? null : devMetadata.repository) || (metadata == null ? null : metadata.repository)) } diff --git a/packages/electron-builder/src/util/readPackageJson.ts b/packages/electron-builder/src/util/readPackageJson.ts index e9258e2d4ff..747d4e6e111 100644 --- a/packages/electron-builder/src/util/readPackageJson.ts +++ b/packages/electron-builder/src/util/readPackageJson.ts @@ -1,5 +1,8 @@ import * as path from "path" import { readJson, readFile } from "fs-extra-p" +import { Config } from "../metadata" +import { safeLoad } from "js-yaml" +import { warn } from "electron-builder-util/out/log" const normalizeData = require("normalize-package-data") @@ -15,7 +18,7 @@ async function authors(file: string, data: any) { return } - let authorData: string | null = null + let authorData try { authorData = await readFile(path.resolve(path.dirname(file), "AUTHORS"), "utf8") } @@ -26,4 +29,70 @@ async function authors(file: string, data: any) { data.contributors = authorData .split(/\r?\n/g) .map(it => it.replace(/^\s*#.*$/, "").trim()) +} + +export async function loadConfig(projectDir: string): Promise { + try { + return safeLoad(await readFile(path.join(projectDir, "electron-builder.yml"), "utf8")) + } + catch (e) { + if (e.code !== "ENOENT") { + throw e + } + } + + const metadata = await readPackageJson(path.join(projectDir, "package.json")) + if (metadata.directories != null) { + warn(`"directories" in the root is deprecated, please specify in the "build"`) + if (metadata.build == null) { + metadata.build = {directories: metadata.directories} + } + else if (metadata.build.directories == null) { + metadata.build.directories = metadata.directories + } + delete metadata.directories + } + return metadata.build +} + +export async function getElectronVersion(config: Config | null | undefined, projectDir: string): Promise { + // build is required, but this check is performed later, so, we should check for null + if (config != null && config.electronVersion != null) { + return config.electronVersion + } + + for (const name of ["electron", "electron-prebuilt", "electron-prebuilt-compile"]) { + try { + return (await readJson(path.join(projectDir, "node_modules", name, "package.json"))).version + } + catch (e) { + if (e.code !== "ENOENT") { + warn(`Cannot read electron version from ${name} package.json: ${e.message}`) + } + } + } + + const packageJsonPath = path.join(projectDir, "package.json") + const electronPrebuiltDep = findFromElectronPrebuilt(await readJson(packageJsonPath)) + 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 } \ No newline at end of file diff --git a/packages/electron-builder/src/yarn.ts b/packages/electron-builder/src/yarn.ts index 6bc3f2d6ee8..5d6ebc0af89 100644 --- a/packages/electron-builder/src/yarn.ts +++ b/packages/electron-builder/src/yarn.ts @@ -3,17 +3,17 @@ import * as path from "path" import { log, warn} from "electron-builder-util/out/log" import { homedir } from "os" import { spawn, asArray } from "electron-builder-util" -import { BuildMetadata } from "./metadata" +import { Config } from "./metadata" import { exists } from "electron-builder-util/out/fs" import { readInstalled } from "./readInstalled" -export async function installOrRebuild(options: BuildMetadata, appDir: string, electronVersion: string, platform: string, arch: string, forceInstall: boolean = false) { - const args = asArray(options.npmArgs) +export async function installOrRebuild(config: Config, appDir: string, electronVersion: string, platform: string, arch: string, forceInstall: boolean = false) { + const args = asArray(config.npmArgs) if (forceInstall || !(await exists(path.join(appDir, "node_modules")))) { - await installDependencies(appDir, electronVersion, platform, arch, args, !options.npmSkipBuildFromSource) + await installDependencies(appDir, electronVersion, platform, arch, args, !config.npmSkipBuildFromSource) } else { - await rebuild(appDir, electronVersion, platform, arch, args, !options.npmSkipBuildFromSource) + await rebuild(appDir, electronVersion, platform, arch, args, !config.npmSkipBuildFromSource) } } diff --git a/test/src/filesTest.ts b/test/src/filesTest.ts index cf47b7e1eb7..8d791bedc77 100644 --- a/test/src/filesTest.ts +++ b/test/src/filesTest.ts @@ -1,6 +1,6 @@ import { expectedWinContents } from "./helpers/expectedContents" import { outputFile, stat, symlink, readFile } from "fs-extra-p" -import { assertPack, modifyPackageJson, getPossiblePlatforms, app } from "./helpers/packTester" +import { assertPack, getPossiblePlatforms, app } from "./helpers/packTester" import BluebirdPromise from "bluebird-lst-c" import * as path from "path" import { assertThat } from "./helpers/fileAssert" @@ -40,26 +40,25 @@ test.ifNotCiWin("extraResources", async () => { await assertPack("test-app-one", { // to check NuGet package targets: platform.createTarget(platform === Platform.WINDOWS ? "squirrel" : DIR_TARGET), + config: { + extraResources: [ + "foo", + "bar/hello.txt", + "bar/${arch}.txt", + "${os}/${arch}.txt", + ], + [osName]: { + extraResources: [ + "platformSpecificR" + ], + extraFiles: [ + "platformSpecificF" + ], + } + }, }, { projectDirCreated: projectDir => { return BluebirdPromise.all([ - modifyPackageJson(projectDir, data => { - data.build.extraResources = [ - "foo", - "bar/hello.txt", - "bar/${arch}.txt", - "${os}/${arch}.txt", - ] - - data.build[osName] = { - extraResources: [ - "platformSpecificR" - ], - extraFiles: [ - "platformSpecificF" - ], - } - }), outputFile(path.join(projectDir, "foo/nameWithoutDot"), "nameWithoutDot"), outputFile(path.join(projectDir, "bar/hello.txt"), "data"), outputFile(path.join(projectDir, `bar/${process.arch}.txt`), "data"), @@ -108,28 +107,25 @@ test.ifNotCiWin("extraResources - one-package", () => { targets: platform.createTarget(platform === Platform.WINDOWS ? "squirrel" : DIR_TARGET), config: { asar: true, + extraResources: [ + "foo", + "bar/hello.txt", + "bar/${arch}.txt", + "${os}/${arch}.txt", + "executable*", + ], + [osName]: { + extraResources: [ + "platformSpecificR" + ], + extraFiles: [ + "platformSpecificF" + ], + }, }, }, { projectDirCreated: projectDir => { return BluebirdPromise.all([ - modifyPackageJson(projectDir, data => { - data.build.extraResources = [ - "foo", - "bar/hello.txt", - "bar/${arch}.txt", - "${os}/${arch}.txt", - "executable*", - ] - - data.build[osName] = { - extraResources: [ - "platformSpecificR" - ], - extraFiles: [ - "platformSpecificF" - ], - } - }), outputFile(path.join(projectDir, "foo/nameWithoutDot"), "nameWithoutDot"), outputFile(path.join(projectDir, "bar/hello.txt"), "data", {mode: "400"}), outputFile(path.join(projectDir, `bar/${process.arch}.txt`), "data"), diff --git a/test/src/mac/dmgTest.ts b/test/src/mac/dmgTest.ts index d3ea0d8b552..e213c8b6136 100644 --- a/test/src/mac/dmgTest.ts +++ b/test/src/mac/dmgTest.ts @@ -1,4 +1,4 @@ -import { assertPack, modifyPackageJson, app, CheckingMacPackager } from "../helpers/packTester" +import { assertPack, app, CheckingMacPackager } from "../helpers/packTester" import { remove, copy } from "fs-extra-p" import * as path from "path" import BluebirdPromise from "bluebird-lst-c" @@ -29,21 +29,18 @@ test.ifMac("custom background - new way", () => { const customBackground = "customBackground.png" return assertPack("test-app-one", { targets: Platform.MAC.createTarget(), - platformPackagerFactory: (packager, platform, cleanupTasks) => platformPackager = new CheckingMacPackager(packager) + platformPackagerFactory: (packager, platform, cleanupTasks) => platformPackager = new CheckingMacPackager(packager), + config: { + mac: { + icon: "customIcon" + }, + dmg: { + background: customBackground, + icon: "foo.icns", + }, + } }, { - projectDirCreated: projectDir => BluebirdPromise.all([ - copy(path.join(__dirname, "..", "..", "..", "packages", "electron-builder", "templates", "dmg", "background.tiff"), path.join(projectDir, customBackground)), - modifyPackageJson(projectDir, data => { - data.build.mac = { - icon: "customIcon" - } - - data.build.dmg = { - background: customBackground, - icon: "foo.icns", - } - }) - ]), + projectDirCreated: projectDir => copy(path.join(__dirname, "..", "..", "..", "packages", "electron-builder", "templates", "dmg", "background.tiff"), path.join(projectDir, customBackground)), packed: async context => { expect(platformPackager.effectiveDistOptions.background).toEqual(customBackground) expect(platformPackager.effectiveDistOptions.icon).toEqual("foo.icns") diff --git a/test/src/mac/macPackagerTest.ts b/test/src/mac/macPackagerTest.ts index e90a1725a70..accef3803fe 100644 --- a/test/src/mac/macPackagerTest.ts +++ b/test/src/mac/macPackagerTest.ts @@ -1,4 +1,4 @@ -import { assertPack, platform, modifyPackageJson, app, appThrows } from "../helpers/packTester" +import { assertPack, platform, app, appThrows } from "../helpers/packTester" import { Platform, createTargets } from "electron-builder" import { DIR_TARGET } from "electron-builder/out/targets/targetFactory" import { copyFile } from "electron-builder-util/out/fs" @@ -37,10 +37,9 @@ test.ifMac("one-package", app({ test.ifMac("electronDist", appThrows(/ENOENT: no such file or directory/, { targets: Platform.MAC.createTarget(DIR_TARGET), -}, { - projectDirCreated: projectDir => modifyPackageJson(projectDir, data => { - data.build.electronDist = "foo" - }) + config: { + electronDist: "foo", + } })) test.ifWinCi("Build macOS on Windows is not supported", appThrows(/Build for macOS is supported only on macOS.+/, platform(Platform.MAC))) \ No newline at end of file diff --git a/test/src/windows/squirrelWindowsTest.ts b/test/src/windows/squirrelWindowsTest.ts index b127f9651f9..f7b610e654e 100644 --- a/test/src/windows/squirrelWindowsTest.ts +++ b/test/src/windows/squirrelWindowsTest.ts @@ -16,12 +16,13 @@ test.skip("delta and msi", app({ }, })) -test.ifNotCiMac("msi as string", appThrows(/msi expected to be boolean value, but string '"false"' was specified/, {targets: Platform.WINDOWS.createTarget("squirrel")}, { - projectDirCreated: it => modifyPackageJson(it, data => { - data.build.win = { - msi: "false", +test.ifNotCiMac("msi as string", appThrows(/msi expected to be boolean value, but string '"false"' was specified/, { + targets: Platform.WINDOWS.createTarget("squirrel"), + config: { + win: { + asar: false, } - }) + } })) test("detect install-spinner, certificateFile/password", () => { diff --git a/test/src/windows/winPackagerTest.ts b/test/src/windows/winPackagerTest.ts index 3ff9ed21bf2..2efa1597685 100755 --- a/test/src/windows/winPackagerTest.ts +++ b/test/src/windows/winPackagerTest.ts @@ -1,8 +1,7 @@ import { Platform } from "electron-builder" -import { assertPack, platform, modifyPackageJson, app, appThrows, CheckingWinPackager } from "../helpers/packTester" +import { assertPack, platform, app, appThrows, CheckingWinPackager } from "../helpers/packTester" import { writeFile, rename, unlink } from "fs-extra-p" import * as path from "path" -import BluebirdPromise from "bluebird-lst-c" test.ifDevOrWinCi("beta version", app({ targets: Platform.WINDOWS.createTarget(["squirrel", "nsis"]), @@ -28,16 +27,14 @@ test.ifMac("custom icon", () => { let platformPackager: CheckingWinPackager = null return assertPack("test-app-one", { targets: Platform.WINDOWS.createTarget("squirrel"), - platformPackagerFactory: (packager, platform, cleanupTasks) => platformPackager = new CheckingWinPackager(packager) + platformPackagerFactory: (packager, platform, cleanupTasks) => platformPackager = new CheckingWinPackager(packager), + config: { + win: { + icon: "customIcon" + }, + } }, { - projectDirCreated: projectDir => BluebirdPromise.all([ - rename(path.join(projectDir, "build", "icon.ico"), path.join(projectDir, "customIcon.ico")), - modifyPackageJson(projectDir, data => { - data.build.win = { - icon: "customIcon" - } - }) - ]), + projectDirCreated: projectDir => rename(path.join(projectDir, "build", "icon.ico"), path.join(projectDir, "customIcon.ico")), packed: async context => { expect(await platformPackager.getIconPath()).toEqual(path.join(context.projectDir, "customIcon.ico")) }, diff --git a/yarn.lock b/yarn.lock index 4a08abc7209..4f0c8c2f679 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,10 +22,6 @@ "7zip-bin-mac" "^1.0.1" "7zip-bin-win" "^2.0.2" -"@types/debug@^0.0.29": - version "0.0.29" - resolved "https://registry.yarnpkg.com/@types/debug/-/debug-0.0.29.tgz#a1e514adfbd92f03a224ba54d693111dbf1f3754" - "@types/electron@^1.4.31": version "1.4.31" resolved "https://registry.yarnpkg.com/@types/electron/-/electron-1.4.31.tgz#6ef658e97152a4d3c9cda44f56bd3f917149bb33" @@ -95,8 +91,8 @@ ansi-escapes@^1.4.0: resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-1.4.0.tgz#d3a8a83b319aa67793662b13e761c7911422306e" ansi-regex@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.0.0.tgz#c5061b6e0ef8a81775e50f5d66151bf6bf371107" + version "2.1.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" ansi-styles@^2.2.1: version "2.2.1" @@ -1668,6 +1664,10 @@ js-tokens@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-2.0.0.tgz#79903f5563ee778cc1162e6dcf1a0027c97f9cb5" +js-tokens@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.0.tgz#a2f2a969caae142fb3cd56228358c89366957bd1" + js-yaml@^3.4.2, js-yaml@^3.7.0: version "3.7.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.7.0.tgz#5c967ddd837a9bfdca5f2de84253abe8a1c03b80" @@ -1887,10 +1887,10 @@ longest@^1.0.1: resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097" loose-envify@^1.0.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.0.tgz#6b26248c42f6d4fa4b0d8542f78edfcde35642a8" + version "1.3.1" + resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848" dependencies: - js-tokens "^2.0.0" + js-tokens "^3.0.0" loud-rejection@^1.0.0: version "1.6.0" @@ -1982,15 +1982,15 @@ micromatch@^2.3.11: parse-glob "^3.0.4" regex-cache "^0.4.2" -mime-db@~1.25.0: - version "1.25.0" - resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.25.0.tgz#c18dbd7c73a5dbf6f44a024dc0d165a1e7b1c392" +mime-db@~1.26.0: + version "1.26.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.26.0.tgz#eaffcd0e4fc6935cf8134da246e2e6c35305adff" mime-types@^2.1.12, mime-types@~2.1.7: - version "2.1.13" - resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.13.tgz#e07aaa9c6c6b9a7ca3012c69003ad25a39e92a88" + version "2.1.14" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.14.tgz#f7ef7d97583fcaf3b7d282b6f8b5679dab1e94ee" dependencies: - mime-db "~1.25.0" + mime-db "~1.26.0" mime@^1.3.4: version "1.3.4" @@ -2028,9 +2028,9 @@ natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" -node-emoji@^1.4.1, node-emoji@^1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.5.0.tgz#9a0d9fe03fd43afa357d6d8e439aa31e599959b7" +node-emoji@^1.4.1, node-emoji@^1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.5.1.tgz#fd918e412769bf8c448051238233840b2aff16a1" dependencies: string.prototype.codepointat "^0.2.0" @@ -2544,9 +2544,9 @@ sntp@1.x.x: dependencies: hoek "2.x.x" -source-map-support@^0.4.2, source-map-support@^0.4.8: - version "0.4.8" - resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.8.tgz#4871918d8a3af07289182e974e32844327b2e98b" +source-map-support@^0.4.2, source-map-support@^0.4.8, source-map-support@^0.4.9: + version "0.4.9" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.9.tgz#45eaa04f067e049d987b27599ed014a37750aaff" dependencies: source-map "^0.5.3" @@ -2589,8 +2589,8 @@ sprintf-js@^1.0.3, sprintf-js@~1.0.2: resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" sshpk@^1.7.0: - version "1.10.1" - resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.10.1.tgz#30e1a5d329244974a1af61511339d595af6638b0" + version "1.10.2" + resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.10.2.tgz#d5a804ce22695515638e798dbe23273de070a5fa" dependencies: asn1 "~0.2.3" assert-plus "^1.0.0" @@ -2746,9 +2746,9 @@ truncate-utf8-bytes@^1.0.0: dependencies: utf8-byte-length "^1.0.1" -ts-babel@^1.3.3: - version "1.3.3" - resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-1.3.3.tgz#56a3d99fd0dab8ef08f9af8d31711f51575aae1e" +ts-babel@^1.3.4: + version "1.3.4" + resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-1.3.4.tgz#787e09974e40d60f3847a33f1b3fab8a5e55154b" dependencies: babel-core "^6.21.0" bluebird-lst-c "^1.0.5"