-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.js
More file actions
66 lines (59 loc) · 1.81 KB
/
init.js
File metadata and controls
66 lines (59 loc) · 1.81 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
const path = require("path");
const child_process = require("child_process");
const options = {
cwd: "./",
};
child_process.execSync("npm install", options);
const fs = require("fs-extra");
function initBuildConfig() {
if (fs.existsSync("./buildConfig.json")) return;
fs.createFileSync("./buildConfig.json");
const data = {
HASH: {},
PACKAGE: {
checkKeyList: ["dependencies", "devDependencies"],
},
};
const jsonData = JSON.stringify(data, null, 2);
fs.writeFileSync("./buildConfig.json", jsonData, { encoding: "utf8" });
}
initBuildConfig();
const buildConfig = require("./buildConfig.json");
const { PACKAGE } = buildConfig;
async function npmInstall(options) {
const dir = __dirname + "\\";
const cwd = options.cwd;
const cwdKey = cwd.replace(dir, "");
console.log(`${cwdKey}正在更新依赖,请稍等……`);
child_process.execSync("npm install", options);
}
function updateConfigPackage(options) {
const dir = __dirname + "\\";
const cwd = options.cwd;
const cwdKey = cwd.replace(dir, "") || "./";
const checkKeyList = PACKAGE.checkKeyList;
const packagePath = path.join(cwd, "package.json");
const packageJson = require(packagePath);
const configJson = {};
for (const checkKey of checkKeyList) {
const obj = packageJson[checkKey];
configJson[checkKey] = obj;
PACKAGE[cwdKey] = configJson;
buildConfig.PACKAGE = PACKAGE;
const jsonData = JSON.stringify(buildConfig, null, 2);
fs.writeFileSync("./buildConfig.json", jsonData, { encoding: "utf8" });
}
}
async function init() {
const list = ["./popup", "./panel"];
for (const item of list) {
const cdPath = path.join(__dirname, item);
const options = {
cwd: cdPath,
};
await npmInstall(options);
updateConfigPackage(options);
}
console.log("初始化完成");
}
init();