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
205 lines (175 loc) • 9.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _bluebirdLstC;
function _load_bluebirdLstC() {
return _bluebirdLstC = require("bluebird-lst-c");
}
var _bluebirdLstC2;
function _load_bluebirdLstC2() {
return _bluebirdLstC2 = _interopRequireDefault(require("bluebird-lst-c"));
}
let writeConfigFile = (() => {
var _ref = (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* (tmpDir, templatePath, options) {
const config = template((yield (0, (_fsExtraP || _load_fsExtraP()).readFile)(templatePath, "utf8")), {
// set interpolate explicitly to avoid troubles with templating of installer.nsi.tpl
interpolate: /<%=([\s\S]+?)%>/g
})(options);
const outputPath = yield tmpDir.getTempFile((_path || _load_path()).basename(templatePath, ".tpl"));
yield (0, (_fsExtraP || _load_fsExtraP()).outputFile)(outputPath, config);
return outputPath;
});
return function writeConfigFile(_x, _x2, _x3) {
return _ref.apply(this, arguments);
};
})();
//# sourceMappingURL=fpm.js.map
var _metadata;
function _load_metadata() {
return _metadata = require("../metadata");
}
var _platformPackager;
function _load_platformPackager() {
return _platformPackager = require("../platformPackager");
}
var _util;
function _load_util() {
return _util = require("../util/util");
}
var _path;
function _load_path() {
return _path = _interopRequireWildcard(require("path"));
}
var _binDownload;
function _load_binDownload() {
return _binDownload = require("../util/binDownload");
}
var _fsExtraP;
function _load_fsExtraP() {
return _fsExtraP = require("fs-extra-p");
}
var _LinuxTargetHelper;
function _load_LinuxTargetHelper() {
return _LinuxTargetHelper = require("./LinuxTargetHelper");
}
var _errorMessages;
function _load_errorMessages() {
return _errorMessages = _interopRequireWildcard(require("../errorMessages"));
}
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 _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
const template = require("lodash.template");
const fpmPath = process.platform === "win32" || process.env.USE_SYSTEM_FPM === "true" ? (_bluebirdLstC2 || _load_bluebirdLstC2()).default.resolve("fpm") : downloadFpm();
// can be called in parallel, all calls for the same version will get the same promise - will be downloaded only once
function downloadFpm() {
const version = process.platform === "darwin" ? "fpm-1.6.3-20150715-2.2.2" : "fpm-1.6.3-2.3.1";
const osAndArch = process.platform === "darwin" ? "mac" : `linux-x86${ process.arch === "ia32" ? "" : "_64" }`;
//noinspection SpellCheckingInspection
const sha2 = process.platform === "darwin" ? "1b13080ecfd2b6fddb984ed6e1dfcb38cdf5b051a04d609c2a95227ed9a5ecbc" : process.arch === "ia32" ? "b55f25749a27097140171f073466c52e59f733a275fea99e2334c540627ffc62" : "4c6fc529e996f7ff850da2d0bb6c85080e43be672494b14c0c6bdcc03bf57328";
return (0, (_binDownload || _load_binDownload()).getBin)("fpm", version, `https://dl.bintray.com/electron-userland/bin/${ version }-${ osAndArch }.7z`, sha2).then(it => (_path || _load_path()).join(it, "fpm"));
}
class FpmTarget extends (_platformPackager || _load_platformPackager()).TargetEx {
constructor(name, packager, helper, outDir) {
super(name);
this.packager = packager;
this.helper = helper;
this.outDir = outDir;
this.options = Object.assign({}, this.packager.platformSpecificBuildOptions, this.packager.devMetadata.build[this.name]);
this.scriptFiles = this.createScripts();
this.desktopEntry = helper.computeDesktopEntry(this.options);
}
createScripts() {
var _this = this;
return (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () {
const defaultTemplatesDir = (_path || _load_path()).join(__dirname, "..", "..", "templates", "linux");
const packager = _this.packager;
const templateOptions = Object.assign({
// old API compatibility
executable: _this.packager.executableName
}, packager.platformSpecificBuildOptions);
function getResource(value, defaultFile) {
if (value == null) {
return (_path || _load_path()).join(defaultTemplatesDir, defaultFile);
}
return (_path || _load_path()).resolve(packager.projectDir, value);
}
const afterInstallFilePath = writeConfigFile(packager.info.tempDirManager, getResource(packager.platformSpecificBuildOptions.afterInstall, "after-install.tpl"), templateOptions);
const afterRemoveFilePath = writeConfigFile(packager.info.tempDirManager, getResource(packager.platformSpecificBuildOptions.afterRemove, "after-remove.tpl"), templateOptions);
return yield (_bluebirdLstC2 || _load_bluebirdLstC2()).default.all([afterInstallFilePath, afterRemoveFilePath]);
})();
}
build(appOutDir, arch) {
var _this2 = this;
return (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () {
const target = _this2.name;
const destination = (_path || _load_path()).join(_this2.outDir, _this2.packager.generateName(target, arch, true /* on Linux we use safe name — without space */));
const scripts = yield _this2.scriptFiles;
const packager = _this2.packager;
const appInfo = packager.appInfo;
const projectUrl = yield appInfo.computePackageUrl();
if (projectUrl == null) {
throw new Error("Please specify project homepage, see https://github.com/electron-userland/electron-builder/wiki/Options#AppMetadata-homepage");
}
const options = _this2.options;
let author = options.maintainer;
if (author == null) {
const a = appInfo.metadata.author;
if (a.email == null) {
throw new Error((_errorMessages || _load_errorMessages()).authorEmailIsMissed);
}
author = `${ a.name } <${ a.email }>`;
}
const synopsis = options.synopsis;
const args = ["-s", "dir", "-t", target, "--architecture", arch === (_metadata || _load_metadata()).Arch.ia32 ? "i386" : arch === (_metadata || _load_metadata()).Arch.x64 ? "amd64" : "armv7l", "--name", appInfo.name, "--force", "--after-install", scripts[0], "--after-remove", scripts[1], "--description", (0, (_platformPackager || _load_platformPackager()).smarten)(target === "rpm" ? options.description : `${ synopsis || "" }\n ${ options.description }`), "--maintainer", author, "--vendor", options.vendor || author, "--version", appInfo.version, "--package", destination, "--url", projectUrl];
const packageCategory = options.packageCategory;
if (packageCategory != null && packageCategory !== null) {
args.push("--category", packageCategory);
}
if (target === "deb") {
args.push("--deb-compression", options.compression || (packager.devMetadata.build.compression === "store" ? "gz" : "xz"));
} else if (target === "rpm") {
// args.push("--rpm-compression", options.compression || (this.devMetadata.build.compression === "store" ? "none" : "xz"))
args.push("--rpm-os", "linux");
if (synopsis != null) {
args.push("--rpm-summary", (0, (_platformPackager || _load_platformPackager()).smarten)(synopsis));
}
}
let depends = options.depends;
if (depends == null) {
if (target === "deb") {
depends = ["libappindicator1", "libnotify-bin"];
} else {
depends = [];
}
} else if (!Array.isArray(depends)) {
if (typeof depends === "string") {
depends = [depends];
} else {
throw new Error(`depends must be Array or String, but specified as: ${ depends }`);
}
}
for (let dep of depends) {
args.push("--depends", dep);
}
(0, (_util || _load_util()).use)(packager.appInfo.metadata.license || packager.devMetadata.license, function (it) {
return args.push("--license", it);
});
(0, (_util || _load_util()).use)(appInfo.buildNumber, function (it) {
return args.push("--iteration", it);
});
(0, (_util || _load_util()).use)(options.fpm, function (it) {
return args.push.apply(args, _toConsumableArray(it));
});
args.push(`${ appOutDir }/=${ (_LinuxTargetHelper || _load_LinuxTargetHelper()).installPrefix }/${ appInfo.productFilename }`);
for (let mapping of yield _this2.helper.icons) {
args.push(mapping.join("=/usr/share/icons/hicolor/"));
}
args.push(`${ yield _this2.desktopEntry }=/usr/share/applications/${ appInfo.productFilename }.desktop`);
yield (0, (_util || _load_util()).exec)((yield fpmPath), args);
_this2.packager.dispatchArtifactCreated(destination);
})();
}
}
exports.default = FpmTarget;