Repository navigation
Expand file tree
/
Copy pathupdate-dependencies.js
More file actions
85 lines (75 loc) · 2.41 KB
/
Copy pathupdate-dependencies.js
File metadata and controls
85 lines (75 loc) · 2.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { exec } from "node:child_process";
import { promisify } from "node:util";
import { readFileSync } from "node:fs";
const execPromise = promisify(exec);
async function execCommand(command) {
const startTime = Date.now();
const { stdout, stderr } = await execPromise(command);
process.stdout.write(
`Completed in ${Date.now() - startTime} ms: \x1b[32m${command}\x1b[0m`
);
if (stderr) {
process.stdout.write(stdout);
process.stderr.write(stderr);
}
}
function readJsonFile(path) {
const content = readFileSync(path, "utf-8");
return JSON.parse(content);
}
const FILENAME_PERMISSION = "./packages/permission/package.json";
const FILENAME_COMMON = "./packages/common/package.json";
const FILENAME_API = "./packages/api/package.json";
const FILENAME_ZKDB = "./packages/zkdb/package.json";
const FILENAME_STORAGE = "./packages/storage/package.json";
const FILENAME_SMART_CONTRACT = "./packages/smart-contract/package.json";
const allFile = [
FILENAME_PERMISSION,
FILENAME_COMMON,
FILENAME_API,
FILENAME_ZKDB,
FILENAME_STORAGE,
FILENAME_SMART_CONTRACT,
];
const packageMap = new Map();
for (let i = 0; i < allFile.length; i += 1) {
const jsonFile = readJsonFile(allFile[i]);
packageMap.set(jsonFile.name, {
name: jsonFile.name,
version: jsonFile.version,
dependencies: Object.entries(
jsonFile.dependencies ? jsonFile.dependencies : {}
),
});
}
async function main() {
allFile.push("./packages/serverless/package.json");
allFile.push("./packages/mina-service/package.json");
for (let i = 0; i < allFile.length; i += 1) {
const jsonFile = readJsonFile(allFile[i]);
const dependencies = Object.entries(
jsonFile.dependencies ? jsonFile.dependencies : {}
);
const listPackage = [];
for (let j = 0; j < dependencies.length; j += 1) {
const [name] = dependencies[j];
if (packageMap.has(name)) {
const newPackage = packageMap.get(name);
listPackage.push(`${newPackage.name}@${newPackage.version}`);
}
}
if (listPackage.length > 0) {
const command = `yarn workspace ${jsonFile.name} add ${listPackage.join(" ")}\n`;
process.stdout.write(`Execute: \x1b[33m${command}\x1b[0m`);
// eslint-disable-next-line no-await-in-loop
await execCommand(command);
}
}
}
main()
.then(() => {
process.stdout.write("Finished!\n");
})
.catch((e) => {
process.stderr.write("Error:", e.message);
});