@svgforge/svgforge-cli 2.0.1 → 2.0.2-unstable.202609132246.c961c8e
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/LICENSE +0 -1
- package/bin/svgforge.js +23 -11
- package/package.json +11 -12
package/LICENSE
CHANGED
package/bin/svgforge.js
CHANGED
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
/**
|
|
4
4
|
Svgforge is a Node.js module for creating SVG sprites
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Some code based on the command line interface originally written for svg-sprite
|
|
7
7
|
by Joschi Kuphal — this is a standalone fork/package of that CLI.
|
|
8
8
|
|
|
9
|
-
@see https://github.com/
|
|
10
|
-
@author
|
|
11
|
-
@author Felix Müller
|
|
12
|
-
@copyright © 2018 Joschi Kuphal
|
|
9
|
+
@see https://github.com/svgforge/svgforge-cli
|
|
10
|
+
@author Felix Müller (https://github.com/joeda1)
|
|
13
11
|
@copyright © 2026 Felix Müller
|
|
14
|
-
@license MIT https://github.com/
|
|
12
|
+
@license MIT https://github.com/svgforge/svgforge-cli/blob/main/LICENSE
|
|
15
13
|
*/
|
|
16
14
|
|
|
17
15
|
import fs from 'node:fs';
|
|
@@ -527,10 +525,22 @@ async function main() {
|
|
|
527
525
|
loadVariables(config);
|
|
528
526
|
|
|
529
527
|
const spriter = new SVGSpriter(config);
|
|
530
|
-
|
|
528
|
+
|
|
529
|
+
// Glob (>= 9, incl. fs.globSync) returns paths without the "./" segment, so
|
|
530
|
+
// the base directory marker has to be detected on the original pattern. A
|
|
531
|
+
// literal "/./" segment marks the directory from which shape ID traversal
|
|
532
|
+
// should start (e.g. "assets/./**/*.svg" yields "path--to--source" instead
|
|
533
|
+
// of "assets--path--to--source").
|
|
534
|
+
const matchedFiles = argv._.flatMap(pattern => {
|
|
535
|
+
const marker = pattern.lastIndexOf('./');
|
|
536
|
+
const baseDepth = marker === -1 ? 0 : pattern.slice(0, marker).split('/').filter(Boolean).length;
|
|
537
|
+
return fs.globSync(pattern)
|
|
538
|
+
.toSorted((a, b) => b.localeCompare(a))
|
|
539
|
+
.map(file => ({baseDepth, file}));
|
|
540
|
+
});
|
|
531
541
|
const excludedInputRoots = getExcludedInputRoots(config);
|
|
532
542
|
|
|
533
|
-
for (const filePattern of
|
|
543
|
+
for (const {baseDepth, file: filePattern} of matchedFiles) {
|
|
534
544
|
const file = path.resolve(filePattern);
|
|
535
545
|
|
|
536
546
|
// Skip files inside the output tree so previously generated artifacts are
|
|
@@ -539,15 +549,17 @@ async function main() {
|
|
|
539
549
|
continue;
|
|
540
550
|
}
|
|
541
551
|
|
|
542
|
-
//
|
|
543
|
-
//
|
|
544
|
-
// in the shape identifiers (e.g. "nested/leaf.svg" -> "nested--leaf")
|
|
552
|
+
// Detect relative patterns to preserve directory structure in the shape
|
|
553
|
+
// identifiers (e.g. "nested/leaf.svg" -> "nested--leaf")
|
|
545
554
|
const isRelative = !path.isAbsolute(filePattern) && !filePattern.startsWith('../');
|
|
546
555
|
const stat = fs.lstatSync(file);
|
|
547
556
|
let basename;
|
|
548
557
|
|
|
549
558
|
if (stat.isSymbolicLink()) {
|
|
550
559
|
basename = path.basename(fs.readlinkSync(file));
|
|
560
|
+
} else if (baseDepth > 0) {
|
|
561
|
+
// Strip the base directory marked by "/./" from the shape identifier
|
|
562
|
+
basename = filePattern.split('/').filter(Boolean).slice(baseDepth).join('/');
|
|
551
563
|
} else {
|
|
552
564
|
basename = isRelative ? filePattern : path.basename(file);
|
|
553
565
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svgforge/svgforge-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-unstable.202609132246.c961c8e",
|
|
4
4
|
"author": "Felix Müller (https://github.com/joeda1)",
|
|
5
|
-
"contributors": [
|
|
6
|
-
"Joschi Kuphal <joschi@kuphal.net> (https://github.com/jkphl)"
|
|
7
|
-
],
|
|
8
5
|
"description": "Command line interface for svgforge — create SVG sprites & stacks with stylesheet resources (CSS, Sass, etc.)",
|
|
9
6
|
"homepage": "https://github.com/svgforge/svgforge-cli",
|
|
10
7
|
"repository": {
|
|
@@ -33,20 +30,22 @@
|
|
|
33
30
|
"files": [
|
|
34
31
|
"bin"
|
|
35
32
|
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"prepare": "husky",
|
|
35
|
+
"lint": "xo",
|
|
36
|
+
"fix": "xo --fix",
|
|
37
|
+
"test": "node --test test/*.test.js",
|
|
38
|
+
"test:coverage": "mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info"
|
|
39
|
+
},
|
|
36
40
|
"dependencies": {
|
|
37
|
-
"@svgforge/svgforge": "^2.0.0",
|
|
41
|
+
"@svgforge/svgforge": "^2.0.2-unstable.0",
|
|
38
42
|
"js-yaml": "^5.4.1",
|
|
39
43
|
"vinyl": "^3.0.1",
|
|
40
44
|
"yargs": "^18.1.0"
|
|
41
45
|
},
|
|
42
46
|
"devDependencies": {
|
|
43
47
|
"eslint-plugin-jsdoc": "^64.3.2",
|
|
48
|
+
"husky": "^9.1.7",
|
|
44
49
|
"xo": "^4.0.0"
|
|
45
|
-
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"lint": "xo",
|
|
48
|
-
"fix": "xo --fix",
|
|
49
|
-
"test": "node --test test/*.test.js",
|
|
50
|
-
"test:coverage": "mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info"
|
|
51
50
|
}
|
|
52
|
-
}
|
|
51
|
+
}
|