chore: update build windows script

This commit is contained in:
buqiyuan 2023-03-06 22:05:11 +08:00
parent be5c25eada
commit ca1d180926

View File

@ -2,12 +2,14 @@ import { sign, doSign } from 'app-builder-lib/out/codeSign/windowsCodeSign';
import { build, BuildResult, Platform } from 'electron-builder';
import type { Configuration } from 'electron-builder';
import minimist from 'minimist';
import YAML from 'yaml';
import pkgInfo from '../package.json';
import { ELETRON_APP_CONFIG } from '../src/environment';
import { execSync, exec, spawn } from 'node:child_process';
import { copyFileSync, readFileSync, writeFileSync } from 'node:fs';
import { createHash } from 'node:crypto';
import { copyFileSync, createReadStream, readFileSync, writeFileSync } from 'node:fs';
import path, { resolve } from 'node:path';
import { exit, platform } from 'node:process';
@ -36,6 +38,21 @@ if (process.platform === 'win32') {
exec(`rd/s/q ${path.resolve(__dirname, '../release')}`);
}
function hashFile(file: string, algorithm = 'sha512', encoding: 'base64' | 'hex' = 'base64', options?: any): Promise<string> {
return new Promise<string>((resolve, reject) => {
const hash = createHash(algorithm);
hash.on('error', reject).setEncoding(encoding);
createReadStream(file, { ...options, highWaterMark: 1024 * 1024 /* better to use more memory but hash faster */ })
.on('error', reject)
.on('end', () => {
hash.end();
resolve(hash.read() as string);
})
.pipe(hash, { end: false });
});
}
const config: Configuration = {
appId: '.postcat.io',
productName: 'Postcat',
@ -182,6 +199,16 @@ const signWindows = () => {
await sign(...signOptions);
if (argv.publish === 'always') {
const latestYmlPath = path.join(__dirname, '../release/latest.yml');
const latestYml = readFileSync(latestYmlPath, 'utf8');
const latestYmlObj = YAML.parse(latestYml);
const sha512 = await hashFile(signOptions[0].path);
latestYmlObj.sha512 = sha512;
for (const file of latestYmlObj.files) {
file.sha512 = sha512;
}
writeFileSync(latestYmlPath, YAML.stringify(latestYmlObj));
execSync('yarn releaseWindows');
}