@jasonscheirer/electron-forge-maker-msix
Version:
An `electron-forge` maker for MSIX that supports `electron-forge` v6 and can be used as a replacement for `electron-builder`. Supports code-signing.
103 lines • 4.66 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const maker_base_1 = require("@electron-forge/maker-base");
const fs_extra_1 = __importDefault(require("fs-extra"));
const node_path_1 = __importDefault(require("node:path"));
const imageAssets_1 = require("./imageAssets");
const msixTools_1 = require("./msixTools");
const run_1 = require("./run");
const sign_1 = require("./sign");
const walk_1 = require("./walk");
const findMainExecutable = async (rootPath) => {
let executable;
for await (const fileName of (0, walk_1.walk)(rootPath)) {
const relativeFileName = fileName.substring(rootPath.length).replace(/^[\\/]+/, '');
if (relativeFileName.toLocaleLowerCase().endsWith('.exe') &&
(!executable || executable.split(/[/\\]/).length > relativeFileName.split(/[/\\]/).length)) {
executable = relativeFileName;
}
}
if (!executable) {
throw new Error(`No executable file found in ${rootPath}`);
}
return executable;
};
const makeMSIX = async (scratchPath, outMSIX, config) => {
var _a;
const makeAppXPath = (_a = config.makeAppXPath) !== null && _a !== void 0 ? _a : (await (0, walk_1.findInWindowsKits)('makeappx.exe'));
await (0, sign_1.codesign)(config, scratchPath);
try {
if ((await fs_extra_1.default.stat(outMSIX)).isFile()) {
(0, run_1.log)(`${outMSIX} already exists; making new one`);
await fs_extra_1.default.unlink(outMSIX);
}
}
catch (e) {
(0, run_1.log)(`Error looking for existing ${outMSIX}: ${e}`);
}
await (0, run_1.run)(makeAppXPath, ['pack', '/d', scratchPath, '/p', outMSIX]);
await (0, sign_1.codesign)(config, outMSIX);
};
class MakerMSIX extends maker_base_1.MakerBase {
constructor() {
super(...arguments);
this.name = 'msix';
this.defaultPlatforms = ['win32'];
}
isSupportedOnCurrentPlatform() {
return process.platform === 'win32';
}
async make(options) {
var _a;
const appID = (_a = this.config.internalAppID) !== null && _a !== void 0 ? _a : options.appName
.toUpperCase()
.replace(/[^A-Z]/g, '')
.slice(0, 10);
// Copy out files to scratch directory for signing/packaging
const scratchPath = node_path_1.default.join(options.makeDir, 'msix/build/');
if (await fs_extra_1.default.pathExists(scratchPath)) {
await fs_extra_1.default.remove(scratchPath);
}
const programFilesPath = node_path_1.default.join(scratchPath, options.appName);
await fs_extra_1.default.ensureDir(programFilesPath);
await fs_extra_1.default.copy(options.dir, programFilesPath);
// Make sure the build dir exists
const outPath = node_path_1.default.join(options.makeDir, `${options.appName}-${options.targetArch}-msix/`);
await fs_extra_1.default.ensureDir(outPath);
// Find all the files to be installed
const executable = await findMainExecutable(scratchPath);
// Generate images for various tile sizes
await (0, imageAssets_1.makeAppXImages)(appID, scratchPath, this.config);
// Actual AppxManifest.xml, the orchestration layer
// Courtesy: if publisher is not set, pull from signed exe
let publisher;
if (this.config.publisher) {
publisher = this.config.publisher;
}
else {
publisher = await (0, msixTools_1.getPublisher)(node_path_1.default.join(scratchPath, executable), this.config);
}
const manifestConfig = (0, msixTools_1.makeManifestConfiguration)({
appID,
version: options.packageJSON.version,
executable,
config: {
...this.config,
publisher,
},
options,
});
await (0, msixTools_1.makeAppManifest)(scratchPath, manifestConfig);
const appInstallerPath = await (0, msixTools_1.makeAppInstaller)(outPath, scratchPath, manifestConfig);
await (0, msixTools_1.makePRI)(scratchPath, this.config);
await (0, msixTools_1.writeContentTypeXML)(scratchPath);
const outMSIX = node_path_1.default.join(outPath, manifestConfig.msixFilename);
await makeMSIX(scratchPath, outMSIX, this.config);
return [outMSIX, appInstallerPath].filter((filename) => filename !== undefined);
}
}
exports.default = MakerMSIX;
//# sourceMappingURL=makerMsix.js.map