forked from wormhole-foundation/wormhole-sdk-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setVersion.ts
68 lines (58 loc) · 2.06 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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];
}),
);
//if (packageJson.exports) {
// packageJson.exports = Object.fromEntries(
// Object.entries(packageJson.exports).map(([path, stuff]) => {
// stuff = {
// "react-native": {
// // @ts-ignore
// import: stuff["import"]["default"],
// // @ts-ignore
// require: stuff["require"]["default"],
// // @ts-ignore
// types: stuff["default"]["types"],
// // @ts-ignore
// default: stuff["default"]["default"],
// },
// // @ts-ignore
// ...stuff,
// };
// return [path, stuff];
// }),
// );
//}
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);