@@ -7,7 +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' ;
10+ import { generateSVG , generateShape } from '../src/generate.js' ;
1111
1212import { Command } from 'commander' ;
1313
@@ -70,7 +70,7 @@ function handlePreview(source, options) {
7070 }
7171}
7272
73- function handleGenerate ( source ) {
73+ function handleGenerateSVG ( source ) {
7474 let { content, error } = read ( source ) ;
7575 if ( error ) {
7676 console . log ( error . message ) ;
@@ -85,6 +85,16 @@ function handleGenerate(source) {
8585 }
8686}
8787
88+ function handleGenerateShape ( source ) {
89+ let { content, error } = read ( source ) ;
90+ if ( error ) {
91+ console . log ( error . message ) ;
92+ process . exit ( 1 ) ;
93+ } else {
94+ console . log ( generateShape ( content ) ) ;
95+ }
96+ }
97+
8898function handleSetBrowser ( executablePath ) {
8999 config . browserPath = executablePath ;
90100 fs . writeFileSync ( configPath , JSON . stringify ( config , null , 2 ) ) ;
@@ -121,24 +131,13 @@ program.command('preview')
121131 handlePreview ( source , options ) ;
122132 } ) ;
123133
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-
134134program . command ( 'parse' )
135135 . description ( 'print the parsed tokens, helped to debug on development' )
136136 . argument ( '<source>' , 'source file to parse' )
137137 . action ( ( source ) => {
138138 handleParse ( source ) ;
139139 } ) ;
140140
141-
142141program . command ( 'config' )
143142 . description ( 'display/set the configuration' )
144143 . action ( ( ) => {
@@ -153,6 +152,24 @@ program.command('config')
153152 }
154153 } ) ;
155154
155+ const commandGenerate = program . command ( 'generate' )
156+ . description ( 'generate code using CSS Doodle generators' )
157+ . action ( ( _ , cmd ) => {
158+ cmd . help ( ) ;
159+ } ) ;
160+
161+ commandGenerate . command ( 'svg <source>' )
162+ . description ( 'generate SVG code using svg() function' )
163+ . action ( ( source ) => {
164+ handleGenerateSVG ( source ) ;
165+ } )
166+
167+ commandGenerate . command ( 'polygon <source>' )
168+ . description ( 'generate CSS polygon() using shape() function' )
169+ . action ( ( source ) => {
170+ handleGenerateShape ( source ) ;
171+ } ) ;
172+
156173if ( process . argv . length <= 2 ) {
157174 program . help ( ) ;
158175} else {
0 commit comments