MCPcopy Create free account
hub / github.com/neplextech/vectorizer / runVectorizeCommand

Function runVectorizeCommand

cli/index.mjs:78–124  ·  view source on GitHub ↗
(inputPath, outputPath, options, command)

Source from the content-addressed store, hash-verified

76});
77
78async function runVectorizeCommand(inputPath, outputPath, options, command) {
79 if (options.print && outputPath) {
80 console.error(pc.yellow('Warning: Output path is ignored when using --print flag'));
81 }
82
83 await assertReadable(inputPath, 'Input file');
84
85 const finalOutputPath = outputPath || inputPath.replace(/\.[^.]+$/, '.svg');
86 const inputBuffer = await fs.readFile(inputPath);
87 const config = buildVectorizeConfig(options, command);
88 const rawArgs = options.raw ? parseRawSize(options.raw) : null;
89
90 console.error(pc.blue(`Converting ${pc.underline(inputPath)} to SVG`));
91
92 const vectorizeStart = performance.now();
93 const printChunks = options.print && !options.optimize;
94 const collectOptions = {
95 printChunks,
96 showProgress: !options.print,
97 };
98 const svg = rawArgs
99 ? await collectVectorizeChunks(
100 (callback) => vectorizeRawToCallback(inputBuffer, rawArgs, config, callback),
101 collectOptions,
102 )
103 : await collectVectorizeChunks((callback) => vectorizeToCallback(inputBuffer, config, callback), collectOptions);
104 const vectorizeDuration = performance.now() - vectorizeStart;
105
106 if (printChunks) {
107 console.error(pc.blue(`Vectorized in ${vectorizeDuration.toFixed(2)}ms`));
108 return;
109 }
110
111 const outputSvg = options.optimize
112 ? await optimizeWithTiming(svg, buildOptimizeOptions(options, 'optimize'), 'Optimized generated SVG')
113 : svg;
114
115 if (options.print) {
116 process.stdout.write(outputSvg);
117 console.error(pc.blue(`Vectorized in ${vectorizeDuration.toFixed(2)}ms`));
118 return;
119 }
120
121 await fs.writeFile(finalOutputPath, outputSvg, 'utf8');
122 console.error(pc.green(`Wrote ${finalOutputPath}`));
123 console.error(pc.blue(`Vectorized in ${vectorizeDuration.toFixed(2)}ms`));
124}
125
126async function runOptimizeCommand(inputPath, outputPath, options) {
127 if (options.print && outputPath) {

Callers

nothing calls this directly

Calls 6

assertReadableFunction · 0.85
buildVectorizeConfigFunction · 0.85
parseRawSizeFunction · 0.85
collectVectorizeChunksFunction · 0.85
optimizeWithTimingFunction · 0.85
buildOptimizeOptionsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…