Create a Windows package for your Electron app.
JavaScript HTML CSS
Latest commit a7598ff Nov 1, 2016 @unindented committed on GitHub Merge pull request #104 from unindented/greenkeeper-fs-extra-1.0.0
Update fs-extra to version 1.0.0 πŸš€

README.md

Electron Installer for Windows

electron-installer-windows Version Build Status Build Status Dependency Status

Create a Windows package for your Electron app.

This tool relies on the awesome Squirrel.Windows framework written by @paulcbetts. It takes care of creating the actual package, signing it, dealing with updates, and many more things. Gotta give credit where credit is due, ya know.

Requirements

I'd recommend building your packages on your target platform, but if you have to run this on Mac OS X or Linux, you will need to install mono and wine through Homebrew:

$ brew install mono wine

You won't get an .msi installer though, only .nupkg and .exe installers. To get an .msi installer you'll need to run on Windows.

Installation

For use from command-line:

$ npm install -g electron-installer-windows

For use in npm scripts or programmatically:

$ npm install --save-dev electron-installer-windows

Usage

Say your Electron app lives in path/to/app, and has a structure like this:

.
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ node_modules
β”‚Β Β  β”œβ”€β”€ electron-packager
β”‚Β Β  └── electron-prebuilt
β”œβ”€β”€ package.json
β”œβ”€β”€ resources
β”‚Β Β  β”œβ”€β”€ Icon.png
β”‚Β Β  β”œβ”€β”€ IconTemplate.png
β”‚Β Β  └── IconTemplate@2x.png
└── src
    β”œβ”€β”€ index.js
    β”œβ”€β”€ main
    β”‚Β Β  └── index.js
    └── renderer
        β”œβ”€β”€ index.html
        └── index.js

You now run electron-packager to build the app for Windows:

$ electron-packager . app --platform win32 --arch x64 --out dist/

And you end up with something like this in your dist folder:

.
└── dist
 Β Β  └── app-win32-x64
        β”œβ”€β”€ LICENSE
        β”œβ”€β”€ LICENSES.chromium.html
        β”œβ”€β”€ content_resources_200_percent.pak
        β”œβ”€β”€ content_shell.pak
        β”œβ”€β”€ d3dcompiler_47.dll
        β”œβ”€β”€ icudtl.dat
        β”œβ”€β”€ libEGL.dll
        β”œβ”€β”€ libGLESv2.dll
        β”œβ”€β”€ locales
        β”œβ”€β”€ msvcp120.dll
        β”œβ”€β”€ msvcr120.dll
        β”œβ”€β”€ natives_blob.bin
        β”œβ”€β”€ node.dll
        β”œβ”€β”€ pdf.dll
        β”œβ”€β”€ app.exe
        β”œβ”€β”€ resources
        β”œβ”€β”€ snapshot_blob.bin
        β”œβ”€β”€ ui_resources_200_percent.pak
        β”œβ”€β”€ vccorlib120.dll
        β”œβ”€β”€ version
        └── xinput1_3.dll

How do you turn that into a Windows package that your users can install?

Command-Line

If you want to run electron-installer-windows straight from the command-line, install the package globally:

$ npm install -g electron-installer-windows

And point it to your built app:

$ electron-installer-windows --src dist/app-win32-x64/ --dest dist/installers/

You'll end up with the package at dist/installers/app-0.0.1-setup.exe.

Scripts

If you want to run electron-installer-windows through npm, install the package locally:

$ npm install --save-dev electron-installer-windows

Edit the scripts section of your package.json:

{
  "name": "app",
  "description": "An awesome app!",
  "version": "0.0.1",
  "scripts": {
    "start": "electron .",
    "build": "electron-packager . app --platform win32 --arch x64 --out dist/",
    "setup": "electron-installer-windows --src dist/app-win32-x64/ --dest dist/installers/"
  },
  "devDependencies": {
    "electron-installer-windows": "*",
    "electron-packager": "*",
    "electron-prebuilt": "*"
  }
}

And run the script:

$ npm run setup

You'll end up with the package at dist/installers/app-0.0.1-setup.exe.

Programmatically

Install the package locally:

$ npm install --save-dev electron-installer-windows

And write something like this:

var installer = require('electron-installer-windows')

var options = {
  src: 'dist/app-win32-x64/',
  dest: 'dist/installers/'
}

console.log('Creating package (this may take a while)')

installer(options, function (err) {
  if (err) {
    console.error(err, err.stack)
    process.exit(1)
  }

  console.log('Successfully created package at ' + options.dest)
})

