-
Notifications
You must be signed in to change notification settings - Fork 7
/
release.js
48 lines (40 loc) · 1.64 KB
/
release.js
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
import fs from 'fs';
import { execSync } from 'child_process';
const newVersion = process.argv[2];
if (!newVersion) {
console.error('Please provide a new version.');
process.exit(1);
}
const updatePackageJson = (filePath) => {
const packageJson = JSON.parse(fs.readFileSync(filePath, 'utf8'));
packageJson.version = newVersion;
fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2) + '\n');
console.log(`Updated version in ${filePath}`);
};
const updateMainJs = (filePath) => {
let content = fs.readFileSync(filePath, 'utf8');
content = content.replace(/const DEV = true;/, 'const DEV = false;');
content = content.replace(/const DEBUG = true;/, 'const DEBUG = false;');
fs.writeFileSync(filePath, content);
console.log(`Updated DEV and DEBUG in ${filePath}`);
};
try {
updatePackageJson('package.json');
updatePackageJson('frontend/package.json');
updateMainJs('main.js');
execSync('git add package.json frontend/package.json main.js');
// Check if there are changes to commit
const changes = execSync('git diff-index --cached HEAD').toString().trim();
if (changes) {
execSync(`git commit -m "Release v${newVersion}"`, { stdio: 'inherit' });
} else {
console.log('No changes to commit.');
}
execSync('git push', { stdio: 'inherit' });
execSync(`git tag -a v${newVersion} -m "Release v${newVersion}"`, { stdio: 'inherit' });
execSync(`git push origin v${newVersion}`, { stdio: 'inherit' });
console.log('Release process completed successfully.');
} catch (error) {
console.error('Error during release process:', error);
process.exit(1);
}