Skip to content

Commit afbe2bd

Browse files
committed
release script
1 parent c8de3af commit afbe2bd

2 files changed

Lines changed: 100 additions & 1 deletion

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"dev": "tsc --watch",
1717
"prepublishOnly": "npm run build && npm test",
1818
"queue:worker": "node dist/cli/worker.js",
19-
"queue:worker:isolate": "node dist/cli/worker.js --isolate"
19+
"queue:worker:isolate": "node dist/cli/worker.js --isolate",
20+
"release": "node scripts/release.ts"
2021
},
2122
"keywords": [
2223
"queue",

scripts/release.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env node
2+
3+
import { execSync } from 'child_process';
4+
import { readFileSync } from 'fs';
5+
import { join } from 'path';
6+
7+
const VALID_VERSIONS = ['patch', 'minor', 'major', 'keep'];
8+
9+
function run(command: string): string {
10+
console.log(`\n> ${command}`);
11+
return execSync(command, { encoding: 'utf8', stdio: 'inherit' }) as unknown as string;
12+
}
13+
14+
function getVersion(): string {
15+
const packageJson = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8'));
16+
return packageJson.version;
17+
}
18+
19+
async function main() {
20+
const versionType = process.argv[2];
21+
22+
if (!versionType || !VALID_VERSIONS.includes(versionType)) {
23+
console.error(`\nUsage: pnpm release <version>\n`);
24+
console.error(`Where <version> is one of: ${VALID_VERSIONS.join(', ')}\n`);
25+
console.error('Examples:');
26+
console.error(' pnpm release patch # 0.0.1 -> 0.0.2');
27+
console.error(' pnpm release minor # 0.0.1 -> 0.1.0');
28+
console.error(' pnpm release major # 0.0.1 -> 1.0.0');
29+
console.error(' pnpm release keep # Keep current version\n');
30+
process.exit(1);
31+
}
32+
33+
console.log('🚀 Starting release process...\n');
34+
35+
// 1. Check git status
36+
console.log('📋 Checking git status...');
37+
try {
38+
execSync('git diff-index --quiet HEAD --', { stdio: 'pipe' });
39+
} catch {
40+
console.error('\n❌ Error: You have uncommitted changes. Please commit or stash them first.\n');
41+
process.exit(1);
42+
}
43+
44+
// 2. Pull latest changes
45+
console.log('📥 Pulling latest changes...');
46+
run('git pull');
47+
48+
// 3. Install dependencies
49+
console.log('\n📦 Installing dependencies...');
50+
run('pnpm install');
51+
52+
// 4. Run build
53+
console.log('\n🔨 Building project...');
54+
run('pnpm run build');
55+
56+
// 5. Run tests
57+
console.log('\n🧪 Running tests...');
58+
run('pnpm test');
59+
60+
// 6. Bump version (if not "keep")
61+
const oldVersion = getVersion();
62+
let newVersion = oldVersion;
63+
64+
if (versionType === 'keep') {
65+
console.log(`\n📝 Keeping version at ${oldVersion}`);
66+
} else {
67+
console.log(`\n📝 Bumping version from ${oldVersion}...`);
68+
run(`npm version ${versionType} --no-git-tag-version`);
69+
newVersion = getVersion();
70+
console.log(` Version bumped to ${newVersion}`);
71+
}
72+
73+
// 7. Create git commit and tag
74+
console.log('\n📌 Creating git commit and tag...');
75+
if (versionType !== 'keep') {
76+
run('git add package.json');
77+
run(`git commit -m "chore: release v${newVersion}"`);
78+
}
79+
run(`git tag v${newVersion}`);
80+
81+
// 8. Push changes
82+
console.log('\n📤 Pushing changes to remote...');
83+
run('git push');
84+
run('git push --tags');
85+
86+
// 9. Show publish command
87+
console.log('\n✅ Release preparation complete!\n');
88+
console.log(`📦 Version ${newVersion} is ready to publish.\n`);
89+
console.log('To publish to npm, run:');
90+
console.log(`\n pnpm publish\n`);
91+
console.log('Or if this is the first publish:');
92+
console.log(`\n pnpm publish --access public\n`);
93+
}
94+
95+
main().catch((error) => {
96+
console.error('\n❌ Release failed:', error.message);
97+
process.exit(1);
98+
});

0 commit comments

Comments
 (0)