@valfuse-node/assets 0.1.2 → 0.2.0
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 +17 -10
- package/dist/cli/index.js +16 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,12 +37,13 @@ public/assets/
|
|
|
37
37
|
└── icons/search.svg
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
Create `valfuse
|
|
40
|
+
Create `valfuse.yaml` in the project root:
|
|
41
41
|
|
|
42
42
|
```yaml
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
assets:
|
|
44
|
+
input_dir: public/assets
|
|
45
|
+
output_file: src/assets/assets.ts
|
|
46
|
+
base_path: /assets
|
|
46
47
|
```
|
|
47
48
|
|
|
48
49
|
Run `npx valfuse-assets`. It generates `src/assets/assets.ts`:
|
|
@@ -83,13 +84,19 @@ your server or CDN uses to serve that directory.
|
|
|
83
84
|
|
|
84
85
|
## Configuration
|
|
85
86
|
|
|
86
|
-
The CLI reads `valfuse
|
|
87
|
-
|
|
87
|
+
The CLI reads the `assets` section of `valfuse.yaml` from the current
|
|
88
|
+
working directory. The same file can also contain `barrel` and `localization`
|
|
89
|
+
sections for the other Valfuse generators:
|
|
88
90
|
|
|
89
91
|
```yaml
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
assets:
|
|
93
|
+
input_dir: public/media
|
|
94
|
+
output_file: src/assets/assets.ts
|
|
95
|
+
base_path: /media
|
|
96
|
+
|
|
97
|
+
barrel:
|
|
98
|
+
input_dir: src
|
|
99
|
+
output_file: src/index.ts
|
|
93
100
|
```
|
|
94
101
|
|
|
95
102
|
Relative file paths in this config are resolved from the current working
|
|
@@ -112,7 +119,7 @@ The default values are:
|
|
|
112
119
|
Pass another config file with `--config`:
|
|
113
120
|
|
|
114
121
|
```bash
|
|
115
|
-
npx valfuse-assets --config config/valfuse
|
|
122
|
+
npx valfuse-assets --config config/valfuse.yaml
|
|
116
123
|
```
|
|
117
124
|
|
|
118
125
|
Use `--check` in CI to fail when the generated module is missing or stale. It
|
package/dist/cli/index.js
CHANGED
|
@@ -213,7 +213,8 @@ Options:
|
|
|
213
213
|
--check Exit with an error when the generated file is stale
|
|
214
214
|
--help, -h Show this help
|
|
215
215
|
|
|
216
|
-
The default config file is valfuse
|
|
216
|
+
The default config file is valfuse.yaml. Configure these options under
|
|
217
|
+
the "assets" section. Defaults for omitted options:
|
|
217
218
|
input_dir: public/assets
|
|
218
219
|
output_file: src/assets/assets.ts
|
|
219
220
|
base_path: /assets
|
|
@@ -263,7 +264,7 @@ function parseArguments(args) {
|
|
|
263
264
|
return options;
|
|
264
265
|
}
|
|
265
266
|
async function readConfig(cwd, configFile) {
|
|
266
|
-
const filePath = resolve2(cwd, configFile ?? "valfuse
|
|
267
|
+
const filePath = resolve2(cwd, configFile ?? "valfuse.yaml");
|
|
267
268
|
let content;
|
|
268
269
|
try {
|
|
269
270
|
content = await readFile2(filePath, "utf8");
|
|
@@ -285,7 +286,19 @@ async function readConfig(cwd, configFile) {
|
|
|
285
286
|
cause: error
|
|
286
287
|
});
|
|
287
288
|
}
|
|
288
|
-
return parseConfigObject(parsed, filePath);
|
|
289
|
+
return parseConfigObject(readGeneratorConfigSection(parsed, "assets", filePath), filePath);
|
|
290
|
+
}
|
|
291
|
+
function readGeneratorConfigSection(value, sectionName, filePath) {
|
|
292
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
293
|
+
throw new Error(`Asset config must be a YAML mapping: ${filePath}`);
|
|
294
|
+
}
|
|
295
|
+
const root = value;
|
|
296
|
+
if (Object.prototype.hasOwnProperty.call(root, sectionName)) {
|
|
297
|
+
return root[sectionName];
|
|
298
|
+
}
|
|
299
|
+
const legacyKeys = /* @__PURE__ */ new Set(["input_dir", "output_file", "base_path"]);
|
|
300
|
+
if (Object.keys(root).every((key) => legacyKeys.has(key))) return root;
|
|
301
|
+
throw new Error(`Asset config section "assets" is missing in ${filePath}.`);
|
|
289
302
|
}
|
|
290
303
|
function parseConfigObject(value, filePath) {
|
|
291
304
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|