From 7b715622eb946ba49ea50fed7538f6fa011f116d Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 10 Mar 2016 00:08:45 -0800 Subject: [PATCH] Add packager build script This add lots of missing options for packaging Electron apps correctly for all platforms. --- bin/build.js | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100755 bin/build.js diff --git a/bin/build.js b/bin/build.js new file mode 100755 index 00000000..e71024ba --- /dev/null +++ b/bin/build.js @@ -0,0 +1,103 @@ +#!/usr/bin/env node + +var cp = require('child_process') +var electronPackager = require('electron-packager') +var fs = require('fs') +var path = require('path') +var pkg = require('../package.json') + +var all = { + // Build 64 bit binaries only. + arch: 'x64', + + // The application source directory. + dir: path.join(__dirname, '..'), + + // The release version of the application. Maps to the `ProductVersion` metadata + // property on Windows, and `CFBundleShortVersionString` on OS X. + 'app-version': pkg.version, + + // Package the application's source code into an archive, using Electron's archive + // format. Mitigates issues around long path names on Windows and slightly speeds up + // require(). + asar: false, + + // The build version of the application. Maps to the FileVersion metadata property on + // Windows, and CFBundleVersion on OS X. We're using the short git hash (e.g. 'e7d837e') + 'build-version': cp.execSync('git rev-parse --short HEAD').toString().replace('\n', ''), + + // Pattern which specifies which files to ignore when copying files to create the + // package(s). + ignore: /^\/(dist|resources\/screenshot.png)$/, + + // The base directory where the finished package(s) are created. + out: path.join(__dirname, '..', 'dist'), + + // Replace an already existing output directory. + overwrite: true, + + // Runs `npm prune --production` which remove the packages specified in + // "devDependencies" before starting to package the app. + prune: true, + + // The Electron version with which the app is built (without the leading 'v') + version: pkg.devDependencies['electron-prebuilt'] +} + +var darwin = { + platform: 'darwin', + + // The bundle identifier to use in the application's plist (OS X only). + 'app-bundle-id': 'io.webtorrent.app', + + // The application category type, as shown in the Finder via "View" -> "Arrange by + // Application Category" when viewing the Applications directory (OS X only). + 'app-category-type': 'public.app-category.utilities', + + // The bundle identifier to use in the application helper's plist (OS X only). + 'helper-bundle-id': 'io.webtorrent.app.helper', +} + +var win32 = { + platform: 'win32', + + // Object hash of application metadata to embed into the executable (Windows only) + 'version-string': { + + // Company that produced the file. + CompanyName: 'WebTorrent', + + // Copyright notices that apply to the file. This should include the full text of all + // notices, legal symbols, copyright dates, and so on. + LegalCopyright: fs.readFileSync(path.join(__dirname, '..', 'LICENSE'), 'utf8'), + + // File description to be presented to users. + FileDescription: 'Streaming torrent client', + + // Original name of the file, not including a path. This information enables an + // application to determine whether a file has been renamed by a user. The format of + // the name depends on the file system for which the file was created. + OriginalFilename: 'WebTorrent.exe', + + // Name of the product with which the file is distributed. + ProductName: 'WebTorrent', + + // Internal name of the file, if one exists, for example, a module name if the file + // is a dynamic-link library. If the file has no internal name, this string should be + // the original filename, without extension. This string is required. + InternalName: 'WebTorrent' + }, +} + +var linux = { + platform: 'linux' +} + +electronPackager(Object.assign({}, all, darwin), done) +electronPackager(Object.assign({}, all, win32), done) +electronPackager(Object.assign({}, all, linux), done) + +function done (err, appPath) { + if (err) console.error(err.message || err) + else console.log('Built ' + appPath) +} diff --git a/package.json b/package.json index 1a4c29ce..1978864e 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "url": "git://github.com/feross/webtorrent-app.git" }, "scripts": { - "build": "electron-packager . $npm_package_productName --overwrite --out=dist --ignore='^/dist$' --prune --asar --all --version=$npm_package_devDependencies_electron_prebuilt", + "build": "node ./bin/build.js", "debug": "DEBUG=* electron .", "start": "electron .", "test": "standard",