|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | +const readline = require('readline'); |
| 4 | + |
| 5 | +const packagesDir = path.join(__dirname, '../packages'); |
| 6 | +const externalDirs = ['../agent', '../client', '../docs']; |
| 7 | +const lernaPath = path.join(__dirname, '../lerna.json'); |
| 8 | + |
| 9 | +// Prompt for version input |
| 10 | +const rl = readline.createInterface({ |
| 11 | + input: process.stdin, |
| 12 | + output: process.stdout |
| 13 | +}); |
| 14 | + |
| 15 | +function askVersion() { |
| 16 | + return new Promise((resolve) => { |
| 17 | + rl.question('Enter the new version: ', (version) => { |
| 18 | + resolve(version); |
| 19 | + rl.close(); |
| 20 | + }); |
| 21 | + }); |
| 22 | +} |
| 23 | + |
| 24 | +// Update versions in all package.json files |
| 25 | +async function updateVersions() { |
| 26 | + const NEW_VERSION = await askVersion(); |
| 27 | + |
| 28 | + const updateDirectory = (dirPath) => { |
| 29 | + const packagePath = path.join(dirPath, 'package.json'); |
| 30 | + |
| 31 | + if (fs.existsSync(packagePath)) { |
| 32 | + const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8')); |
| 33 | + const oldVersion = packageJson.version; |
| 34 | + |
| 35 | + if (oldVersion) { |
| 36 | + packageJson.version = NEW_VERSION; |
| 37 | + fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + '\n'); |
| 38 | + console.log(`Updated ${dirPath}: ${oldVersion} -> ${packageJson.version}`); |
| 39 | + } else { |
| 40 | + console.warn(`Version not found in ${dirPath}/package.json`); |
| 41 | + } |
| 42 | + } else { |
| 43 | + console.warn(`No package.json found in ${dirPath}`); |
| 44 | + } |
| 45 | + }; |
| 46 | + |
| 47 | + // Update packages folder |
| 48 | + if (fs.existsSync(packagesDir)) { |
| 49 | + const packageDirs = fs.readdirSync(packagesDir); |
| 50 | + packageDirs.forEach((dir) => updateDirectory(path.join(packagesDir, dir))); |
| 51 | + } else { |
| 52 | + console.warn(`Packages directory not found at ${packagesDir}`); |
| 53 | + } |
| 54 | + |
| 55 | + // Update external folders |
| 56 | + externalDirs.forEach((dir) => { |
| 57 | + const fullPath = path.join(__dirname, dir); |
| 58 | + if (fs.existsSync(fullPath)) { |
| 59 | + updateDirectory(fullPath); |
| 60 | + } else { |
| 61 | + console.warn(`External directory not found: ${fullPath}`); |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + // Update lerna.json |
| 66 | + if (fs.existsSync(lernaPath)) { |
| 67 | + const lernaJson = JSON.parse(fs.readFileSync(lernaPath, 'utf-8')); |
| 68 | + const oldVersion = lernaJson.version; |
| 69 | + |
| 70 | + if (oldVersion) { |
| 71 | + lernaJson.version = NEW_VERSION; |
| 72 | + fs.writeFileSync(lernaPath, JSON.stringify(lernaJson, null, 2) + '\n'); |
| 73 | + console.log(`Updated lerna.json: ${oldVersion} -> ${lernaJson.version}`); |
| 74 | + } else { |
| 75 | + console.warn(`Version not found in lerna.json`); |
| 76 | + } |
| 77 | + } else { |
| 78 | + console.warn(`lerna.json not found at ${lernaPath}`); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +updateVersions(); |
0 commit comments