-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
37 lines (34 loc) · 1.15 KB
/
utils.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
import path from "path";
import * as fs from "fs/promises";
export async function getDirectories(path) {
return fs
.readdir(path, { withFileTypes: true })
.then((dirents) =>
dirents.filter((d) => d.isDirectory()).map((d) => d.name)
);
}
export async function updatePackageJSON(folderPath, examples, version) {
for (const example of examples) {
const packageJSONPath = path.join(folderPath, example, "package.json");
try {
const packageJSONData = await fs.readFile(packageJSONPath, "utf-8");
const packageJSON = JSON.parse(packageJSONData);
if (packageJSON.dependencies && packageJSON.dependencies["@blocto/sdk"]) {
packageJSON.dependencies["@blocto/sdk"] = version;
await fs.writeFile(
packageJSONPath,
JSON.stringify(packageJSON, null, 2)
);
console.log(
`✅ Updated @blocto/sdk version for ${example} to ${version} 🎉`
);
} else {
console.log(`❌ No @blocto/sdk dependency found in ${example}`);
}
} catch (err) {
console.error(
`Error updating @blocto/sdk version for ${example}: ${err}`
);
}
}
}