UNPKG

@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.

129 lines 4.22 kB
"use strict"; // Borrowed with modifications from https://github.com/felixrieseberg/electron-updater-yaml // MIT Licensed var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAppUpdateYml = getAppUpdateYml; exports.getChannelYml = getChannelYml; const crypto_1 = __importDefault(require("crypto")); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); /** * Returns the contents of the app-update.yml file, which you should place in * your app package's "resources" folder. This file is used by the auto-updater * to determine where to download updates from. */ async function getAppUpdateYml(options) { const { name, url, publisherName } = options; const channel = options.channel || 'latest'; const updaterCacheDirName = options.updaterCacheDirName || `${name.toLowerCase()}-updater`; let ymlContents = `provider: generic url: '${url}' channel: ${channel} updaterCacheDirName: ${updaterCacheDirName}\n`; if (publisherName) { ymlContents += `publisherName: - ${publisherName}\n`; } return ymlContents; } /** * Returns the contents of the channel.yml file, which you should place in your */ async function getChannelYml(options) { const { installerPath, version } = options; const platform = options.platform || process.platform; const releaseDate = options.releaseDate || new Date().toISOString(); const files = await getFiles(installerPath, platform); let filesText = ''; for (const file of files) { filesText += ` - url: ${file.name} sha512: ${file.hash} size: ${file.size}`; } const ymlContents = `version: ${version} files:${filesText} path: ${files[0].name} sha512: ${files[0].hash} releaseDate: '${releaseDate}'\n`; return ymlContents; } /** * Returns files we should use to auto-update */ async function getFiles(installerPath, platform) { const files = []; const result = []; if (platform === 'win32') { const exeFile = getFileInFolder(/\.exe$/, installerPath); const msixFile = getFileInFolder(/\.msix$/, installerPath); if (!(exeFile || msixFile)) { throw new Error(`Could not find .exe or .msix file in ${installerPath}`); } if (exeFile) { files.push(exeFile); } if (msixFile) { files.push(msixFile); } } else if (platform === 'darwin') { const zipFile = getFileInFolder(/\.zip$/, installerPath); const dmgFile = getFileInFolder(/\.dmg$/, installerPath); if (!zipFile) { throw new Error(`Could not find .zip file in ${installerPath}`); } if (!dmgFile) { throw new Error(`Could not find .dmg file in ${installerPath}`); } files.push(zipFile, dmgFile); } else { throw new Error(`Unsupported platform: ${platform}`); } for (const file of files) { const filePath = path_1.default.join(installerPath, file); result.push({ name: file, path: filePath, size: getFileSize(filePath), hash: await getFileHash(filePath), }); } return result; } /** * Returns an sha512 hash of the file at the given path */ function getFileHash(filePath) { const hash = crypto_1.default.createHash('sha512'); const stream = fs_1.default.createReadStream(filePath); hash.setEncoding('base64'); return new Promise((resolve, reject) => { stream.on('end', () => { hash.end(); resolve(hash.read()); }); stream.on('error', (error) => { hash.end(); reject(error); }); stream.pipe(hash); }); } /** * Returns file size in bytes */ function getFileSize(filePath) { return fs_1.default.statSync(filePath).size; } /** * Find files in a folder that match a certain extension */ function getFileInFolder(test, dir) { return fs_1.default.readdirSync(dir).find((file) => test.test(file)); } //# sourceMappingURL=yaml.js.map