-
Notifications
You must be signed in to change notification settings - Fork 26
/
update-package-versions.js
51 lines (42 loc) · 1.47 KB
/
update-package-versions.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
49
50
51
const fs = require('fs');
const path = require('path');
// Get the new version from command line arguments
const newVersion = process.argv[2];
if (!newVersion) {
console.error('No version provided');
process.exit(1);
}
// List of package.json files to update
const packagePaths = [
'packages/toolkit/package.json',
'packages/apps/package.json',
'package.json',
];
// Update each package.json
packagePaths.forEach((packagePath) => {
const fullPath = path.join(__dirname, '..', packagePath);
try {
// Read the package.json
const packageJson = JSON.parse(fs.readFileSync(fullPath, 'utf8'));
// Update the version
packageJson.version = newVersion;
// If this is the root package.json, update the dependencies
// This is a hack to get the @lecca-io packages to always be the same version as the root package
if (packagePath === 'package.json') {
if (packageJson.dependencies) {
if (packageJson.dependencies['@lecca-io/toolkit']) {
packageJson.dependencies['@lecca-io/toolkit'] = newVersion;
}
if (packageJson.dependencies['@lecca-io/apps']) {
packageJson.dependencies['@lecca-io/apps'] = newVersion;
}
}
}
// Write back to file
fs.writeFileSync(fullPath, JSON.stringify(packageJson, null, 2) + '\n');
console.info(`Updated ${packagePath} to version ${newVersion}`);
} catch (error) {
console.error(`Error updating ${packagePath}:`, error);
process.exit(1);
}
});