@@ -7,6 +7,7 @@ import { pkg, config, configPath } from '../src/static.js';
77import { parse } from '../src/parse.js' ;
88import { preview } from '../src/preview/index.js' ;
99import { render } from '../src/render.js' ;
10+ import { generateSVG } from '../src/generate-svg.js' ;
1011
1112import { Command } from 'commander' ;
1213
@@ -23,7 +24,7 @@ function read(path) {
2324 return { content, error } ;
2425}
2526
26- async function handleGenerate ( source , options ) {
27+ async function handleRender ( source , options ) {
2728 let { content, error } = read ( source ) ;
2829 if ( error ) {
2930 console . log ( error . message ) ;
@@ -69,6 +70,21 @@ function handlePreview(source, options) {
6970 }
7071}
7172
73+ function handleGenerate ( source ) {
74+ let { content, error } = read ( source ) ;
75+ if ( error ) {
76+ console . log ( error . message ) ;
77+ process . exit ( 1 ) ;
78+ } else {
79+ content = content . trim ( ) ;
80+ if ( / ^ s v g \s * \{ / i. test ( content ) || ! content . length ) {
81+ console . log ( generateSVG ( content ) ) ;
82+ } else {
83+ console . log ( 'Not a valid SVG format' ) ;
84+ }
85+ }
86+ }
87+
7288function handleSetBrowser ( executablePath ) {
7389 config . browserPath = executablePath ;
7490 fs . writeFileSync ( configPath , JSON . stringify ( config , null , 2 ) ) ;
@@ -94,7 +110,7 @@ program
94110 . option ( '-o, --output <output>' , 'custom filename of the generated image' )
95111 . option ( '-x, --scale <scale>' , 'scale factor of the generated image, defaults to 1' )
96112 . action ( ( source , options ) => {
97- handleGenerate ( source , options ) ;
113+ handleRender ( source , options ) ;
98114 } ) ;
99115
100116program . command ( 'preview' )
@@ -105,13 +121,24 @@ program.command('preview')
105121 handlePreview ( source , options ) ;
106122 } ) ;
107123
124+ program . command ( 'generate' )
125+ . description ( 'generate code using CSS Doodle generators' )
126+ . action ( ( _ , cmd ) => {
127+ cmd . help ( ) ;
128+ } )
129+ . command ( 'svg <source>' )
130+ . action ( ( source , options , command ) => {
131+ handleGenerate ( source ) ;
132+ } ) ;
133+
108134program . command ( 'parse' )
109135 . description ( 'print the parsed tokens, helped to debug on development' )
110136 . argument ( '<source>' , 'source file to parse' )
111137 . action ( ( source ) => {
112138 handleParse ( source ) ;
113139 } ) ;
114140
141+
115142program . command ( 'config' )
116143 . description ( 'display/set the configuration' )
117144 . action ( ( ) => {
0 commit comments