-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtag-channel.ts
More file actions
51 lines (39 loc) · 1.46 KB
/
tag-channel.ts
File metadata and controls
51 lines (39 loc) · 1.46 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
#!/usr/bin/env bun
/**
* Manage npm dist-tags for the allagents package.
*
* Usage:
* bun scripts/tag-channel.ts <next|latest> [version]
*/
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { $ } from 'bun';
type DistTag = 'next' | 'latest';
const VALID_TAGS: DistTag[] = ['next', 'latest'];
function parseArgs(argv: readonly string[]): { tag: DistTag; version?: string } {
const tag = argv[2];
const version = argv[3];
if (!tag) {
throw new Error('Missing dist-tag. Usage: bun scripts/tag-channel.ts <next|latest> [version]');
}
if (!VALID_TAGS.includes(tag as DistTag)) {
throw new Error(`Invalid dist-tag: ${tag}. Valid options: ${VALID_TAGS.join(', ')}`);
}
return { tag: tag as DistTag, version };
}
async function main() {
const { tag, version: requestedVersion } = parseArgs(process.argv);
const pkgPath = resolve(process.cwd(), 'package.json');
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { name: string; version: string };
const targetVersion = requestedVersion ?? pkg.version;
const spec = `${pkg.name}@${targetVersion}`;
console.log(`🏷️ Tagging npm dist-tag '${tag}' -> ${targetVersion}\n`);
console.log(`• ${spec}`);
await $`npm dist-tag add ${spec} ${tag}`.quiet();
console.log('\n✅ Updated npm dist-tag.');
}
main().catch((error) => {
const message = error instanceof Error ? error.message : String(error);
console.error(`❌ ${message}`);
process.exit(1);
});