-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-version.mjs
31 lines (25 loc) · 1.05 KB
/
update-version.mjs
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
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Read the main package.json file
const mainPackageJsonPath = path.join(__dirname, "package.json");
const mainPackageJson = JSON.parse(
fs.readFileSync(mainPackageJsonPath, "utf8"),
);
// Get the version from the main package.json
const mainVersion = mainPackageJson.version;
// Get all package.json files in the packages directory
const packagesDir = path.join(__dirname, "packages");
const packageJsonFiles = fs
.readdirSync(packagesDir)
.map((file) => path.join(packagesDir, file, "package.json"))
.filter((file) => fs.existsSync(file));
// Update the version in each package.json
packageJsonFiles.forEach((packageJsonPath) => {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
packageJson.version = mainVersion;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
});
console.log(`Version ${mainVersion} sync completed.`);