-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathsetVersion.ts
46 lines (37 loc) · 1.42 KB
/
setVersion.ts
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
import fs from "fs";
import path from "path";
function updateVersionInPackageJson(dirPath: string, version: string) {
const packageJsonPath = path.join(dirPath, "package.json");
const packageJson = require(packageJsonPath);
packageJson.version = version;
if (packageJson.dependencies)
packageJson.dependencies = Object.fromEntries(
Object.entries(packageJson.dependencies).map((entry) => {
const [k, v] = entry as [string, string];
// Note: this may be wrong if we start importing
// packages outside the workspaces in this repo
if (k.startsWith("@wormhole-foundation")) {
return [k, `${version}`];
}
return [k, v];
}),
);
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
}
function rootDir(): string {
return path.join(__dirname);
}
function updateVersionsInWorkspaces(version: string) {
const dir = rootDir();
updateVersionInPackageJson(dir, version);
const rootPackageJsonPath = path.join(dir, "package.json");
const rootPackageJson = require(rootPackageJsonPath);
rootPackageJson.workspaces.forEach((workspaceDir: string) => {
const workspacePackageDir = path.join(dir, workspaceDir);
updateVersionInPackageJson(workspacePackageDir, version);
});
}
const args = process.argv.slice(2);
const version = args[0];
if (!version) throw new Error('Need to pass in a version arg');
updateVersionsInWorkspaces(version);