forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-versions.js
82 lines (70 loc) · 2.42 KB
/
update-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
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
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const packagesDir = path.join(__dirname, '../packages');
const externalDirs = ['../agent', '../client', '../docs'];
const lernaPath = path.join(__dirname, '../lerna.json');
// Prompt for version input
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function askVersion() {
return new Promise((resolve) => {
rl.question('Enter the new version: ', (version) => {
resolve(version);
rl.close();
});
});
}
// Update versions in all package.json files
async function updateVersions() {
const NEW_VERSION = await askVersion();
const updateDirectory = (dirPath) => {
const packagePath = path.join(dirPath, 'package.json');
if (fs.existsSync(packagePath)) {
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
const oldVersion = packageJson.version;
if (oldVersion) {
packageJson.version = NEW_VERSION;
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + '\n');
console.log(`Updated ${dirPath}: ${oldVersion} -> ${packageJson.version}`);
} else {
console.warn(`Version not found in ${dirPath}/package.json`);
}
} else {
console.warn(`No package.json found in ${dirPath}`);
}
};
// Update packages folder
if (fs.existsSync(packagesDir)) {
const packageDirs = fs.readdirSync(packagesDir);
packageDirs.forEach((dir) => updateDirectory(path.join(packagesDir, dir)));
} else {
console.warn(`Packages directory not found at ${packagesDir}`);
}
// Update external folders
externalDirs.forEach((dir) => {
const fullPath = path.join(__dirname, dir);
if (fs.existsSync(fullPath)) {
updateDirectory(fullPath);
} else {
console.warn(`External directory not found: ${fullPath}`);
}
});
// Update lerna.json
if (fs.existsSync(lernaPath)) {
const lernaJson = JSON.parse(fs.readFileSync(lernaPath, 'utf-8'));
const oldVersion = lernaJson.version;
if (oldVersion) {
lernaJson.version = NEW_VERSION;
fs.writeFileSync(lernaPath, JSON.stringify(lernaJson, null, 2) + '\n');
console.log(`Updated lerna.json: ${oldVersion} -> ${lernaJson.version}`);
} else {
console.warn(`Version not found in lerna.json`);
}
} else {
console.warn(`lerna.json not found at ${lernaPath}`);
}
}
updateVersions();