You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
8.1 KiB

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MakerBase = void 0;
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const which_1 = __importDefault(require("which"));
class Maker {
/**
* @param configOrConfigFetcher - Either a configuration object for this maker or a simple method that returns such a configuration for a given target architecture
* @param platformsToMakeOn - If you want this maker to run on platforms different from `defaultPlatforms` you can provide those platforms here
*/
constructor(configOrConfigFetcher = {}, platformsToMakeOn) {
this.configOrConfigFetcher = configOrConfigFetcher;
this.platformsToMakeOn = platformsToMakeOn;
this.requiredExternalBinaries = [];
Object.defineProperty(this, '__isElectronForgeMaker', {
value: true,
enumerable: false,
configurable: false,
});
}
get platforms() {
if (this.platformsToMakeOn)
return this.platformsToMakeOn;
return this.defaultPlatforms;
}
// TODO: Remove this, it is an eye-sore and is a nasty hack to provide forge
// v5 style functionality in the new API
async prepareConfig(targetArch) {
if (typeof this.configOrConfigFetcher === 'function') {
this.config = await Promise.resolve(this.configOrConfigFetcher(targetArch));
}
else {
this.config = this.configOrConfigFetcher;
}
}
/**
* Makers must implement this method and return true or false indicating whether
* this maker can be run on the current platform. Normally this is just a process.platform
* check but it can be a deeper check for dependencies like fake-root or other
* required external build tools.
*
* If the issue is a missing dependency you should log out a HELPFUL error message
* telling the developer exactly what is missing and if possible how to get it.
*/
isSupportedOnCurrentPlatform() {
if (this.isSupportedOnCurrentPlatform === Maker.prototype.isSupportedOnCurrentPlatform) {
throw new Error(`Maker ${this.name} did not implement the isSupportedOnCurrentPlatform method`);
}
return true;
}
/**
* Makers must implement this method and return an array of absolute paths
* to the artifacts generated by your maker
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async make(opts) {
if (this.make === Maker.prototype.make) {
throw new Error(`Maker ${this.name} did not implement the make method`);
}
return [];
}
/**
* Helpers
*/
/**
* Ensures the directory exists and is forced to be empty.
*
* I.e. If the directory already exists it is deleted and recreated, this
* is a destructive operation
*/
async ensureDirectory(dir) {
if (await fs_extra_1.default.pathExists(dir)) {
await fs_extra_1.default.remove(dir);
}
return fs_extra_1.default.mkdirs(dir);
}
/**
* Ensures the path to the file exists and the file does not exist
*
* I.e. If the file already exists it is deleted and the path created
*/
async ensureFile(file) {
if (await fs_extra_1.default.pathExists(file)) {
await fs_extra_1.default.remove(file);
}
await fs_extra_1.default.mkdirs(path_1.default.dirname(file));
}
/**
* Checks if the specified binaries exist, which are required for the maker to be used.
*/
externalBinariesExist() {
return this.requiredExternalBinaries.every((binary) => which_1.default.sync(binary, { nothrow: true }) !== null);
}
/**
* Throws an error if any of the binaries don't exist.
*/
ensureExternalBinariesExist() {
if (!this.externalBinariesExist()) {
throw new Error(`Cannot make for ${this.name}, the following external binaries need to be installed: ${this.requiredExternalBinaries.join(', ')}`);
}
}
/**
* Checks if the given module is installed, used for testing if optional dependencies
* are installed or not
*/
isInstalled(module) {
try {
require(module);
return true;
}
catch (e) {
// Package doesn't exist -- must not be installable on this platform
return false;
}
}
/**
* Normalize the given semver-formatted version to a 4-part dot delimited version number without
* prerelease information for use in Windows apps.
*/
normalizeWindowsVersion(version) {
const noPrerelease = version.replace(/-.*/, '');
return `${noPrerelease}.0`;
}
}
exports.default = Maker;
exports.MakerBase = Maker;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFrZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvTWFrZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsZ0RBQXdCO0FBR3hCLHdEQUEwQjtBQUMxQixrREFBMEI7QUFvQzFCLE1BQThCLEtBQUs7SUFZakM7OztPQUdHO0lBQ0gsWUFBb0Isd0JBQXNELEVBQU8sRUFBWSxpQkFBbU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