Skip to content

Commit 2d22cc1

Browse files
committed
feat: add user config file + update npx script
1 parent 3f69697 commit 2d22cc1

File tree

5 files changed

+45
-22
lines changed

5 files changed

+45
-22
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
node_modules/
33
/lucide-static
44
/lucide-react
5-
5+
/dist
66
# package-lock.json
77
package-lock.json
88

svg-sprite/README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,29 @@ npm run build
1111

1212
## Structure
1313

14-
- `scripts/` - Build scripts for generating sprites and wrappers
15-
- `src/lib/` - Core library code
16-
- `src/icons/` - Auto-generated React wrapper components
17-
- `dist/` - Compiled output
14+
```
15+
📂 svg-sprite/
16+
│── 📂 dist
17+
│ └── 📂 icons
18+
│ │ |── Icon.js
19+
│ │ |── Icon.d.ts
20+
│ │ └── ** 1600 more icons **
21+
│ │── config.js
22+
│ │── config.d.ts
23+
│ │── index.d.ts
24+
│ └── index.js
25+
│── 📂 scripts
26+
│ │── build-sprite.js
27+
│ │── gen-dist.js
28+
│ │── gen-wrappers.js
29+
│ │── index.js
30+
│ │── scan-icons.js
31+
│ └── used-icons.js
32+
│── 📂 src
33+
│ │── 📂 icons
34+
│ │ │── Icon.jsx
35+
│ │ └── ** 1600 more icons **
36+
│ └── config.ts
37+
│── README.md
38+
│── package.json
39+
└── tsconfig.json```

svg-sprite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"type-check": "tsc --noEmit | tee type-errors.log"
2020
},
2121
"bin": {
22-
"svg-sprite-gen": "scripts/index.js"
22+
"zero-svg": "scripts/index.js"
2323
},
2424
"peerDependencies": {
2525
"react": ">=17"

svg-sprite/src/config.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1+
// src/config.ts
12
import fs from "fs";
23
import path from "path";
3-
import { createRequire } from "module";
4+
import { pathToFileURL } from "url";
45

5-
// Default config
6-
let config = {
6+
const DEFAULT_CONFIG = {
77
IMPORT_NAME: "@react-zero-ui/svg-sprite",
88
SPRITE_PATH: "/icons.svg",
99
ROOT_DIR: "app",
1010
CUSTOM_SVG_DIR: "custom-icons",
1111
OUTPUT_DIR: "public",
1212
};
1313

14-
// Check for user config (synchronously)
15-
const userConfigPath = path.resolve(process.cwd(), "zero-ui.config.js");
16-
if (fs.existsSync(userConfigPath)) {
14+
let userConfig = {};
15+
const configFile = path.resolve(process.cwd(), "zero-ui.config.js");
16+
17+
if (fs.existsSync(configFile)) {
1718
try {
18-
const require = createRequire(import.meta.url);
19-
delete require.cache[userConfigPath]; // Clear cache for hot reloading
20-
const userConfig = require(userConfigPath);
21-
config = { ...config, ...userConfig };
19+
const mod = await import(pathToFileURL(configFile).href);
20+
userConfig = mod.default ?? mod;
2221
} catch (e) {
2322
// @ts-expect-error
24-
console.warn("⚠️ Failed to load zero-ui.config.js:", e.message);
23+
console.warn("⚠️ Failed to load zero-ui.config.js:", e.message);
2524
}
2625
}
2726

28-
export const IMPORT_NAME = config.IMPORT_NAME;
29-
export const SPRITE_PATH = config.SPRITE_PATH;
30-
export const ROOT_DIR = config.ROOT_DIR;
31-
export const CUSTOM_SVG_DIR = config.CUSTOM_SVG_DIR;
32-
export const OUTPUT_DIR = config.OUTPUT_DIR;
27+
const merged = { ...DEFAULT_CONFIG, ...userConfig };
28+
29+
export const IMPORT_NAME = merged.IMPORT_NAME;
30+
export const SPRITE_PATH = merged.SPRITE_PATH;
31+
export const ROOT_DIR = merged.ROOT_DIR;
32+
export const CUSTOM_SVG_DIR = merged.CUSTOM_SVG_DIR;
33+
export const OUTPUT_DIR = merged.OUTPUT_DIR;

svg-sprite/type-errors.log

Whitespace-only changes.

0 commit comments

Comments
 (0)