You'll end up with the package at dist/installers/app-0.0.1-setup.exe.

Options

Even though you can pass most of these options through the command-line interface, it may be easier to create a configuration file:

{
  "dest": "dist/installers/",
  "icon": "resources/Icon.ico",
  "tags": [
    "Utility"
  ]
}

And pass that instead with the config option:

$ electron-installer-windows --src dist/app-win32-x64/ --config config.json

Anyways, here's the full list of options:

src

Type: String Default: undefined

Path to the folder that contains your built Electron application.

dest

Type: String Default: undefined

Path to the folder that will contain your Windows installer.

rename

Type: Function Default: function (dest, src) { return path.join(dest, src); }

Function that renames all files generated by the task just before putting them in your dest folder.

options.name

Type: String Default: package.name

Name of the package (e.g. atom), used in the id field of the nuspec file.

options.productName

Type: String Default: package.productName || package.name

Name of the application (e.g. Atom), used in the title field of the nuspec file.

options.description

Type: String Default: package.description

Short description of the application, used in the summary field of the nuspec file.

options.productDescription

Type: String Default: package.productDescription || package.description

Long description of the application, used in the description field of the nuspec file.

options.version

Type: String Default: package.version

Long description of the application, used in the version field of the nuspec file.

options.copyright

Type: String Default: package.copyright

Copyright details for the package, used in the copyright field of the nuspec file.

options.authors

Type: Array[String] Default: package.author

List of authors of the package, used in the authors field of the spec file.

options.owners

Type: Array[String] Default: package.author

List of owners of the package, used in the authors field of the spec file.

options.homepage

Type: String Default: package.homepage || package.author.url

URL of the homepage for the package, used in the projectUrl field of the spec file.

options.iconUrl

Type: String Default: undefined

URL for the image to use as the icon for the package in the Manage NuGet Packages dialog box, used in the iconUrl field of the spec file.

options.licenseUrl

Type: String Default: undefined

URL for the license that the package is under, used in the licenseUrl field of the spec file.

options.requireLicenseAcceptance

Type: String Default: false

Whether the client needs to ensure that the package license (described by licenseUrl) is accepted before the package is installed, used in the requireLicenseAcceptance field of the spec file.

options.tags

Type: Array[String] Default: []

List of tags and keywords that describe the package, used in the tags field of the spec file.

options.certificateFile

Type: String Default: undefined

Path to an Authenticode Code Signing Certificate.

options.certificatePassword

Type: String Default: undefined

Password to decrypt the certificate given in certificateFile.

options.signWithParams

Type: String Default: undefined

Parameters to pass to signtool. Overrides certificateFile and certificatePassword.

options.remoteReleases

Type: String Default: undefined

URL to your existing updates. If given, these will be downloaded to create delta updates.

If you are using Amazon S3 to store your releases, read the documentation for Squirrel.Windows on Amazon S3.

If you are using GitHub, read the documentation for Squirrel.Windows on GitHub.

Signing

Internet Explorer's SmartScreen Filter, and antivirus programs, may flag your package as malware if it's not signed. Luckily, signing your package with electron-installer-windows is pretty easy. Let's test the process with a self-signed certificate.

To generate the certificate, open the Developer Command Prompt for Visual Studio and execute the following:

$ makecert -sv my_private_key.pvk -n "CN=MyTestCertificate" my_test_certificate.cer -b 01/01/2016 -e 01/01/2026 -r
$ pvk2pfx -pvk my_private_key.pvk -spc my_test_certificate.cer -pfx my_signing_key.pfx -po my_password

Now we can tell electron-installer-windows to sign the packages that it generates with that certificate:

$ electron-installer-windows --src dist/app-win32-x64/ --dest dist/installers/ --certificateFile my_signing_key.pfx --certificatePassword my_password

Boom, that's it. Now get a standard code signing certificate from a real certificate authority!

Maintenance

Squirrel

Current version: 1.4.4

To update Squirrel to the latest version:

$ rm vendor/squirrel/*
$ mono vendor/nuget/NuGet.exe install squirrel.windows -OutputDirectory vendor/tmp/
$ cp -r vendor/tmp/squirrel.windows.1.4.4/tools/* vendor/squirrel/
$ rm -rf vendor/tmp/

NuGet

Current version: 2.8.5

To update NuGet to the latest version, head over to the releases page.

Meta

Contributors

License

Copyright (c) 2016 Daniel Perez Alvarez (unindented.org). This is free software, and may be redistributed under the terms specified in the LICENSE file.