-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
Β·52 lines (40 loc) Β· 1.77 KB
/
Copy pathindex.js
File metadata and controls
executable file
Β·52 lines (40 loc) Β· 1.77 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
#!/usr/bin/env node
const fs = require('fs');
const { execSync } = require('child_process');
const path = require('path');
// Get the project root directory
const projectRoot = process.cwd();
const packageJsonPath = path.join(projectRoot, 'package.json');
const versionJsonPath = path.join(projectRoot, 'public', 'version.json');
// Get command-line arguments (patch, minor, major)
const versionType = process.argv[3];
if (!['patch', 'minor', 'major'].includes(versionType)) {
console.error('β Please use: patch, minor, or major');
process.exit(1);
}
try {
// π₯ Step 1: Check if Git has uncommitted changes
const status = execSync('git status --porcelain').toString().trim();
if (status) {
console.error('β Git working directory is not clean. Commit or stash your changes first.');
process.exit(1);
}
// π₯ Step 2: Bump version in package.json
execSync(`npm version ${versionType} --no-git-tag-version`, { stdio: 'inherit' });
// π₯ Step 3: Get the updated version
const { version } = require(packageJsonPath);
// π₯ Step 4: Ensure public directory exists
if (!fs.existsSync(path.dirname(versionJsonPath))) {
fs.mkdirSync(path.dirname(versionJsonPath), { recursive: true });
}
// π₯ Step 5: Update version.json
fs.writeFileSync(versionJsonPath, JSON.stringify({ version }, null, 2));
console.log(`β
version.json updated to version ${version}`);
// π₯ Step 6: Commit and tag the new version
execSync('git add package.json public/version.json', { stdio: 'inherit' });
execSync(`git commit -m "Bump version to ${version}"`, { stdio: 'inherit' });
execSync(`git tag v${version}`, { stdio: 'inherit' });
console.log('π Version updated and committed!');
} catch (error) {
console.error('β Error updating version:', error);
}