@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 CHANGED
@@ -37,12 +37,13 @@ public/assets/
37
37
  └── icons/search.svg
38
38
  ```
39
39
 
40
- Create `valfuse-assets.yaml` in the project root:
40
+ Create `valfuse.yaml` in the project root:
41
41
 
42
42
  ```yaml
43
- input_dir: public/assets
44
- output_file: src/assets/assets.ts
45
- base_path: /assets
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-assets.yaml` from the current working directory, matching
87
- the config-file convention used by the localization CLI:
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
- input_dir: public/media
91
- output_file: src/assets/assets.ts
92
- base_path: /media
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-assets.yaml
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-assets.yaml. Defaults for omitted options:
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-assets.yaml");
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)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valfuse-node/assets",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Generate a typed TypeScript registry for static asset paths",
5
5
  "license": "MIT",
6
6
  "keywords": [