|
| 1 | +import { execSync } from "child_process"; |
| 2 | +import fs from "fs"; |
| 3 | +import path from "path"; |
| 4 | + |
| 5 | +// Function to update the version in package.json |
| 6 | +function updatePackageVersion(packagePath, versionType) { |
| 7 | + const packageJsonPath = path.join(packagePath, "package.json"); |
| 8 | + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); |
| 9 | + |
| 10 | + // Extract current version |
| 11 | + const currentVersion = packageJson.version; |
| 12 | + console.log(`Current version of ${packageJson.name}: ${currentVersion}`); |
| 13 | + |
| 14 | + // Bump version (simplified logic, you might want to use a library like 'semver' for this) |
| 15 | + const versionParts = currentVersion.split(".").map(Number); |
| 16 | + let newVersion = currentVersion; |
| 17 | + if (versionType === "major") { |
| 18 | + versionParts[0] += 1; |
| 19 | + versionParts[1] = 0; |
| 20 | + versionParts[2] = 0; |
| 21 | + newVersion = versionParts.join("."); |
| 22 | + } else if (versionType === "minor") { |
| 23 | + versionParts[1] += 1; |
| 24 | + versionParts[2] = 0; |
| 25 | + newVersion = versionParts.join("."); |
| 26 | + } else if (versionType === "patch") { |
| 27 | + versionParts[2] += 1; |
| 28 | + newVersion = versionParts.join("."); |
| 29 | + } |
| 30 | + |
| 31 | + packageJson.version = newVersion; |
| 32 | + // Write updated version back to package.json |
| 33 | + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); |
| 34 | + console.log(`Updated version of ${packageJson.name} to: ${newVersion}`); |
| 35 | +} |
| 36 | + |
| 37 | +// Get the version type from command line arguments |
| 38 | +const versionType = process.argv[2]; |
| 39 | + |
| 40 | +// Update versions for each package |
| 41 | +const packages = ["packages/resolver", "packages/agent-starter"]; |
| 42 | + |
| 43 | +packages.forEach((packagePath) => { |
| 44 | + updatePackageVersion(packagePath, versionType); |
| 45 | +}); |
| 46 | + |
| 47 | +execSync(`changeset publish`, { stdio: "inherit" }); |
0 commit comments