forked from wormhole-foundation/wormhole-sdk-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncVersion.ts
More file actions
42 lines (35 loc) · 1.41 KB
/
Copy pathsyncVersion.ts
File metadata and controls
42 lines (35 loc) · 1.41 KB
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
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 updateVersionsInWorkspaces(version: string) {
updateVersionInPackageJson(__dirname, version);
const rootPackageJsonPath = path.join(__dirname, "package.json");
const rootPackageJson = require(rootPackageJsonPath);
rootPackageJson.workspaces.forEach((workspaceDir: string) => {
const workspacePackageDir = path.join(__dirname, workspaceDir);
updateVersionInPackageJson(workspacePackageDir, version);
});
}
function getVersion(): string {
const versionFilePath = path.join(__dirname, "VERSION");
const v = fs.readFileSync(versionFilePath);
return v.toString().replace('\n', '');
}
updateVersionsInWorkspaces(getVersion());