|
1 | | -// generate-icons.ts |
2 | | -import *asfs from "fs" |
3 | | -import *aspath from "path" |
4 | | -import { toPascalCase,extractSvgContent,camelizeSvgAttributes,generateComponent} from "./src/shared" |
| 1 | +import{generateAngularIcons}from"./src/generators/angular" |
| 2 | +import {generateReactIcons} from "./src/generators/react" |
| 3 | +import {generateSvelteIcons} from "./src/generators/svelte" |
| 4 | +import { generateVueIcons} from "./src/generators/vue" |
5 | 5 |
|
6 | 6 | const SVG_DIR = "src/icons-svg" |
7 | | -const OUTPUT_DIR = "dist/components/icons" |
8 | | - |
9 | | - |
10 | | -function main() { |
11 | | - if (!fs.existsSync(OUTPUT_DIR)) fs.mkdirSync(OUTPUT_DIR, { recursive: true }) |
12 | | - |
13 | | - const withSvgSource = path.resolve("src/shared/hoc/withSvg.tsx") |
14 | | - const withSvgTarget = path.resolve("dist/components/icons/withSvg.tsx") |
15 | | - |
16 | | - if (!fs.existsSync(withSvgTarget)) { |
17 | | - fs.copyFileSync(withSvgSource, withSvgTarget) |
18 | | - } |
19 | | - const files = fs.readdirSync(SVG_DIR).filter((f) => f.endsWith(".svg")) |
20 | | - const exports: string[] = [] |
21 | | - |
22 | | - for (const file of files) { |
23 | | - const baseName = path.basename(file) |
24 | | - const componentName = toPascalCase(baseName) |
25 | | - const svgRaw = fs.readFileSync(path.join(SVG_DIR, file), "utf-8") |
26 | | - const svgInner = camelizeSvgAttributes(extractSvgContent(svgRaw)) |
27 | | - |
28 | | - const componentCode = generateComponent(componentName, svgInner) |
29 | | - const outPath = path.join(OUTPUT_DIR, `${componentName}.tsx`) |
30 | | - fs.writeFileSync(outPath, componentCode) |
31 | | - exports.push(`export { ${componentName} } from "./${componentName}"`) |
32 | | - } |
33 | | - |
34 | | - fs.writeFileSync(path.join(OUTPUT_DIR, "index.ts"), exports.join("\n") + "\n") |
35 | | - console.log("β
Icons generated!") |
| 7 | +const REACT_ICONS_DIR = "dist/icons/react" |
| 8 | +const VUE_ICONS_DIR = "dist/icons/vue" |
| 9 | +const SVELTE_ICONS_DIR = "dist/icons/svelte" |
| 10 | +const ANGULAR_ICONS_DIR = "dist/icons/angular" |
| 11 | + |
| 12 | +const framework = process.argv[2] |
| 13 | + |
| 14 | +switch (framework) { |
| 15 | + case "react": |
| 16 | + generateReactIcons(SVG_DIR, REACT_ICONS_DIR) |
| 17 | + break |
| 18 | + case "vue": |
| 19 | + generateVueIcons(SVG_DIR, VUE_ICONS_DIR) |
| 20 | + break |
| 21 | + case "svelte": |
| 22 | + generateSvelteIcons(SVG_DIR, SVELTE_ICONS_DIR) |
| 23 | + break |
| 24 | + case "angular": |
| 25 | + generateAngularIcons(SVG_DIR, ANGULAR_ICONS_DIR) |
| 26 | + break |
| 27 | + default: |
| 28 | + console.log("β Please specify a framework: react | vue | svelte | angular") |
36 | 29 | } |
37 | | - |
38 | | -main() |
0 commit comments