@svgforge/svgforge-cli 2.0.0 → 2.0.1

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
@@ -103,6 +103,7 @@ The test suite spawns the CLI as a child process against fixtures in `test/fixtu
103
103
  ## License
104
104
 
105
105
  [MIT](LICENSE) © Felix Müller
106
+
106
107
  [npm-url]: https://www.npmjs.com/package/@svgforge/svgforge-cli
107
108
 
108
109
  [npm-image]: https://img.shields.io/npm/v/@svgforge/svgforge-cli?logo=npm&logoColor=fff
package/bin/svgforge.js CHANGED
@@ -471,6 +471,40 @@ function loadVariables(cfg) {
471
471
  }
472
472
  }
473
473
 
474
+ /**
475
+ Resolve the output directories that must not be re-ingested as source files
476
+
477
+ Generated artifacts (sprites, stylesheets, examples) live inside the configured
478
+ destination tree. When an input glob covers that tree (e.g. a recursive
479
+ SVG glob), a sprite written by a previous run would otherwise be fed back
480
+ in as a shape with an id derived from its output path (e.g.
481
+ "assets--OUT--stack--svg--sprite").
482
+
483
+ @param {SpriterConfig} cfg Spriter configuration
484
+ @returns {string[]} Absolute output root directories to exclude from the input
485
+ */
486
+ function getExcludedInputRoots(cfg) {
487
+ const destRoot = path.resolve(cfg.dest || '.');
488
+ const roots = new Set([destRoot]);
489
+
490
+ // When the destination defaults to the current directory every glob would
491
+ // land inside it, so restrict the exclusion to the mode specific output
492
+ // directories instead.
493
+ if (destRoot === process.cwd()) {
494
+ roots.clear();
495
+
496
+ for (const mode of MODES) {
497
+ const modeDest = cfg.mode?.[mode]?.dest;
498
+
499
+ if (modeDest) {
500
+ roots.add(path.resolve(destRoot, modeDest));
501
+ }
502
+ }
503
+ }
504
+
505
+ return [...roots];
506
+ }
507
+
474
508
  /**
475
509
  Run the command line interface
476
510
 
@@ -494,13 +528,21 @@ async function main() {
494
528
 
495
529
  const spriter = new SVGSpriter(config);
496
530
  const files = argv._.flatMap(filePattern => fs.globSync(filePattern).toSorted((a, b) => b.localeCompare(a)));
531
+ const excludedInputRoots = getExcludedInputRoots(config);
497
532
 
498
533
  for (const filePattern of files) {
534
+ const file = path.resolve(filePattern);
535
+
536
+ // Skip files inside the output tree so previously generated artifacts are
537
+ // not processed as source shapes again
538
+ if (excludedInputRoots.some(root => file === root || file.startsWith(root + path.sep))) {
539
+ continue;
540
+ }
541
+
499
542
  // Glob >= 9 returns paths without the "./" prefix, so detect relative
500
543
  // patterns from the original glob result to preserve directory structure
501
544
  // in the shape identifiers (e.g. "nested/leaf.svg" -> "nested--leaf")
502
545
  const isRelative = !path.isAbsolute(filePattern) && !filePattern.startsWith('../');
503
- const file = path.resolve(filePattern);
504
546
  const stat = fs.lstatSync(file);
505
547
  let basename;
506
548
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svgforge/svgforge-cli",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "author": "Felix Müller (https://github.com/joeda1)",
5
5
  "contributors": [
6
6
  "Joschi Kuphal <joschi@kuphal.net> (https://github.com/jkphl)"
@@ -34,8 +34,8 @@
34
34
  "bin"
35
35
  ],
36
36
  "dependencies": {
37
- "js-yaml": "^5.4.1",
38
37
  "@svgforge/svgforge": "^2.0.0",
38
+ "js-yaml": "^5.4.1",
39
39
  "vinyl": "^3.0.1",
40
40
  "yargs": "^18.1.0"
41
41
  },