|
1
|
import fse from "fs-extra" |
|
2
|
import os from "os" |
|
3
|
import { resolve } from "path" |
|
4
|
import dedent from "ts-dedent" |
|
5
|
|
|
6
|
import { getComponentName } from "@/commands/icons/utils" |
|
7
|
|
|
8
|
const BANNER = |
|
9
|
dedent` |
|
10
|
// This file is generated automatically. |
|
11
|
` + os.EOL |
|
12
|
|
|
13
|
export async function generateIndex(path: string) { |
|
14
|
let index = BANNER |
|
15
|
|
|
16
|
const entries = await fse.readdir(path) |
|
17
|
|
|
18
|
for (const entry of entries) { |
|
19
|
if (entry === "index.ts" || entry === "__tests__") { |
|
20
|
continue |
|
21
|
} |
|
22
|
|
|
23
|
const name = entry.replace(/\.tsx?$/, "") |
|
24
|
const exportName = getComponentName(name) |
|
25
|
|
|
26
|
index += `export { default as ${exportName} } from "./${name}"${os.EOL}` |
|
27
|
} |
|
28
|
|
|
29
|
await fse.writeFile(resolve(path, "index.ts"), index) |
|
30
|
} |