-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.js
More file actions
95 lines (78 loc) Β· 3.16 KB
/
Copy pathrelease.js
File metadata and controls
95 lines (78 loc) Β· 3.16 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
#!/usr/bin/env node
import { execSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
function main() {
const args = process.argv.slice(2);
if (args.length === 0) {
console.error('β Please provide a version number');
console.log('Usage: bun run release <version>');
console.log('Example: bun run release 1.2.1');
process.exit(1);
}
const version = args[0];
// Validate version format (basic semver check)
if (!/^\d+\.\d+\.\d+(-\w+)?$/.test(version)) {
console.error('β Invalid version format. Use semantic versioning (e.g., 1.2.1)');
process.exit(1);
}
console.log(`π Releasing leshi-ui version ${version}...`);
console.log('');
try {
// Update CLI package.json version
const cliPackageJsonPath = join(__dirname, 'cli', 'package.json');
const cliPackageJson = JSON.parse(readFileSync(cliPackageJsonPath, 'utf-8'));
cliPackageJson.version = version;
writeFileSync(cliPackageJsonPath, JSON.stringify(cliPackageJson, null, 2) + '\n');
console.log('β
Updated CLI package.json version');
// Build the CLI
console.log('π¨ Building CLI...');
execSync('bun run build', { cwd: join(__dirname, 'cli'), stdio: 'inherit' });
console.log('β
CLI build completed');
// Run tests
console.log('π§ͺ Running tests...');
try {
execSync('bun test', { cwd: join(__dirname, 'cli'), stdio: 'inherit' });
console.log('β
All tests passed');
} catch (error) {
console.log('β οΈ Tests not configured yet, skipping...');
}
// Run linting
console.log('π Running linter...');
try {
execSync('bun run lint', { cwd: join(__dirname, 'cli'), stdio: 'inherit' });
console.log('β
Linting passed');
} catch (error) {
console.log('β οΈ Linting issues found, but continuing...');
}
// Commit version bump
console.log('π Committing version bump...');
execSync(`git add cli/package.json`, { stdio: 'inherit' });
execSync(`git commit -m "chore: bump version to ${version}"`, { stdio: 'inherit' });
console.log('β
Version bump committed');
// Create git tag BEFORE publishing
console.log('π·οΈ Creating git tag...');
execSync(`git tag v${version}`, { stdio: 'inherit' });
execSync(`git push origin main`, { stdio: 'inherit' });
execSync(`git push origin v${version}`, { stdio: 'inherit' });
console.log('β
Git tag created and pushed');
// Publish to npm (after tag is created)
console.log('π¦ Publishing to npm...');
execSync('npm publish', {
cwd: join(__dirname, 'cli'),
stdio: 'inherit',
env: { ...process.env, NODE_ENV: 'production' }
});
console.log('β
Successfully published to npm');
console.log('');
console.log('π Release completed successfully!');
console.log(`π¦ leshi-ui@${version} is now available on npm`);
console.log(`π Install with: npx leshi-ui@latest`);
} catch (error) {
console.error('β Release failed:', error.message);
process.exit(1);
}
}
main();