@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.
69 lines • 3.13 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeAppXImages = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
const node_path_1 = __importDefault(require("node:path"));
const sharp_1 = __importDefault(require("sharp"));
const REQUIRED_APPX_DIMENSIONS = [
{ w: 150, h: 150 },
{ w: 44, h: 44 },
{ w: 310, h: 150 },
{ w: 310, h: 310 },
{ w: 71, h: 71 },
{ w: 50, h: 50, specialName: 'StoreLogo' },
];
const REQUIRED_APPX_SCALES = [100, 125, 150, 200, 400];
const INVISIBLE = { r: 0, g: 0, b: 0, alpha: 0 };
const makeAppXImages = async (appID, outPath, config) => {
var _a;
const assetPath = node_path_1.default.join(outPath, 'assets');
await fs_extra_1.default.ensureDir(assetPath);
for (const scale of REQUIRED_APPX_SCALES) {
const scaleMultiplier = scale / 100.0;
for (const dimensions of REQUIRED_APPX_DIMENSIONS) {
const { w, h } = dimensions;
const [imageWidth, imageHeight] = [
Math.trunc(w * scaleMultiplier),
Math.trunc(h * scaleMultiplier),
];
const baseName = (_a = dimensions.specialName) !== null && _a !== void 0 ? _a : `${appID}-${w}x${h}Logo`;
const imageNamewithScale = `${baseName}.scale-${scale}.png`;
const pathOnDiskWithScale = node_path_1.default.join(node_path_1.default.join(assetPath, imageNamewithScale));
const image = (0, sharp_1.default)(config.appIcon);
// Small touch: superimpose the app icon on a background for banner-sized images
if ((h > 300 || w > 300) && config.wallpaperIcon) {
const bgimage = (0, sharp_1.default)(config.wallpaperIcon).resize(imageWidth, imageHeight, {
fit: 'cover',
background: INVISIBLE,
});
const overlayicon = await image
.resize(Math.trunc(imageWidth * 0.85), Math.trunc(imageHeight * 0.85), {
fit: 'inside',
background: INVISIBLE,
})
.toBuffer();
await bgimage
.composite([{ input: overlayicon, gravity: 'center' }])
.toFile(pathOnDiskWithScale);
}
else {
await image
.resize(imageWidth, imageHeight, {
fit: 'contain',
background: INVISIBLE,
})
.toFile(pathOnDiskWithScale);
}
if (scale === 100) {
const imageName = `${baseName}.png`;
const pathOnDiskWithoutScale = node_path_1.default.join(node_path_1.default.join(assetPath, imageName));
await fs_extra_1.default.copyFile(pathOnDiskWithScale, pathOnDiskWithoutScale);
}
}
}
};
exports.makeAppXImages = makeAppXImages;
//# sourceMappingURL=imageAssets.js.map