@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.
97 lines • 4.11 kB
JavaScript
import { MakerBase } from '@electron-forge/maker-base';
import fs from 'fs-extra';
import path from 'node:path';
import { makeAppXImages as makeMSIXImageTiles } from './imageAssets';
import { getPublisher, makeAppInstaller, makeAppManifest, makeManifestConfiguration, makePRI, writeContentTypeXML, } from './msixTools';
import { log, run } from './run';
import { codesign } from './sign';
import { findInWindowsKits, walk } from './walk';
const findMainExecutable = async (rootPath) => {
let executable;
for await (const fileName of 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 findInWindowsKits('makeappx.exe'));
await codesign(config, scratchPath);
try {
if ((await fs.stat(outMSIX)).isFile()) {
log(`${outMSIX} already exists; making new one`);
await fs.unlink(outMSIX);
}
}
catch (e) {
log(`Error looking for existing ${outMSIX}: ${e}`);
}
await run(makeAppXPath, ['pack', '/d', scratchPath, '/p', outMSIX]);
await codesign(config, outMSIX);
};
export default class MakerMSIX extends 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 = path.join(options.makeDir, 'msix/build/');
if (await fs.pathExists(scratchPath)) {
await fs.remove(scratchPath);
}
const programFilesPath = path.join(scratchPath, options.appName);
await fs.ensureDir(programFilesPath);
await fs.copy(options.dir, programFilesPath);
// Make sure the build dir exists
const outPath = path.join(options.makeDir, `${options.appName}-${options.targetArch}-msix/`);
await fs.ensureDir(outPath);
// Find all the files to be installed
const executable = await findMainExecutable(scratchPath);
// Generate images for various tile sizes
await makeMSIXImageTiles(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 getPublisher(path.join(scratchPath, executable), this.config);
}
const manifestConfig = makeManifestConfiguration({
appID,
version: options.packageJSON.version,
executable,
config: {
...this.config,
publisher,
},
options,
});
await makeAppManifest(scratchPath, manifestConfig);
const appInstallerPath = await makeAppInstaller(outPath, scratchPath, manifestConfig);
await makePRI(scratchPath, this.config);
await writeContentTypeXML(scratchPath);
const outMSIX = path.join(outPath, manifestConfig.msixFilename);
await makeMSIX(scratchPath, outMSIX, this.config);
return [outMSIX, appInstallerPath].filter((filename) => filename !== undefined);
}
}
//# sourceMappingURL=makerMsix.js.map