-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.lintstagedrc.js
37 lines (35 loc) · 1015 Bytes
/
.lintstagedrc.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
module.exports = (files) => {
const fs = require("fs");
const sep = require("path").sep;
const exec = require("child_process").exec;
const root = __dirname.replace(new RegExp("\\" + sep, "g"), "/");
const dirs = files.reduce((acc, value) => {
const segs = value.replace(root + "/", "").split("/");
while (segs.pop()) {
const path = segs.join("/");
if (path && !acc.includes(path)) {
acc.push(path);
}
}
return acc;
}, []);
const project_dirs = dirs.filter((path) =>
fs.existsSync(root + "/" + path + "/package.json"),
);
project_dirs.forEach((dir) => {
const cmd =
dir
.split("/")
.map((folder) => `cd ${folder} && `)
.join("") + "npm install && npm run lint && npm run test";
console.log("=============================");
console.log(cmd);
console.log("=============================");
exec(cmd, (error) => {
if (error) {
throw new Error(error);
}
});
});
return [];
};