-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdate-shared-types.js
42 lines (38 loc) · 1.02 KB
/
update-shared-types.js
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
const { exec } = require("child_process");
const fs = require("fs");
const path = require("path");
const directories = fs
.readdirSync(".", { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
const updatePackage = (dir) => {
return new Promise((resolve, reject) => {
exec(
"npm uninstall peerprep-shared-types && npm install peerprep-shared-types",
{ cwd: dir },
(error, stdout, stderr) => {
if (error) {
console.error(`Error in ${dir}: ${error}`);
reject(error);
return;
}
console.log(`Updated peerprep-shared-types in ${dir}`);
resolve();
}
);
});
};
const updateAll = async () => {
for (const dir of directories) {
if (fs.existsSync(path.join(dir, "package.json"))) {
try {
if (dir !== "peerprep-shared-types") {
await updatePackage(dir);
}
} catch (error) {
console.error(`Failed to update ${dir}`);
}
}
}
};
updateAll();