svgfusion 1.0.6 → 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.
Files changed (2) hide show
  1. package/dist/cli.js +71 -18
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -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 import_path2 = require("path");
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, import_path2.dirname)(__filename2);
556
+ var __dirname = (0, import_path3.dirname)(__filename2);
524
557
  var packageJson = JSON.parse(
525
- (0, import_fs2.readFileSync)((0, import_path2.join)(__dirname, "..", "package.json"), "utf-8")
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", {
@@ -559,7 +592,19 @@ program.command("convert").description("Convert SVG files to React or Vue compon
559
592
  if (framework !== "react" && framework !== "vue") {
560
593
  throw new Error('Framework must be either "react" or "vue"');
561
594
  }
562
- const svgFiles = await readSvgDirectory(input);
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
+ }
563
608
  if (svgFiles.length === 0) {
564
609
  throw new Error("No SVG files found in the input path");
565
610
  }
@@ -569,8 +614,16 @@ program.command("convert").description("Convert SVG files to React or Vue compon
569
614
  for (const filePath of svgFiles) {
570
615
  const svgContent = await readSvgFile(filePath);
571
616
  const optimizedSvg = optimize2 ? optimizeSvg(svgContent) : svgContent;
572
- const result = framework === "react" ? await convertToReact(optimizedSvg, { typescript }) : await convertToVue(optimizedSvg, { typescript });
573
- const outputPath = (0, import_path2.join)(output, result.filename);
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);
574
627
  await writeComponentFile(outputPath, result.code);
575
628
  }
576
629
  console.log(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svgfusion",
3
- "version": "1.0.6",
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",