Skip to content

Commit

Permalink
chore: update build windows script
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Mar 6, 2023
1 parent be5c25e commit ca1d180
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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');
}

Expand Down

0 comments on commit ca1d180

Please sign in to comment.