-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretag
executable file
·42 lines (34 loc) · 1.11 KB
/
retag
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
#!/usr/bin/env node
import process from 'node:process';
import child_process from 'node:child_process';
import { promisify } from 'node:util';
import { readFile } from 'node:fs/promises';
const execFile = promisify(child_process.execFile);
async function main() {
let version;
if (process.argv.length == 2) {
const content = await readFile('./package.json', { encoding: 'utf8' });
version = JSON.parse(content).version;
}
else if (process.argv.length == 3) {
version = process.argv[2];
}
else {
throw new Error(`Invalid args ${process.argv.join(', ')}`);
}
const res = version.match(/^v?((([0-9]+)\.[0-9]+)\.[0-9]+)$/);
if (res === null) {
throw new Error(`Invalid version ${version}`);
}
const [ , patch, minor, major ] = res;
const { stdout, stderr } = await execFile('git', ['rev-parse', '--verify', '--quiet', `v${patch}`]);
if (stderr.length) {
process.stderr.write(stderr);
}
const tagRef = stdout.trim();
for (const tag of [minor, major]) {
await execFile('git', ['update-ref', `refs/tags/v${tag}`, tagRef]);
process.stdout.write(`v${tag}\n`);
}
}
main();