@fmdzc/cli-ai 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/scripts/tag.js ADDED
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { readFileSync } from 'node:fs';
4
+ import { dirname, join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const ROOT_DIR = join(__dirname, '..');
9
+
10
+ function git(args, options = {}) {
11
+ const cmd = `git ${args}`;
12
+ try {
13
+ return execSync(cmd, {
14
+ cwd: ROOT_DIR,
15
+ encoding: 'utf8',
16
+ stdio: options.silent ? 'pipe' : 'inherit',
17
+ ...options,
18
+ });
19
+ } catch (error) {
20
+ if (options.ignoreError) return null;
21
+ throw error;
22
+ }
23
+ }
24
+
25
+ function getPackageTag() {
26
+ const pkgPath = join(ROOT_DIR, 'package.json');
27
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
28
+ return `v${pkg.version}`;
29
+ }
30
+
31
+ function createTag(tag) {
32
+ const version = tag.slice(1);
33
+ console.log(`Creating tag ${tag}...`);
34
+
35
+ git(`tag -a ${tag} -m "Release ${version}"`);
36
+ console.log(`✓ Tag ${tag} created locally`);
37
+
38
+ console.log(`Pushing tag ${tag} to origin...`);
39
+ git(`push origin ${tag}`);
40
+ console.log(`✓ Tag ${tag} pushed to origin`);
41
+
42
+ return tag;
43
+ }
44
+
45
+ function repushTag(tag) {
46
+ console.log(`Re-pushing tag ${tag}...`);
47
+
48
+ console.log(`Deleting local tag ${tag}...`);
49
+ git(`tag -d ${tag}`, { ignoreError: true, silent: true });
50
+ console.log(`✓ Local tag deleted (or didn't exist)`);
51
+
52
+ console.log(`Deleting remote tag ${tag}...`);
53
+ git(`push origin --delete ${tag}`, { ignoreError: true, silent: true });
54
+ console.log(`✓ Remote tag deleted (or didn't exist)`);
55
+
56
+ return createTag(tag);
57
+ }
58
+
59
+ function showUsage() {
60
+ console.log(`
61
+ Usage: node scripts/tag.js [options] [tag]
62
+
63
+ Creates and pushes a git tag for the specified version.
64
+ If no tag is provided, uses the version from package.json.
65
+
66
+ Options:
67
+ --repush, --force Delete existing tag (local & remote) before creating
68
+ --help, -h Show this help message
69
+
70
+ Examples:
71
+ node scripts/tag.js # Tag current package.json version
72
+ node scripts/tag.js v3.0.5 # Tag specific version
73
+ node scripts/tag.js --repush # Re-push current version tag
74
+ node scripts/tag.js --force v3.0.5 # Re-push specific version tag
75
+ `);
76
+ }
77
+
78
+ function main() {
79
+ const args = process.argv.slice(2);
80
+
81
+ // Parse arguments
82
+ let repush = false;
83
+ let tag = null;
84
+
85
+ for (const arg of args) {
86
+ if (arg === '--help' || arg === '-h') {
87
+ showUsage();
88
+ process.exit(0);
89
+ } else if (arg === '--repush' || arg === '--force') {
90
+ repush = true;
91
+ } else if (!arg.startsWith('-')) {
92
+ tag = arg;
93
+ }
94
+ }
95
+
96
+ // Use package.json version if not specified
97
+ if (!tag) {
98
+ tag = getPackageTag();
99
+ }
100
+
101
+ // Validate tag format (vX.X.X with optional prerelease/build metadata)
102
+ if (!/^v\d+\.\d+\.\d+(-[\w.]+)?(\+[\w.]+)?$/.test(tag)) {
103
+ console.error(`Invalid tag format: ${tag}`);
104
+ console.error(`Expected format: vX.X.X (e.g., v3.0.5)`);
105
+ process.exit(1);
106
+ }
107
+
108
+ console.log(`\nTag: ${tag}`);
109
+ console.log(`Mode: ${repush ? 're-push (delete + create)' : 'create new'}\n`);
110
+
111
+ try {
112
+ const result = repush ? repushTag(tag) : createTag(tag);
113
+ console.log(`\n✓ Successfully ${repush ? 're-pushed' : 'created'} tag ${result}`);
114
+ } catch (error) {
115
+ console.error(`\n✗ Failed to ${repush ? 're-push' : 'create'} tag:`, error.message);
116
+ process.exit(1);
117
+ }
118
+ }
119
+
120
+ main();