Repository navigation
Expand file tree
/
Copy pathrelease.ts
More file actions
48 lines (40 loc) · 1.4 KB
/
Copy pathrelease.ts
File metadata and controls
48 lines (40 loc) · 1.4 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
const bump = process.argv[2] as 'major' | 'minor' | 'patch';
if (!bump) {
console.error('Please specify a bump type: major, minor, or patch');
process.exit(1);
}
// Ensure git is clean before proceeding
const code = await Bun.spawn(['git', 'diff', '--quiet']).exited;
if (code !== 0) {
console.error(
'Git working directory is not clean. Please commit or stash your changes before releasing.'
);
process.exit(1);
}
const pkgjson = (await Bun.file('package.json').json()) as { version: string };
const [major, minor, patch] = pkgjson.version.split('.').map((part) => {
const parsed = Number.parseInt(part, 10);
return Number.isNaN(parsed) ? undefined : parsed;
});
if (major === undefined || minor === undefined || patch === undefined) {
console.error('Invalid version in package.json');
process.exit(1);
}
switch (bump) {
case 'major':
pkgjson.version = `${major + 1}.0.0`;
break;
case 'minor':
pkgjson.version = `${major}.${minor + 1}.0`;
break;
case 'patch':
pkgjson.version = `${major}.${minor}.${patch + 1}`;
break;
default:
console.error('Invalid bump type. Use "major", "minor", or "patch".');
process.exit(1);
}
await Bun.write('package.json', JSON.stringify(pkgjson, null, 2) + '\n');
await Bun.spawn(['git', 'add', 'package.json']).exited;
await Bun.spawn(['git', 'commit', '-m', `🔖 Release ${pkgjson.version}`]).exited;
await Bun.spawn(['git', 'tag', `v${pkgjson.version}`]).exited;