electron-builder-lib
Version:
electron-builder lib
188 lines (163 loc) • 8.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LinuxTargetHelper = exports.installPrefix = undefined;
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 _lazyVal;
function _load_lazyVal() {
return _lazyVal = require("lazy-val");
}
var _path = _interopRequireWildcard(require("path"));
var _pathManager;
function _load_pathManager() {
return _pathManager = require("../util/pathManager");
}
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; } }
const installPrefix = exports.installPrefix = "/opt";
class LinuxTargetHelper {
constructor(packager) {
this.packager = packager;
this.iconPromise = new (_lazyVal || _load_lazyVal()).Lazy(() => this.computeDesktopIcons());
this.maxIconPath = null;
}
get icons() {
return this.iconPromise.value;
}
// must be name without spaces and other special characters, but not product name used
computeDesktopIcons() {
var _this = this;
return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
let collectIcons = (() => {
var _ref = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (sourceDir) {
return JSON.parse((yield (0, (_builderUtil || _load_builderUtil()).exec)((yield (0, (_tools || _load_tools()).getAppBuilderTool)()), ["collect-icons", "--source", sourceDir], execOptions)));
});
return function collectIcons(_x) {
return _ref.apply(this, arguments);
};
})();
const packager = _this.packager;
const execOptions = {
env: Object.assign({}, process.env, {
// icns-to-png creates temp dir amd cannot delete it automatically since result files located in and it is our responsibility remove it after use,
// so, we just set TMPDIR to tempDirManager.rootTempDir and tempDirManager in any case will delete rootTempDir on exit
TMPDIR: yield _this.packager.info.tempDirManager.rootTempDir })
};
let iconDir = packager.platformSpecificBuildOptions.icon;
if (iconDir != null) {
const iconDirCandidate = _path.resolve(packager.info.buildResourcesDir, iconDir);
if ((yield (0, (_fs || _load_fs()).statOrNull)(iconDirCandidate)) == null) {
iconDir = _path.resolve(packager.projectDir, iconDir);
} else {
iconDir = iconDirCandidate;
}
} else if ((yield packager.resourceList).includes("icons")) {
iconDir = _path.join(packager.info.buildResourcesDir, "icons");
}
let result;
if (iconDir == null) {
const icnsPath = yield _this.getIcns();
if (icnsPath == null) {
result = yield collectIcons(_path.join((0, (_pathManager || _load_pathManager()).getTemplatePath)("linux"), "electron-icons"));
} else {
result = JSON.parse((yield (0, (_builderUtil || _load_builderUtil()).exec)((yield (0, (_tools || _load_tools()).getAppBuilderTool)()), ["icns-to-png", "--input", icnsPath], execOptions)));
}
} else {
result = yield collectIcons(iconDir);
}
_this.maxIconPath = result.maxIconPath;
return result.icons;
})();
}
getIcns() {
var _this2 = this;
return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
const build = _this2.packager.info.config;
let iconPath = (build.mac || {}).icon || build.icon;
if (iconPath != null && !iconPath.endsWith(".icns")) {
iconPath += ".icns";
}
return iconPath == null ? yield _this2.packager.getDefaultIcon("icns") : _path.resolve(_this2.packager.projectDir, iconPath);
})();
}
getDescription(options) {
return options.description || this.packager.appInfo.description;
}
writeDesktopEntry(targetSpecificOptions, exec, destination, extra) {
var _this3 = this;
return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
const data = yield _this3.computeDesktopEntry(targetSpecificOptions, exec, extra);
const tempFile = destination || (yield _this3.packager.getTempFile(`${_this3.packager.appInfo.productFilename}.desktop`));
yield (0, (_fsExtraP || _load_fsExtraP()).outputFile)(tempFile, data);
return tempFile;
})();
}
computeDesktopEntry(targetSpecificOptions, exec, extra) {
var _this4 = this;
return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
if (exec != null && exec.length === 0) {
throw new Error("Specified exec is empty");
}
const appInfo = _this4.packager.appInfo;
const productFilename = appInfo.productFilename;
const desktopMeta = Object.assign({ Name: appInfo.productName, Comment: _this4.getDescription(targetSpecificOptions), Exec: exec == null ? `"${installPrefix}/${productFilename}/${_this4.packager.executableName}" %U` : exec, Terminal: "false", Type: "Application", Icon: _this4.packager.executableName }, extra, targetSpecificOptions.desktop);
let category = targetSpecificOptions.category;
if ((0, (_builderUtil || _load_builderUtil()).isEmptyOrSpaces)(category)) {
const macCategory = (_this4.packager.config.mac || {}).category;
if (macCategory != null) {
category = macToLinuxCategory[macCategory];
}
if (category == null) {
// https://github.com/develar/onshape-desktop-shell/issues/48
if (macCategory != null) {
(_builderUtil || _load_builderUtil()).log.warn({ macCategory }, "cannot map macOS category to Linux. If possible mapping is known for you, please file issue to add it.");
}
(_builderUtil || _load_builderUtil()).log.warn({
reason: "linux.category is not set and cannot map from macOS",
docs: "https://electron.build/configuration/configuration#LinuxBuildOptions-category"
}, "application Linux category is set to default \"Utility\"");
category = "Utility";
}
}
desktopMeta.Categories = `${category}${category.endsWith(";") ? "" : ";"}`;
let data = `[Desktop Entry]`;
for (const name of Object.keys(desktopMeta)) {
const value = desktopMeta[name];
data += `\n${name}=${value}`;
}
data += "\n";
return data;
})();
}
}
exports.LinuxTargetHelper = LinuxTargetHelper;
const macToLinuxCategory = {
"public.app-category.graphics-design": "Graphics",
"public.app-category.developer-tools": "Development",
"public.app-category.education": "Education",
"public.app-category.games": "Game",
"public.app-category.video": "Video;AudioVideo",
"public.app-category.utilities": "Utility",
"public.app-category.social-networking": "Chat",
"public.app-category.finance": "Finance"
};
//# sourceMappingURL=LinuxTargetHelper.js.map