config2ts 2.5.0 → 2.5.2
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 +5 -5
- package/lib/config2ts.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,16 +56,16 @@ export type Mp3Asset = { path: string; type: 'mp3' };
|
|
|
56
56
|
export type PngAsset = { path: string; type: 'png' };
|
|
57
57
|
export type SvgAsset = { path: string; type: 'svg' };
|
|
58
58
|
|
|
59
|
-
export const
|
|
59
|
+
export const ASSETS = {
|
|
60
60
|
public: {
|
|
61
61
|
image: {
|
|
62
62
|
adjustHorizontal: {path:'public/image/adjust-horizontal.png',type:'png'},
|
|
63
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
|
singleFile: {
|
|
70
70
|
effect1: {path:'public/single-file/effect1.mp3',type:'mp3'}
|
|
71
71
|
}
|
|
@@ -76,9 +76,9 @@ export const RES = {
|
|
|
76
76
|
### usage
|
|
77
77
|
|
|
78
78
|
```typescript
|
|
79
|
-
import {
|
|
79
|
+
import { ASSETS } from "./assets";
|
|
80
80
|
|
|
81
|
-
const meta =
|
|
81
|
+
const meta = ASSETS.public.image.adjustHorizontal;
|
|
82
82
|
// meta.path → 'public/image/adjust-horizontal.png'
|
|
83
83
|
// meta.type → 'png'
|
|
84
84
|
```
|
package/lib/config2ts.js
CHANGED
|
@@ -411,7 +411,7 @@ function serializeAssetNode(node, indent, uniformDirs, extTypeMap) {
|
|
|
411
411
|
}
|
|
412
412
|
else {
|
|
413
413
|
const childUt = uniformDirs.get(value);
|
|
414
|
-
const typeAnnotation = childUt ? `
|
|
414
|
+
const typeAnnotation = childUt ? ` satisfies Record<string, ${extTypeMap.get(childUt)}>` : "";
|
|
415
415
|
lines.push(`${indent}${serializedKey}: {`);
|
|
416
416
|
lines.push(serializeAssetNode(value, indent + " ", uniformDirs, extTypeMap));
|
|
417
417
|
lines.push(`${indent}}${typeAnnotation}${comma}`);
|
|
@@ -443,11 +443,11 @@ function assets2ts(assetsDir) {
|
|
|
443
443
|
}
|
|
444
444
|
if (sortedExts.length > 0)
|
|
445
445
|
template += "\n";
|
|
446
|
-
template += `export const
|
|
446
|
+
template += `export const ASSETS = {\n`;
|
|
447
447
|
const rootUt = uniformDirs.get(root);
|
|
448
448
|
template += ` ${dirName}: {\n`;
|
|
449
449
|
template += serializeAssetNode(root, " ", uniformDirs, extTypeMap);
|
|
450
|
-
const rootAnnotation = rootUt ? `
|
|
450
|
+
const rootAnnotation = rootUt ? ` satisfies Record<string, ${extTypeMap.get(rootUt)}>` : "";
|
|
451
451
|
template += `\n }${rootAnnotation}\n`;
|
|
452
452
|
template += `};\n`;
|
|
453
453
|
return template;
|