-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbump-desktop-version.ts
More file actions
115 lines (98 loc) · 2.73 KB
/
Copy pathbump-desktop-version.ts
File metadata and controls
115 lines (98 loc) · 2.73 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {
desktopReleasePackageSources,
normalizeReleaseVersion,
readPackageVersion,
writePackageVersion,
} from './desktop-release-version.ts';
interface ParsedArgs {
dryRun: boolean;
version?: string;
}
interface VersionChange {
currentVersion: string;
path: string;
}
function parseArgs(argv: string[]): ParsedArgs {
const args: ParsedArgs = { dryRun: false };
for (let i = 0; i < argv.length; i += 1) {
const arg = argv[i];
const next = argv[i + 1];
if (arg === '--dry-run') {
args.dryRun = true;
continue;
}
if (arg === '--version' || arg === '-v') {
if (!next) throw new Error(`${arg} requires a value.`);
if (args.version) throw new Error('Only one release version is allowed.');
args.version = next;
i += 1;
continue;
}
if (arg.startsWith('-')) {
throw new Error(`Unknown argument: ${arg}`);
}
if (args.version) {
throw new Error('Only one release version is allowed.');
}
args.version = arg;
}
return args;
}
function printUsage(): void {
console.error(
[
'Usage: bun run bump-desktop-version <version>',
' bun run bump-desktop-version --dry-run <version>',
'',
'Examples:',
' bun run bump-desktop-version 0.0.2',
' bun run bump-desktop-version v0.0.2',
].join('\n'),
);
}
function main(): void {
const args = parseArgs(process.argv.slice(2));
if (!args.version) {
printUsage();
throw new Error('Release version is required.');
}
const { tag, version } = normalizeReleaseVersion(args.version);
const changes: VersionChange[] = desktopReleasePackageSources.map(
(source) => ({
currentVersion: readPackageVersion(source.path),
path: source.path,
}),
);
const pendingChanges = changes.filter(
(change) => change.currentVersion !== version,
);
if (args.dryRun) {
console.log(`Desktop version dry run: ${version} (${tag})`);
for (const change of changes) {
const suffix =
change.currentVersion === version
? 'already set'
: `${change.currentVersion} -> ${version}`;
console.log(` - ${change.path}: ${suffix}`);
}
console.log('No files were changed.');
return;
}
for (const change of pendingChanges) {
writePackageVersion(change.path, version);
}
if (pendingChanges.length === 0) {
console.log(`Desktop version already set to ${version} (${tag})`);
return;
}
console.log(`Updated desktop version to ${version} (${tag})`);
for (const change of pendingChanges) {
console.log(` - ${change.path}: ${change.currentVersion} -> ${version}`);
}
}
try {
main();
} catch (error) {
console.error(error instanceof Error ? error.message : error);
process.exit(1);
}