-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeIndex.ts
44 lines (43 loc) · 1.28 KB
/
makeIndex.ts
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
import { writeFileSync } from "fs";
import { glob } from "glob";
import { existsSync, rmSync } from "node:fs";
import path from "path";
const Dirs = [{
dir: "./src/components/",
match: "**/*",
name: "components",
}, {
dir: "./src/assets/",
match: "**/*.vue",
name: "assets",
}, {
dir: "./src/types/",
match: "**/*",
name: "types",
}, {
dir: "./src/utils/",
match: "**/*",
name: "utils",
}];
const SrcRe = /^src/;
const mainIndex: string[] = ["export * as tailwindConfig from \"@/tailwind.config\";", "export * as theme from \"@/theme\";"];
for (const { dir, match, name } of Dirs) {
const output: string[] = [];
if (existsSync(`${dir}/index.ts`)) {
rmSync(`${dir}/index.ts`);
}
const files = glob.sync(`${dir}${match}`);
for (const file of files) {
const extension = path.extname(file);
const componentName = path.basename(file, extension);
if (extension === ".ts") {
output.push(`export * from "${file.replace(SrcRe, "@").replace(/\\/g, "/").replace(extension, "")}";`);
}
else {
output.push(`export { default as ${componentName} } from "${file.replace(SrcRe, "@").replace(/\\/g, "/")}";`);
}
}
writeFileSync(`${dir}/index.ts`, output.join("\n"));
mainIndex.push(`export * as ${name} from "@/${name}/index";`);
}
writeFileSync("src/index.ts", mainIndex.join("\n"));