-
Notifications
You must be signed in to change notification settings - Fork 4
/
scripts.js
84 lines (77 loc) · 2.19 KB
/
scripts.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
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
const { execSync } = require("child_process");
const fs = require("fs");
const directories = fs
.readdirSync(".", { withFileTypes: true })
.filter((directory) => directory.isDirectory())
.map((dirent) => dirent.name)
.filter((name) => !name.startsWith("."));
let failed = false;
if (process.argv.includes("lint")) {
consistency();
eslint();
}
function eslint() {
directories.forEach((dir) => {
try {
console.log(`\n\n=== Running "npm run lint" in directory: ${dir} ===`);
execSync("npm run lint", { cwd: dir, stdio: "inherit" });
} catch (error) {
console.error(
`[ERROR]: Error running "npm run lint" in directory: ${dir}`
);
failed = true;
}
});
}
function consistency() {
const reactShadcnDirectories = directories.filter((dir) =>
dir.startsWith("template-react-vite-")
);
const nextShadcnDirectories = directories.filter((dir) =>
dir.startsWith("template-nextjs-")
);
const shouldBeConsistent = [].concat(
[
".eslintrc.cjs",
"src/lib",
"src/components",
".gitignore",
"tailwind.config.js",
"postcss.config.js",
"tsconfig.json",
].map((path) => reactShadcnDirectories.map((dir) => `${dir}/${path}`)),
[
"components",
".eslintrc.cjs",
".gitignore",
"tailwind.config.js",
"postcss.config.js",
"tsconfig.json",
].map((path) => nextShadcnDirectories.map((dir) => `${dir}/${path}`)),
[
[].concat(
reactShadcnDirectories.map((dir) => `${dir}/src/lib`),
nextShadcnDirectories.map((dir) => `${dir}/lib`)
),
[].concat(
reactShadcnDirectories.map((dir) => `${dir}/convex/tsconfig.json`),
nextShadcnDirectories.map((dir) => `${dir}/convex/tsconfig.json`)
),
]
);
shouldBeConsistent.forEach((paths) => {
const first = paths[0];
paths.forEach((path) => {
try {
execSync(`git diff --color=always --no-index ${first} ${path}`, {
encoding: "utf8",
});
} catch (error) {
console.error(`\n[ERROR]: ${first} differs from ${path}\n`);
console.error(error.stdout);
failed = true;
}
});
});
}
process.exit(failed ? 1 : 0);