electron-builder-lib
Version:
electron-builder lib
250 lines (213 loc) • 11.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _bluebirdLst;
function _load_bluebirdLst() {
return _bluebirdLst = require("bluebird-lst");
}
var _bluebirdLst2;
function _load_bluebirdLst2() {
return _bluebirdLst2 = _interopRequireDefault(require("bluebird-lst"));
}
var _builderUtil;
function _load_builderUtil() {
return _builderUtil = require("builder-util");
}
var _builderUtilRuntime;
function _load_builderUtilRuntime() {
return _builderUtilRuntime = require("builder-util-runtime");
}
var _fs;
function _load_fs() {
return _fs = require("builder-util/out/fs");
}
var _ejs;
function _load_ejs() {
return _ejs = _interopRequireWildcard(require("ejs"));
}
var _fsExtraP;
function _load_fsExtraP() {
return _fsExtraP = require("fs-extra-p");
}
var _lazyVal;
function _load_lazyVal() {
return _lazyVal = require("lazy-val");
}
var _path = _interopRequireWildcard(require("path"));
var _core;
function _load_core() {
return _core = require("../core");
}
var _PublishManager;
function _load_PublishManager() {
return _PublishManager = require("../publish/PublishManager");
}
var _pathManager;
function _load_pathManager() {
return _pathManager = require("../util/pathManager");
}
var _differentialUpdateInfoBuilder;
function _load_differentialUpdateInfoBuilder() {
return _differentialUpdateInfoBuilder = require("./differentialUpdateInfoBuilder");
}
var _targetUtil;
function _load_targetUtil() {
return _targetUtil = require("./targetUtil");
}
var _tools;
function _load_tools() {
return _tools = require("./tools");
}
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 }; }
const appRunTemplate = new (_lazyVal || _load_lazyVal()).Lazy((0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
return (_ejs || _load_ejs()).compile((yield (0, (_fsExtraP || _load_fsExtraP()).readFile)(_path.join((0, (_pathManager || _load_pathManager()).getTemplatePath)("linux"), "AppRun.sh"), "utf-8")));
}));
// https://unix.stackexchange.com/questions/375191/append-to-sub-directory-inside-squashfs-file
class AppImageTarget extends (_core || _load_core()).Target {
constructor(ignored, packager, helper, outDir) {
super("appImage");
this.packager = packager;
this.helper = helper;
this.outDir = outDir;
this.options = Object.assign({}, this.packager.platformSpecificBuildOptions, this.packager.config[this.name]);
// we add X-AppImage-BuildId to ensure that new desktop file will be installed
this.desktopEntry = new (_lazyVal || _load_lazyVal()).Lazy(() => helper.computeDesktopEntry(this.options, "AppRun", {
"X-AppImage-Version": `${packager.appInfo.buildVersion}`,
"X-AppImage-BuildId": (_builderUtilRuntime || _load_builderUtilRuntime()).UUID.v1()
}));
}
build(appOutDir, arch) {
var _this = this;
return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
const packager = _this.packager;
// https://github.com/electron-userland/electron-builder/issues/775
// https://github.com/electron-userland/electron-builder/issues/1726
// tslint:disable-next-line:no-invalid-template-strings
const artifactName = packager.expandArtifactNamePattern(_this.options, "AppImage", arch, "${name}-${version}-${arch}.${ext}", false);
const artifactPath = _path.join(_this.outDir, artifactName);
_this.logBuilding("AppImage", artifactPath, arch);
// pax doesn't like dir with leading dot (e.g. `.__appimage`)
const stageDir = yield (0, (_targetUtil || _load_targetUtil()).createStageDir)(_this, packager, arch);
const appInStageDir = stageDir.getTempFile("app");
yield copyDirUsingHardLinks(appOutDir, appInStageDir);
const resourceName = `appimagekit-${_this.packager.executableName}`;
const installIcons = yield _this.copyIcons(stageDir.dir, resourceName);
const finalDesktopFilename = `${_this.packager.executableName}.desktop`;
yield (_bluebirdLst2 || _load_bluebirdLst2()).default.all([(0, (_fs || _load_fs()).unlinkIfExists)(artifactPath), (0, (_fsExtraP || _load_fsExtraP()).writeFile)(stageDir.getTempFile("/AppRun"), (yield appRunTemplate.value)({
systemIntegration: _this.options.systemIntegration || "ask",
desktopFileName: finalDesktopFilename,
executableName: _this.packager.executableName,
resourceName,
installIcons
}), {
mode: "0755"
}), (0, (_fsExtraP || _load_fsExtraP()).writeFile)(stageDir.getTempFile(finalDesktopFilename), (yield _this.desktopEntry.value))]);
// must be after this.helper.icons call
if (_this.helper.maxIconPath == null) {
throw new Error("Icon is not provided");
}
//noinspection SpellCheckingInspection
const vendorDir = yield (0, (_tools || _load_tools()).getAppImage)();
if (_this.packager.packagerOptions.effectiveOptionComputed != null && (yield _this.packager.packagerOptions.effectiveOptionComputed({ desktop: yield _this.desktopEntry.value }))) {
return;
}
if (arch === (_builderUtil || _load_builderUtil()).Arch.x64 || arch === (_builderUtil || _load_builderUtil()).Arch.ia32) {
yield (0, (_fs || _load_fs()).copyDir)(_path.join(vendorDir, "lib", arch === (_builderUtil || _load_builderUtil()).Arch.x64 ? "x86_64-linux-gnu" : "i386-linux-gnu"), stageDir.getTempFile("usr/lib"), {
isUseHardLink: (_fs || _load_fs()).USE_HARD_LINKS
});
}
const publishConfig = yield (0, (_PublishManager || _load_PublishManager()).getAppUpdatePublishConfiguration)(packager, arch);
if (publishConfig != null) {
yield (0, (_fsExtraP || _load_fsExtraP()).writeFile)(_path.join(packager.getResourcesDir(appInStageDir), "app-update.yml"), (0, (_builderUtil || _load_builderUtil()).serializeToYaml)(publishConfig));
}
const vendorToolDir = _path.join(vendorDir, process.platform === "darwin" ? "darwin" : `linux-${process.arch}`);
// default gzip compression - 51.9, xz - 50.4 difference is negligible, start time - well, it seems, a little bit longer (but on Parallels VM on external SSD disk)
// so, to be decided later, is it worth to use xz by default
const args = ["--runtime-file", _path.join(vendorDir, `runtime-${archToRuntimeName(arch)}`), "--no-appstream"];
if ((_builderUtil || _load_builderUtil()).debug.enabled) {
args.push("--verbose");
}
if (packager.compression === "maximum") {
args.push("--comp", "xz");
}
args.push(stageDir.dir, artifactPath);
yield (0, (_builderUtil || _load_builderUtil()).exec)(_path.join(vendorToolDir, "appimagetool"), args, {
env: Object.assign({}, process.env, { PATH: `${vendorToolDir}:${process.env.PATH}`,
// to avoid detection by appimagetool (see extract_arch_from_text about expected arch names)
ARCH: arch === (_builderUtil || _load_builderUtil()).Arch.ia32 ? "i386" : arch === (_builderUtil || _load_builderUtil()).Arch.x64 ? "x86_64" : "arm" })
});
yield stageDir.cleanup();
const updateInfo = yield (0, (_differentialUpdateInfoBuilder || _load_differentialUpdateInfoBuilder()).appendBlockmap)(artifactPath);
packager.info.dispatchArtifactCreated({
file: artifactPath,
safeArtifactName: packager.computeSafeArtifactName(artifactName, "AppImage", arch, false),
target: _this,
arch,
packager,
isWriteUpdateInfo: true,
updateInfo
});
})();
}
copyIcons(stageDir, resourceName) {
var _this2 = this;
return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
const iconDirRelativePath = "usr/share/icons/hicolor";
const iconDir = _path.join(stageDir, iconDirRelativePath);
yield (0, (_fsExtraP || _load_fsExtraP()).ensureDir)(iconDir);
// https://github.com/AppImage/AppImageKit/issues/438#issuecomment-319094239
// expects icons in the /usr/share/icons/hicolor
const iconNames = yield (_bluebirdLst2 || _load_bluebirdLst2()).default.map(_this2.helper.icons, (() => {
var _ref2 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (icon) {
const filename = `${_this2.packager.executableName}.png`;
const iconSizeDir = `${icon.size}x${icon.size}/apps`;
const dir = _path.join(iconDir, iconSizeDir);
yield (0, (_fsExtraP || _load_fsExtraP()).ensureDir)(dir);
const finalIconFile = _path.join(dir, filename);
yield (0, (_fs || _load_fs()).copyOrLinkFile)(icon.file, finalIconFile, null, true);
if (icon.file === _this2.helper.maxIconPath) {
yield (0, (_fsExtraP || _load_fsExtraP()).symlink)(_path.relative(stageDir, finalIconFile), _path.join(stageDir, filename));
}
return { filename, iconSizeDir, size: icon.size };
});
return function (_x) {
return _ref2.apply(this, arguments);
};
})());
let installIcons = "";
for (const icon of iconNames) {
installIcons += `xdg-icon-resource install --noupdate --context apps --size ${icon.size} "$APPDIR/${iconDirRelativePath}/${icon.iconSizeDir}/${icon.filename}" "${resourceName}"\n`;
}
return installIcons;
})();
}
}
exports.default = AppImageTarget; // https://unix.stackexchange.com/questions/202430/how-to-copy-a-directory-recursively-using-hardlinks-for-each-file
function copyDirUsingHardLinks(source, destination) {
if (process.platform !== "darwin") {
const args = ["-d", "--recursive", "--preserve=mode"];
args.push("--link");
args.push(source + "/", destination + "/");
return (0, (_fsExtraP || _load_fsExtraP()).ensureDir)(_path.dirname(destination)).then(() => (0, (_builderUtil || _load_builderUtil()).exec)("cp", args));
}
// pax requires created dir
const promise = (0, (_fsExtraP || _load_fsExtraP()).ensureDir)(destination);
return promise.then(() => (0, (_builderUtil || _load_builderUtil()).exec)("pax", ["-rwl", "-p", "amp" /* Do not preserve file access times, Do not preserve file modification times, Preserve the file mode bits */, ".", destination], {
cwd: source
}));
}
function archToRuntimeName(arch) {
switch (arch) {
case (_builderUtil || _load_builderUtil()).Arch.armv7l:
return "armv7";
case (_builderUtil || _load_builderUtil()).Arch.ia32:
return "i686";
case (_builderUtil || _load_builderUtil()).Arch.x64:
return "x86_64";
default:
throw new Error(`AppImage for arch ${(_builderUtil || _load_builderUtil()).Arch[arch]} not supported`);
}
}
//# sourceMappingURL=AppImageTarget.js.map