From c334fb4f42a70ee368ebc243ccb6f82bca31d265 Mon Sep 17 00:00:00 2001 From: Michael Kreil Date: Sat, 4 Nov 2023 21:07:44 +0100 Subject: [PATCH] improve release script --- package.json | 2 +- scripts/release.ts | 36 +++++++++++++++++------------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 83c7c59..03dba43 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "release": "tsx scripts/release.ts", "test-browser": "tsc -p tsconfig.browser.test.json && jest", "test-node": "npm run build-node && NODE_OPTIONS=--experimental-vm-modules jest -c=jest.node.config.js", - "test": "npm run test-browser && npm run test-node" + "test": "npm run test-node" }, "repository": { "type": "git", diff --git a/scripts/release.ts b/scripts/release.ts index 079acd0..7f02ab7 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -9,26 +9,26 @@ process.chdir((new URL('../', import.meta.url)).pathname); info('starting release process'); // lint -await check('lint', lint()); +await check('lint', run('npm run lint', true)); // check if no git //await check('are all changes committed?', checkThatNoUncommittedChanges()); // test -await check('run tests', test()); +await check('run tests', run('npm run test', true)); // build styles -await check('build styles', run('npm run build-styles')); +await check('build styles', run('npm run build-styles', true)); // build node -await check('build node version', run('npm run build-node')); +await check('build node version', run('npm run build-node', true)); // build browser -await check('build browser version', run('npm run build-browser')); - -// prepare release notes +await check('build browser version', run('npm run build-browser', true)); // handle version const new_version = await getVersion() +// prepare release notes + // npm release // git add @@ -41,12 +41,8 @@ const new_version = await getVersion() // upload styles // upload browser.js -async function lint() { - if ((await run('npm run lint')).code) throw Error('linting problems') -} -async function test() { - if ((await run('npm run test')).code) throw Error('testing problems') -} +/****************************************************************************/ + async function checkThatNoUncommittedChanges() { if ((await run('git status --porcelain')).stdout.length < 3) return; throw Error('please commit all changes before releasing'); @@ -108,14 +104,16 @@ async function getVersion() { /****************************************************************************/ -function run(command: string): Promise<{ code: number | null, signal: string | null, stdout: string, stderr: string }> { +function run(command: string, errorOnCodeZero?: true): Promise<{ code: number | null, signal: string | null, stdout: string, stderr: string }> { return new Promise((res, rej) => { const stdout: Buffer[] = []; const stderr: Buffer[] = []; const cp = spawn('bash', ['-c', command]) .on('error', error => rej(error)) .on('close', (code, signal) => { - res({ code, signal, stdout: Buffer.concat(stdout).toString(), stderr: Buffer.concat(stderr).toString() }) + const result = { code, signal, stdout: Buffer.concat(stdout).toString(), stderr: Buffer.concat(stderr).toString() }; + if (errorOnCodeZero && (code !== 0)) return rej(result); + res(result) }) cp.stdout?.on('data', chunk => stdout.push(chunk)); cp.stderr?.on('data', chunk => stderr.push(chunk)); @@ -126,13 +124,13 @@ function panic(text: string) { process.stderr.write(`\x1b[1;31m! ERROR: ${text}\ function warn(text: string) { process.stderr.write(`\x1b[1;33m! warning: ${text}\x1b[0m\n`); } function info(text: string) { process.stderr.write(`\x1b[0mi ${text}\n`); } function abort() { process.stderr.write('\x1b[1;31m! ABORT\x1b[0m\n'); process.exit(); } -async function check(message: string, promise: Promise) { - process.stderr.write(`\x1b[0;90m\u2610 ${message}\x1b[0m`); +async function check(message: string, promise: Promise) { + process.stderr.write(`\x1b[0;90m\u2B95 ${message}\x1b[0m`); try { await promise; - process.stderr.write(`\r\x1b[0;92m\u2611 ${message}\x1b[0m\n`); + process.stderr.write(`\r\x1b[0;92m\u2714 ${message}\x1b[0m\n`); } catch (error) { - process.stderr.write(`\r\x1b[0;91m\u2610 ${message}\x1b[0m\n`); + process.stderr.write(`\r\x1b[0;91m\u2718 ${message}\x1b[0m\n`); panic((error as Error).message); } } \ No newline at end of file