config2ts 2.5.2 → 2.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -7
- package/lib/config2ts.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,9 +41,9 @@ Scan assets directory and generate an `assets.ts` index file with nested resourc
|
|
|
41
41
|
|
|
42
42
|
- `-a, --assets <path>` set assets resource directory. default: `public`
|
|
43
43
|
- Output file: `assets.ts` (alongside the merged config file)
|
|
44
|
-
-
|
|
44
|
+
- File and directory names are used exactly as-is (e.g., `Direction.png` → `Direction`, `adjust-horizontal.png` → `'adjust-horizontal'`); keys with special characters are automatically quoted
|
|
45
45
|
- `type` field uses file extension (lowercase), e.g. `'png'`, `'mp3'`, `'svg'`
|
|
46
|
-
- Directories containing 2+ files of the same extension get a dedicated type (e.g. `PngAsset`, `Mp3Asset`) and `
|
|
46
|
+
- Directories containing 2+ files of the same extension get a dedicated type (e.g. `PngAsset`, `Mp3Asset`) and `satisfies Record<string, XxxAsset>` annotation
|
|
47
47
|
- Directories with ≤1 file or mixed extensions do not get a type annotation
|
|
48
48
|
- Nested directories are supported (e.g. `public/sub/image/`)
|
|
49
49
|
|
|
@@ -59,14 +59,14 @@ export type SvgAsset = { path: string; type: 'svg' };
|
|
|
59
59
|
export const ASSETS = {
|
|
60
60
|
public: {
|
|
61
61
|
image: {
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
'adjust-horizontal': {path:'public/image/adjust-horizontal.png',type:'png'},
|
|
63
|
+
Direction: {path:'public/image/Direction.png',type:'png'}
|
|
64
64
|
} satisfies Record<string, PngAsset>,
|
|
65
65
|
music: {
|
|
66
66
|
effect1: {path:'public/music/effect1.mp3',type:'mp3'},
|
|
67
67
|
effect2: {path:'public/music/effect2.mp3',type:'mp3'}
|
|
68
68
|
} satisfies Record<string, Mp3Asset>,
|
|
69
|
-
|
|
69
|
+
'single-file': {
|
|
70
70
|
effect1: {path:'public/single-file/effect1.mp3',type:'mp3'}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -78,9 +78,12 @@ export const ASSETS = {
|
|
|
78
78
|
```typescript
|
|
79
79
|
import { ASSETS } from "./assets";
|
|
80
80
|
|
|
81
|
-
const meta = ASSETS.public.image.
|
|
82
|
-
// meta.path → 'public/image/
|
|
81
|
+
const meta = ASSETS.public.image.Direction;
|
|
82
|
+
// meta.path → 'public/image/Direction.png'
|
|
83
83
|
// meta.type → 'png'
|
|
84
|
+
|
|
85
|
+
const adjustMeta = ASSETS.public.image['adjust-horizontal'];
|
|
86
|
+
// adjustMeta.path → 'public/image/adjust-horizontal.png'
|
|
84
87
|
```
|
|
85
88
|
|
|
86
89
|
## Options
|
package/lib/config2ts.js
CHANGED
|
@@ -342,7 +342,7 @@ function scanDir(dir, basePath) {
|
|
|
342
342
|
for (const entry of entries) {
|
|
343
343
|
const fullPath = path.join(dir, entry.name);
|
|
344
344
|
if (entry.isDirectory()) {
|
|
345
|
-
const key =
|
|
345
|
+
const key = entry.name;
|
|
346
346
|
const childNode = scanDir(fullPath, path.posix.join(basePath, entry.name));
|
|
347
347
|
if (childNode !== null) {
|
|
348
348
|
node[key] = childNode;
|
|
@@ -352,7 +352,7 @@ function scanDir(dir, basePath) {
|
|
|
352
352
|
else if (entry.isFile()) {
|
|
353
353
|
const parsed = path.parse(entry.name);
|
|
354
354
|
const ext = parsed.ext.slice(1).toLowerCase();
|
|
355
|
-
const key =
|
|
355
|
+
const key = parsed.name;
|
|
356
356
|
const relPath = path.posix.join(basePath, entry.name);
|
|
357
357
|
node[key] = { path: relPath, type: ext };
|
|
358
358
|
hasContent = true;
|