-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathfinalizeRelease.ts
More file actions
66 lines (60 loc) · 2 KB
/
Copy pathfinalizeRelease.ts
File metadata and controls
66 lines (60 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env ts-node
/* eslint-disable import/extensions, no-console */
import * as readline from 'node:readline';
import simpleGit from 'simple-git';
import { version } from '../package.json';
/**
* Script: upgradeConfigs.ts
* Run with: ts-node scripts/upgradeConfig.ts
* ------------------------------------------
* Amend the previous commit with changes to the changelog
* Then tag and push it. This script is run after
* `npx commit-and-tag-version`
*/
/**
* Amends the previous commit, creates the annotated release tag
* and then pushes commit and tag.
*/
async function commitAndTag(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/naming-convention
await simpleGit().commit([], 'CHANGELOG.md', { '--amend': null, '--no-edit': null, '--no-verify': null });
await simpleGit().addAnnotatedTag(`v${version}`, `Release Version ${version}`);
// eslint-disable-next-line @typescript-eslint/naming-convention
await simpleGit().push({ '--follow-tags': null });
}
/**
* Prompts the user for input
*
* @param query - A string to prompt the user
*
* @returns Promise with the input of the user
*/
async function waitForUserInput(query: string): Promise<string> {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
return new Promise((resolve): void => rl.question(query, (answer): void => {
rl.close();
resolve(answer);
}));
}
/**
* Halts the script, waiting for user input before
* committing the changelog changes, adding an
* annotated tag and pushing the changes to origin.
*/
async function finalizeRelease(): Promise<void> {
await waitForUserInput('Manually edit CHANGELOG.md, press any key to finalize...');
return commitAndTag();
}
/**
* Ends the process and writes out an error in case something goes wrong.
*/
function endProcess(error: Error): never {
console.error(error);
process.exit(1);
}
finalizeRelease()
.then((): void => console.info(`Changes and tag v${version} pushed to origin.`))
.catch(endProcess);