electron-builder-lib
Version:
electron-builder lib
168 lines (150 loc) • 8.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _bluebirdLst;
function _load_bluebirdLst() {
return _bluebirdLst = require("bluebird-lst");
}
var _builderUtil;
function _load_builderUtil() {
return _builderUtil = require("builder-util");
}
var _fs;
function _load_fs() {
return _fs = require("builder-util/out/fs");
}
var _fsExtraP;
function _load_fsExtraP() {
return _fsExtraP = require("fs-extra-p");
}
var _path = _interopRequireWildcard(require("path"));
var _core;
function _load_core() {
return _core = require("../core");
}
var _targetUtil;
function _load_targetUtil() {
return _targetUtil = require("./targetUtil");
}
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; } }
// usr/share/fonts is required, cannot run otherwise
const unnecessaryFiles = ["usr/share/doc", "usr/share/man", "usr/share/icons", "usr/share/bash-completion", "usr/share/lintian", "usr/share/dh-python", "usr/share/python3", "usr/lib/python*", "usr/bin/python*"];
class SnapTarget extends (_core || _load_core()).Target {
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.config[this.name]);
}
build(appOutDir, arch) {
var _this = this;
return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
const packager = _this.packager;
const appInfo = packager.appInfo;
const options = _this.options;
const stageDir = yield (0, (_targetUtil || _load_targetUtil()).createStageDir)(_this, packager, arch);
// snapcraft.yaml inside a snap directory
const snapDir = _path.join(stageDir.dir, "snap");
const snap = {};
snap.name = packager.executableName.toLowerCase();
snap.version = appInfo.version;
snap.summary = options.summary || appInfo.productName;
snap.description = _this.helper.getDescription(options);
snap.confinement = options.confinement || "strict";
snap.grade = options.grade || "stable";
const snapFileName = `${snap.name}_${snap.version}_${(0, (_builderUtil || _load_builderUtil()).toLinuxArchString)(arch)}.snap`;
const artifactPath = _path.join(_this.outDir, snapFileName);
_this.logBuilding("snap", artifactPath, arch);
yield _this.helper.icons;
if (_this.helper.maxIconPath != null) {
snap.icon = "snap/gui/icon.png";
yield (0, (_fs || _load_fs()).copyFile)(_this.helper.maxIconPath, _path.join(snapDir, "gui", "icon.png"));
}
const desktopFile = yield _this.helper.writeDesktopEntry(_this.options, packager.executableName, _path.join(snapDir, "gui", `${snap.name}.desktop`), {
// tslint:disable:no-invalid-template-strings
Icon: "${SNAP}/meta/gui/icon.png"
});
if (options.assumes != null) {
if (!Array.isArray(options.assumes)) {
throw new Error("snap.assumes must be an array of strings");
}
snap.assumes = options.assumes;
}
snap.apps = {
[snap.name]: {
command: `env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/${packager.executableName}`,
plugs: (0, (_builderUtil || _load_builderUtil()).replaceDefault)(options.plugs, ["desktop", "desktop-legacy", "home", "x11", "unity7", "browser-support", "network", "gsettings", "pulseaudio", "opengl"])
}
};
const isUseDocker = process.platform !== "linux";
// libxss1, libasound2, gconf2 - was "error while loading shared libraries: libXss.so.1" on Xubuntu 16.04
const defaultStagePackages = ["libasound2", "libgconf2-4", "libnotify4", "libnspr4", "libnss3", "libpcre3", "libpulse0", "libxss1", "libxtst6"];
const defaultAfter = ["desktop-gtk2"];
const after = (0, (_builderUtil || _load_builderUtil()).replaceDefault)(options.after, defaultAfter);
snap.parts = {
app: {
plugin: "dump",
"stage-packages": (0, (_builderUtil || _load_builderUtil()).replaceDefault)(options.stagePackages, defaultStagePackages),
source: isUseDocker ? "/appOutDir" : appOutDir,
after
}
};
const stagePackages = (0, (_builderUtil || _load_builderUtil()).replaceDefault)(options.stagePackages, defaultStagePackages);
if (stagePackages.length > 0) {
snap.parts.app["stage-packages"] = stagePackages;
}
if (packager.packagerOptions.effectiveOptionComputed != null && (yield packager.packagerOptions.effectiveOptionComputed({ snap, desktopFile }))) {
return;
}
const snapcraftFile = _path.join(snapDir, "snapcraft.yaml");
yield (0, (_fsExtraP || _load_fsExtraP()).outputFile)(snapcraftFile, (0, (_builderUtil || _load_builderUtil()).serializeToYaml)(snap));
if (isUseDocker) {
yield _this.buildUsingDocker(options, arch, snapFileName, stageDir, appOutDir);
} else {
if (options.buildPackages != null && options.buildPackages.length > 0) {
yield (0, (_builderUtil || _load_builderUtil()).spawn)("apt-get", ["-qq", "update"]);
yield (0, (_builderUtil || _load_builderUtil()).spawn)("apt-get", ["-qq", "install", "--no-install-recommends"].concat(options.buildPackages));
}
const spawnOptions = {
cwd: stageDir.dir,
stdio: ["ignore", "inherit", "inherit"]
};
yield (0, (_builderUtil || _load_builderUtil()).spawn)("snapcraft", ["prime", "--target-arch", (0, (_builderUtil || _load_builderUtil()).toLinuxArchString)(arch)], spawnOptions);
yield (0, (_builderUtil || _load_builderUtil()).exec)("/bin/bash", ["-c", `rm -rf ${unnecessaryFiles.join(" ")}`], {
cwd: stageDir.dir + _path.sep + "prime"
});
yield (0, (_builderUtil || _load_builderUtil()).spawn)("snapcraft", ["snap", "--target-arch", (0, (_builderUtil || _load_builderUtil()).toLinuxArchString)(arch), "-o", artifactPath], spawnOptions);
}
yield stageDir.cleanup();
packager.dispatchArtifactCreated(artifactPath, _this, arch);
})();
}
buildUsingDocker(options, arch, snapFileName, stageDir, appOutDir) {
var _this2 = this;
return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
const commands = [];
if (options.buildPackages != null && options.buildPackages.length > 0) {
commands.push(`apt-get update && apt-get install -y ${options.buildPackages.join(" ")}`);
}
// copy stage to linux fs to avoid performance issues (https://docs.docker.com/docker-for-mac/osxfs-caching/)
commands.push(`cp -R /stage /s/`);
commands.push("cd /s");
commands.push("apt-get -qq update");
commands.push(`snapcraft prime --target-arch ${(0, (_builderUtil || _load_builderUtil()).toLinuxArchString)(arch)}`);
commands.push(`rm -rf ${unnecessaryFiles.map(function (it) {
return `prime/${it}`;
}).join(" ")}`);
commands.push(`snapcraft snap --target-arch ${(0, (_builderUtil || _load_builderUtil()).toLinuxArchString)(arch)} -o /out/${snapFileName}`);
const packager = _this2.packager;
yield (0, (_builderUtil || _load_builderUtil()).spawn)("docker", ["run", "--rm", "-v", `${packager.info.projectDir}:/project:delegated`,
// dist dir can be outside of project dir
"-v", `${_this2.outDir}:/out`, "-v", `${stageDir.dir}:/stage:ro`, "-v", `${appOutDir}:/appOutDir:ro`, "electronuserland/builder:latest", "/bin/bash", "-c", commands.join(" && ")], {
cwd: packager.info.projectDir,
stdio: ["ignore", "inherit", "inherit"]
});
})();
}
}
exports.default = SnapTarget; //# sourceMappingURL=snap.js.map