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
118 lines (100 loc) • 4.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.archiveApp = undefined;
var _bluebirdLstC;
function _load_bluebirdLstC() {
return _bluebirdLstC = require("bluebird-lst-c");
}
// withoutDir - not applicable for tar.* formats
let archiveApp = exports.archiveApp = (() => {
var _ref = (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* (compression, format, outFile, dirToArchive) {
let isMacApp = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
let withoutDir = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
const storeOnly = compression === "store";
if (format.startsWith("tar.")) {
// we don't use 7z here - develar: I spent a lot of time making pipe working - but it works on MacOS and often hangs on Linux (even if use pipe-io lib)
// and in any case it is better to use system tools (in the light of docker - it is not problem for user because we provide complete docker image).
const info = extToCompressionDescriptor[format];
let tarEnv = process.env;
if (compression != null && compression !== "normal") {
tarEnv = Object.assign({}, process.env);
tarEnv[info.env] = storeOnly ? info.minLevel : info.maxLevel;
}
const args = [info.flag, "-cf", outFile];
if (!isMacApp) {
args.push("--transform", `s,^\.,${ (_path || _load_path()).basename(outFile, "." + format) },`);
}
args.push(isMacApp ? (_path || _load_path()).basename(dirToArchive) : ".");
yield (0, (_util || _load_util()).spawn)(process.platform === "darwin" || process.platform === "freebsd" ? "gtar" : "tar", args, {
cwd: isMacApp ? (_path || _load_path()).dirname(dirToArchive) : dirToArchive,
env: tarEnv
});
return outFile;
}
const args = (0, (_util || _load_util()).debug7zArgs)("a");
if (format === "7z" || format.endsWith(".7z")) {
if (!storeOnly) {
// 7z is very fast, so, use ultra compression
args.push("-mx=9", "-mfb=64", "-md=64m", "-ms=on");
}
} else if (format === "zip") {
if (compression === "maximum") {
// http://superuser.com/a/742034
//noinspection SpellCheckingInspection
args.push("-mfb=258", "-mpass=15");
}
} else if (compression === "maximum") {
args.push("-mx=9");
}
// remove file before - 7z doesn't overwrite file, but update
try {
yield (0, (_fsExtraP || _load_fsExtraP()).unlink)(outFile);
} catch (e) {}
if (format === "zip" || storeOnly) {
args.push("-mm=" + (storeOnly ? "Copy" : "Deflate"));
}
args.push(outFile, withoutDir ? "." : (_path || _load_path()).basename(dirToArchive));
yield (0, (_util || _load_util()).spawn)((_zipBin || _load_zipBin()).path7za, args, {
cwd: withoutDir ? dirToArchive : (_path || _load_path()).dirname(dirToArchive)
});
return outFile;
});
return function archiveApp(_x2, _x3, _x4, _x5, _x6, _x7) {
return _ref.apply(this, arguments);
};
})();
//# sourceMappingURL=archive.js.map
var _util;
function _load_util() {
return _util = require("../util/util");
}
var _path;
function _load_path() {
return _path = _interopRequireWildcard(require("path"));
}
var _fsExtraP;
function _load_fsExtraP() {
return _fsExtraP = require("fs-extra-p");
}
var _zipBin;
function _load_zipBin() {
return _zipBin = require("7zip-bin");
}
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; } }
class CompressionDescriptor {
constructor(flag, env, minLevel) {
let maxLevel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "-9";
this.flag = flag;
this.env = env;
this.minLevel = minLevel;
this.maxLevel = maxLevel;
}
}
const extToCompressionDescriptor = {
"tar.xz": new CompressionDescriptor("--xz", "XZ_OPT", "-0", "-9e"),
"tar.lz": new CompressionDescriptor("--lzip", "LZOP", "-0"),
"tar.gz": new CompressionDescriptor("--gz", "GZIP", "-1"),
"tar.bz2": new CompressionDescriptor("--bzip2", "BZIP2", "-1")
};