(inputPath, outputPath, options, command)
| 76 | }); |
| 77 | |
| 78 | async 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 | |
| 126 | async function runOptimizeCommand(inputPath, outputPath, options) { |
| 127 | if (options.print && outputPath) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…