svgfusion 1.0.5 → 1.0.7
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/dist/cli.js +74 -23
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -31,10 +31,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
31
|
));
|
|
32
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
33
|
|
|
34
|
-
// node_modules/.pnpm/tsup@8.5.
|
|
34
|
+
// node_modules/.pnpm/tsup@8.5.0_postcss@8.5.6_typescript@5.8.3_yaml@2.8.0/node_modules/tsup/assets/cjs_shims.js
|
|
35
35
|
var getImportMetaUrl, importMetaUrl;
|
|
36
36
|
var init_cjs_shims = __esm({
|
|
37
|
-
"node_modules/.pnpm/tsup@8.5.
|
|
37
|
+
"node_modules/.pnpm/tsup@8.5.0_postcss@8.5.6_typescript@5.8.3_yaml@2.8.0/node_modules/tsup/assets/cjs_shims.js"() {
|
|
38
38
|
"use strict";
|
|
39
39
|
getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
40
40
|
importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
@@ -125,6 +125,51 @@ var init_files = __esm({
|
|
|
125
125
|
init_cjs_shims();
|
|
126
126
|
var import_commander = require("commander");
|
|
127
127
|
init_files();
|
|
128
|
+
var import_promises2 = require("fs/promises");
|
|
129
|
+
var import_path2 = require("path");
|
|
130
|
+
|
|
131
|
+
// src/utils/name.ts
|
|
132
|
+
init_cjs_shims();
|
|
133
|
+
function svgToComponentName(filename) {
|
|
134
|
+
let baseName = filename.replace(/\.svg$/i, "");
|
|
135
|
+
baseName = processComplexFilename(baseName);
|
|
136
|
+
return pascalCase(baseName);
|
|
137
|
+
}
|
|
138
|
+
function processComplexFilename(filename) {
|
|
139
|
+
let processed = filename;
|
|
140
|
+
const simpleMatch = processed.match(/^([^,]+),\s*Type=([^,]+)/i);
|
|
141
|
+
if (simpleMatch) {
|
|
142
|
+
processed = `${simpleMatch[1]} ${simpleMatch[2]}`;
|
|
143
|
+
return processed;
|
|
144
|
+
}
|
|
145
|
+
const sizeMatch = processed.match(/Size=(\w+)/i);
|
|
146
|
+
const colorMatch = processed.match(/Color=(\w+)/i);
|
|
147
|
+
const typeMatch = processed.match(/Type=(\w+)/i);
|
|
148
|
+
if (sizeMatch || colorMatch || typeMatch) {
|
|
149
|
+
const parts = [];
|
|
150
|
+
if (typeMatch) parts.push(typeMatch[1]);
|
|
151
|
+
if (colorMatch) parts.push(colorMatch[1]);
|
|
152
|
+
if (sizeMatch) parts.push(sizeMatch[1]);
|
|
153
|
+
if (parts.length > 0) {
|
|
154
|
+
processed = parts.join(" ");
|
|
155
|
+
return processed;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
processed = processed.replace(/\b\w+=\w+\b/g, "").replace(/,\s*/g, " ").replace(/[=]/g, " ").replace(/\s+/g, " ").trim();
|
|
159
|
+
if (!processed || processed.length < 2) {
|
|
160
|
+
processed = filename;
|
|
161
|
+
}
|
|
162
|
+
return processed;
|
|
163
|
+
}
|
|
164
|
+
function pascalCase(str) {
|
|
165
|
+
return str.replace(/[^a-zA-Z0-9\s-_]/g, " ").split(/[\s-_]+/).filter((word) => word.length > 0).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
166
|
+
}
|
|
167
|
+
function formatComponentName(name, prefix, suffix) {
|
|
168
|
+
const prefixPart = prefix ? pascalCase(prefix) : "";
|
|
169
|
+
const suffixPart = suffix ? pascalCase(suffix) : "";
|
|
170
|
+
const baseName = pascalCase(name);
|
|
171
|
+
return `${prefixPart}${baseName}${suffixPart}`;
|
|
172
|
+
}
|
|
128
173
|
|
|
129
174
|
// src/core/react-converter.ts
|
|
130
175
|
init_cjs_shims();
|
|
@@ -170,18 +215,6 @@ function optimizeSvg(svgContent, config = defaultConfig) {
|
|
|
170
215
|
}
|
|
171
216
|
}
|
|
172
217
|
|
|
173
|
-
// src/utils/name.ts
|
|
174
|
-
init_cjs_shims();
|
|
175
|
-
function pascalCase(str) {
|
|
176
|
-
return str.replace(/[^a-zA-Z0-9\s-_]/g, " ").split(/[\s-_]+/).filter((word) => word.length > 0).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
177
|
-
}
|
|
178
|
-
function formatComponentName(name, prefix, suffix) {
|
|
179
|
-
const prefixPart = prefix ? pascalCase(prefix) : "";
|
|
180
|
-
const suffixPart = suffix ? pascalCase(suffix) : "";
|
|
181
|
-
const baseName = pascalCase(name);
|
|
182
|
-
return `${prefixPart}${baseName}${suffixPart}`;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
218
|
// src/core/converter.ts
|
|
186
219
|
var BaseConverter = class {
|
|
187
220
|
/**
|
|
@@ -508,7 +541,7 @@ async function convertToVue(svgContent, options = {}) {
|
|
|
508
541
|
|
|
509
542
|
// src/cli.ts
|
|
510
543
|
var import_url = require("url");
|
|
511
|
-
var
|
|
544
|
+
var import_path3 = require("path");
|
|
512
545
|
var import_fs2 = require("fs");
|
|
513
546
|
var import_figlet = __toESM(require("figlet"));
|
|
514
547
|
var colors = {
|
|
@@ -520,9 +553,9 @@ var colors = {
|
|
|
520
553
|
reset: "\x1B[0m"
|
|
521
554
|
};
|
|
522
555
|
var __filename2 = (0, import_url.fileURLToPath)(importMetaUrl);
|
|
523
|
-
var __dirname = (0,
|
|
556
|
+
var __dirname = (0, import_path3.dirname)(__filename2);
|
|
524
557
|
var packageJson = JSON.parse(
|
|
525
|
-
(0, import_fs2.readFileSync)((0,
|
|
558
|
+
(0, import_fs2.readFileSync)((0, import_path3.join)(__dirname, "..", "package.json"), "utf-8")
|
|
526
559
|
);
|
|
527
560
|
function createBanner() {
|
|
528
561
|
const title = import_figlet.default.textSync("SVGfusion", {
|
|
@@ -542,9 +575,7 @@ ${colors.gray}\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
|
542
575
|
`;
|
|
543
576
|
}
|
|
544
577
|
var program = new import_commander.Command();
|
|
545
|
-
|
|
546
|
-
console.log(createBanner());
|
|
547
|
-
}
|
|
578
|
+
console.log(createBanner());
|
|
548
579
|
program.name("svgfusion").description(
|
|
549
580
|
"Transform SVG files into production-ready React and Vue 3 components"
|
|
550
581
|
).version(packageJson.version);
|
|
@@ -561,7 +592,19 @@ program.command("convert").description("Convert SVG files to React or Vue compon
|
|
|
561
592
|
if (framework !== "react" && framework !== "vue") {
|
|
562
593
|
throw new Error('Framework must be either "react" or "vue"');
|
|
563
594
|
}
|
|
564
|
-
const
|
|
595
|
+
const inputStat = await (0, import_promises2.stat)(input);
|
|
596
|
+
let svgFiles;
|
|
597
|
+
if (inputStat.isFile()) {
|
|
598
|
+
if ((0, import_path2.extname)(input).toLowerCase() === ".svg") {
|
|
599
|
+
svgFiles = [input];
|
|
600
|
+
} else {
|
|
601
|
+
throw new Error("Input file must be an SVG file");
|
|
602
|
+
}
|
|
603
|
+
} else if (inputStat.isDirectory()) {
|
|
604
|
+
svgFiles = await readSvgDirectory(input);
|
|
605
|
+
} else {
|
|
606
|
+
throw new Error("Input must be a file or directory");
|
|
607
|
+
}
|
|
565
608
|
if (svgFiles.length === 0) {
|
|
566
609
|
throw new Error("No SVG files found in the input path");
|
|
567
610
|
}
|
|
@@ -571,8 +614,16 @@ program.command("convert").description("Convert SVG files to React or Vue compon
|
|
|
571
614
|
for (const filePath of svgFiles) {
|
|
572
615
|
const svgContent = await readSvgFile(filePath);
|
|
573
616
|
const optimizedSvg = optimize2 ? optimizeSvg(svgContent) : svgContent;
|
|
574
|
-
const
|
|
575
|
-
const
|
|
617
|
+
const filename = (0, import_path2.basename)(filePath);
|
|
618
|
+
const componentName = svgToComponentName(filename);
|
|
619
|
+
const result = framework === "react" ? await convertToReact(optimizedSvg, {
|
|
620
|
+
typescript,
|
|
621
|
+
name: componentName
|
|
622
|
+
}) : await convertToVue(optimizedSvg, {
|
|
623
|
+
typescript,
|
|
624
|
+
name: componentName
|
|
625
|
+
});
|
|
626
|
+
const outputPath = (0, import_path3.join)(output, result.filename);
|
|
576
627
|
await writeComponentFile(outputPath, result.code);
|
|
577
628
|
}
|
|
578
629
|
console.log(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svgfusion",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A powerful CLI tool and library that converts SVG files into production-ready React and Vue 3 components with TypeScript support and automatic optimization.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"build": "tsup && chmod +x dist/cli.js",
|
|
65
65
|
"dev": "tsup --watch",
|
|
66
66
|
"test": "jest",
|
|
67
|
-
"test:coverage": "jest --coverage",
|
|
67
|
+
"test:coverage": "jest --coverage --json --testLocationInResults --outputFile=./coverage/coverage-summary.json",
|
|
68
68
|
"test:watch": "jest --watch",
|
|
69
69
|
"lint": "eslint src/**/*.ts tests/**/*.ts",
|
|
70
70
|
"lint:fix": "eslint src/**/*.ts tests/**/*.ts --fix",
|