UNPKG

electron-builder

Version:

A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out of the box

187 lines (163 loc) 10.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createApp = undefined; var _bluebirdLstC; function _load_bluebirdLstC() { return _bluebirdLstC = require("bluebird-lst-c"); } var _bluebirdLstC2; function _load_bluebirdLstC2() { return _bluebirdLstC2 = _interopRequireDefault(require("bluebird-lst-c")); } let createApp = exports.createApp = (() => { var _ref = (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* (packager, appOutDir, initializeApp) { const appInfo = packager.appInfo; const appFilename = appInfo.productFilename; const contentsPath = (_path || _load_path()).join(appOutDir, "Electron.app", "Contents"); const frameworksPath = (_path || _load_path()).join(contentsPath, "Frameworks"); const appPlistFilename = (_path || _load_path()).join(contentsPath, "Info.plist"); const helperPlistFilename = (_path || _load_path()).join(frameworksPath, "Electron Helper.app", "Contents", "Info.plist"); const helperEHPlistFilename = (_path || _load_path()).join(frameworksPath, "Electron Helper EH.app", "Contents", "Info.plist"); const helperNPPlistFilename = (_path || _load_path()).join(frameworksPath, "Electron Helper NP.app", "Contents", "Info.plist"); const buildMetadata = packager.devMetadata.build; const result = yield (_bluebirdLstC2 || _load_bluebirdLstC2()).default.all([initializeApp(), (_bluebirdLstC2 || _load_bluebirdLstC2()).default.map([appPlistFilename, helperPlistFilename, helperEHPlistFilename, helperNPPlistFilename, buildMetadata["extend-info"]], function (it) { return it == null ? it : (0, (_fsExtraP || _load_fsExtraP()).readFile)(it, "utf8"); })]); const fileContents = result[1]; const appPlist = (0, (_plist || _load_plist()).parse)(fileContents[0]); const helperPlist = (0, (_plist || _load_plist()).parse)(fileContents[1]); const helperEHPlist = (0, (_plist || _load_plist()).parse)(fileContents[2]); const helperNPPlist = (0, (_plist || _load_plist()).parse)(fileContents[3]); // If an extend-info file was supplied, copy its contents in first if (fileContents[4] != null) { Object.assign(appPlist, (0, (_plist || _load_plist()).parse)(fileContents[4])); } const appBundleIdentifier = filterCFBundleIdentifier(appInfo.id); const oldHelperBundleId = buildMetadata["helper-bundle-id"]; if (oldHelperBundleId != null) { (0, (_log || _load_log()).warn)("build.helper-bundle-id is deprecated, please set as build.mac.helperBundleId"); } const helperBundleIdentifier = filterCFBundleIdentifier(packager.platformSpecificBuildOptions.helperBundleId || oldHelperBundleId || `${ appBundleIdentifier }.helper`); const icon = yield packager.getIconPath(); const oldIcon = appPlist.CFBundleIconFile; if (icon != null) { appPlist.CFBundleIconFile = `${ appInfo.productFilename }.icns`; } appPlist.CFBundleDisplayName = appInfo.productName; appPlist.CFBundleIdentifier = appBundleIdentifier; appPlist.CFBundleName = appInfo.productName; helperPlist.CFBundleDisplayName = `${ appInfo.productName } Helper`; helperPlist.CFBundleIdentifier = helperBundleIdentifier; appPlist.CFBundleExecutable = appFilename; helperPlist.CFBundleName = appInfo.productName; helperPlist.CFBundleExecutable = `${ appFilename } Helper`; helperEHPlist.CFBundleDisplayName = `${ appFilename } Helper EH`; helperEHPlist.CFBundleIdentifier = `${ helperBundleIdentifier }.EH`; helperEHPlist.CFBundleName = `${ appInfo.productName } Helper EH`; helperEHPlist.CFBundleExecutable = `${ appFilename } Helper EH`; helperNPPlist.CFBundleDisplayName = `${ appInfo.productName } Helper NP`; helperNPPlist.CFBundleIdentifier = `${ helperBundleIdentifier }.NP`; helperNPPlist.CFBundleName = `${ appInfo.productName } Helper NP`; helperNPPlist.CFBundleExecutable = `${ appFilename } Helper NP`; appPlist.CFBundleShortVersionString = appInfo.version; appPlist.CFBundleVersion = appInfo.buildVersion; const protocols = (0, (_util || _load_util()).asArray)(buildMetadata.protocols).concat((0, (_util || _load_util()).asArray)(packager.platformSpecificBuildOptions.protocols)); if (protocols.length > 0) { appPlist.CFBundleURLTypes = protocols.map(function (protocol) { const schemes = (0, (_util || _load_util()).asArray)(protocol.schemes); if (schemes.length === 0) { throw new Error(`Protocol "${ protocol.name }": must be at least one scheme specified`); } return { CFBundleURLName: protocol.name, CFBundleTypeRole: protocol.role || "Editor", CFBundleURLSchemes: schemes.slice() }; }); } const fileAssociations = packager.getFileAssociations(); if (fileAssociations.length > 0) { appPlist.CFBundleDocumentTypes = yield (_bluebirdLstC2 || _load_bluebirdLstC2()).default.map(fileAssociations, (() => { var _ref2 = (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* (fileAssociation) { const extensions = (0, (_util || _load_util()).asArray)(fileAssociation.ext).map((_platformPackager || _load_platformPackager()).normalizeExt); const customIcon = yield packager.getResource(fileAssociation.icon, `${ extensions[0] }.icns`); // todo rename electron.icns return { CFBundleTypeExtensions: extensions, CFBundleTypeName: fileAssociation.name, CFBundleTypeRole: fileAssociation.role || "Editor", CFBundleTypeIconFile: customIcon || appPlist.CFBundleIconFile }; }); return function (_x4) { return _ref2.apply(this, arguments); }; })()); } const oldCategory = buildMetadata["app-category-type"]; if (oldCategory != null) { (0, (_log || _load_log()).warn)("app-category-type is deprecated, please set as build.mac.category"); } let category = packager.platformSpecificBuildOptions.category || buildMetadata.category || oldCategory; (0, (_util || _load_util()).use)(category || oldCategory, function (it) { return appPlist.LSApplicationCategoryType = it; }); (0, (_util || _load_util()).use)(appInfo.copyright, function (it) { return appPlist.NSHumanReadableCopyright = it; }); const promises = [(0, (_fsExtraP || _load_fsExtraP()).writeFile)(appPlistFilename, (0, (_plist || _load_plist()).build)(appPlist)), (0, (_fsExtraP || _load_fsExtraP()).writeFile)(helperPlistFilename, (0, (_plist || _load_plist()).build)(helperPlist)), (0, (_fsExtraP || _load_fsExtraP()).writeFile)(helperEHPlistFilename, (0, (_plist || _load_plist()).build)(helperEHPlist)), (0, (_fsExtraP || _load_fsExtraP()).writeFile)(helperNPPlistFilename, (0, (_plist || _load_plist()).build)(helperNPPlist)), doRename((_path || _load_path()).join(contentsPath, "MacOS"), "Electron", appPlist.CFBundleExecutable)]; if (icon != null) { promises.push((0, (_fsExtraP || _load_fsExtraP()).unlink)((_path || _load_path()).join(contentsPath, "Resources", oldIcon))); promises.push((0, (_fsExtraP || _load_fsExtraP()).copy)(icon, (_path || _load_path()).join(contentsPath, "Resources", appPlist.CFBundleIconFile))); } yield (_bluebirdLstC2 || _load_bluebirdLstC2()).default.all(promises); yield moveHelpers(frameworksPath, appFilename); yield (0, (_fsExtraP || _load_fsExtraP()).rename)((_path || _load_path()).dirname(contentsPath), (_path || _load_path()).join(appOutDir, `${ appFilename }.app`)); }); return function createApp(_x, _x2, _x3) { return _ref.apply(this, arguments); }; })(); //# sourceMappingURL=mac.js.map var _fsExtraP; function _load_fsExtraP() { return _fsExtraP = require("fs-extra-p"); } var _path; function _load_path() { return _path = _interopRequireWildcard(require("path")); } var _plist; function _load_plist() { return _plist = require("plist"); } var _util; function _load_util() { return _util = require("../util/util"); } var _platformPackager; function _load_platformPackager() { return _platformPackager = require("../platformPackager"); } var _log; function _load_log() { return _log = require("../util/log"); } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function doRename(basePath, oldName, newName) { return (0, (_fsExtraP || _load_fsExtraP()).rename)((_path || _load_path()).join(basePath, oldName), (_path || _load_path()).join(basePath, newName)); } function moveHelpers(frameworksPath, appName) { return (_bluebirdLstC2 || _load_bluebirdLstC2()).default.map([" Helper", " Helper EH", " Helper NP"], suffix => { const executableBasePath = (_path || _load_path()).join(frameworksPath, `Electron${ suffix }.app`, "Contents", "MacOS"); return doRename(executableBasePath, `Electron${ suffix }`, appName + suffix).then(() => doRename(frameworksPath, `Electron${ suffix }.app`, `${ appName }${ suffix }.app`)); }); } function filterCFBundleIdentifier(identifier) { // Remove special characters and allow only alphanumeric (A-Z,a-z,0-9), hyphen (-), and period (.) // Apple documentation: https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-102070 return identifier.replace(/ /g, "-").replace(/[^a-zA-Z0-9.-]/g, ""); }