|
1 |
| -import { createProgressLog } from "./../util/cli"; |
| 1 | +import { createProgressLog, ProgressLog } from "./../util/cli"; |
2 | 2 | import { readOptions } from "./../util/prettier";
|
3 | 3 | import { packagesPath } from "./../util/workspace";
|
| 4 | +import { writeIndexFile } from "./genIconsMaterialSource"; |
4 | 5 | import { readdir, writeFile } from "fs/promises";
|
5 | 6 | import pLimit from "p-limit";
|
6 | 7 | import { join } from "path";
|
7 | 8 | import { format } from "prettier";
|
8 | 9 |
|
9 | 10 | const outPath = join(packagesPath, "icons-material/lib");
|
10 | 11 |
|
11 |
| -async function genIconsMaterialTyping() { |
12 |
| - const { name } = genIconsMaterialTyping; |
| 12 | +async function writeIndexTypingFile( |
| 13 | + iconNames: string[], |
| 14 | + progressLog: ProgressLog |
| 15 | +) { |
| 16 | + const contents = [ |
| 17 | + `import SvgIcon from "@suid/material/SvgIcon";`, |
| 18 | + `type C = typeof SvgIcon;`, |
| 19 | + ...iconNames.map((v) => `export const ${v}: C;`), |
| 20 | + ].join("\n"); |
| 21 | + progressLog.add(); |
| 22 | + await writeFile(join(outPath, "index.d.ts"), contents); |
| 23 | +} |
13 | 24 |
|
14 |
| - const fileNames = (await readdir(outPath)).filter((v) => v.endsWith(".jsx")); |
15 |
| - const progressLog = createProgressLog({ |
16 |
| - name, |
17 |
| - total: fileNames.length, |
18 |
| - }); |
| 25 | +async function writeComponentTypingFiles( |
| 26 | + iconNames: string[], |
| 27 | + progressLog: ProgressLog |
| 28 | +) { |
19 | 29 | const contents = format(`export { default } from "@suid/material/SvgIcon"`, {
|
20 | 30 | ...(await readOptions()),
|
21 | 31 | parser: "typescript",
|
22 | 32 | });
|
23 | 33 |
|
24 | 34 | const limit = pLimit(10);
|
25 |
| - const paths = fileNames.map((f) => |
26 |
| - join(outPath, f.replace(/.jsx$/, ".d.ts")) |
27 |
| - ); |
| 35 | + const paths = iconNames.map((v) => join(outPath, `${v}.d.ts`)); |
28 | 36 |
|
29 |
| - const promises = paths.map((path) => |
| 37 | + return paths.map((path) => |
30 | 38 | limit(() => {
|
31 |
| - progressLog.add(); |
| 39 | + progressLog?.add(); |
32 | 40 | return writeFile(path, contents);
|
33 | 41 | })
|
34 | 42 | );
|
| 43 | +} |
| 44 | +async function genIconsMaterialTyping() { |
| 45 | + const { name } = genIconsMaterialTyping; |
| 46 | + |
| 47 | + const iconNames = (await readdir(outPath)) |
| 48 | + .filter((v) => v !== "index.jsx" && v.endsWith(".jsx")) |
| 49 | + .map((v) => v.replace(/.jsx$/, "")); |
| 50 | + |
| 51 | + const progressLog = createProgressLog({ |
| 52 | + name, |
| 53 | + total: iconNames.length + 1, |
| 54 | + }); |
35 | 55 |
|
36 |
| - await Promise.all(promises); |
| 56 | + await Promise.all([ |
| 57 | + ...(await writeComponentTypingFiles(iconNames, progressLog)), |
| 58 | + writeIndexTypingFile(iconNames, progressLog), |
| 59 | + writeIndexFile(iconNames), |
| 60 | + ]); |
37 | 61 | progressLog.stop();
|
38 | 62 | }
|
39 | 63 |
|
|
0 commit comments