@@ -35,13 +35,13 @@ export async function handleRender(source, options) {
3535export async function handleParse ( source ) {
3636 let { content, error } = await read ( source ) ;
3737 if ( error ) {
38- console . log ( error . message ) ;
38+ console . warn ( error . message ) ;
3939 process . exit ( 1 ) ;
4040 } else {
4141 try {
4242 console . log ( JSON . stringify ( parse ( content ) , null , 2 ) ) ;
4343 } catch ( e ) {
44- console . log ( e . message ) ;
44+ console . error ( e . message ) ;
4545 process . exit ( 1 ) ;
4646 }
4747 }
@@ -61,14 +61,14 @@ export async function handlePreview(source, options) {
6161export async function handleGenerateSVG ( source ) {
6262 let { content, error } = await read ( source ) ;
6363 if ( error ) {
64- console . log ( error . message ) ;
64+ console . error ( error . message ) ;
6565 process . exit ( 1 ) ;
6666 } else {
6767 content = content . trim ( ) ;
6868 if ( / ^ s v g \s * \{ / i. test ( content ) || ! content . length ) {
6969 console . log ( generateSVG ( content ) ) ;
7070 } else {
71- console . log ( 'Not a valid SVG format') ;
71+ console . warn ( 'warn: invalid SVG format') ;
7272 }
7373 }
7474}
@@ -83,13 +83,17 @@ export async function handleGenerateShape(source) {
8383 }
8484}
8585
86- export function handleSetConfig ( field , value ) {
87- config [ field ] = value ;
88- if ( value === '' ) {
89- delete config [ field ] ;
90- }
91- fs . writeFileSync ( configPath , JSON . stringify ( config , null , 2 ) ) ;
92- console . log ( 'OK' )
86+ export async function handleSetConfig ( field , value ) {
87+ config [ field ] = value ;
88+ if ( value === '' ) {
89+ delete config [ field ] ;
90+ }
91+ try {
92+ fs . writeFileSync ( configPath , JSON . stringify ( config , null , 2 ) ) ;
93+ console . log ( 'ok' ) ;
94+ } catch ( e ) {
95+ console . error ( 'error: failed to write config file' ) ;
96+ }
9397}
9498
9599export function handleDisplayConfig ( field ) {
@@ -109,9 +113,9 @@ async function read(path) {
109113 let content = '' ;
110114 let error = null ;
111115 if ( path === undefined ) {
112- console . log ( 'No source file specified, reading from stdin... ' ) ;
116+ console . log ( 'No source file specified, reading from stdin: ' ) ;
113117 let key = os . platform ( ) === 'win32' ? 'CTRL+Z' : 'CTRL+D' ;
114- console . log ( `Press ${ key } to finish input.\n` ) ;
118+ console . log ( `( Press ${ key } to finish input.) \n` ) ;
115119 try {
116120 content = await readFromStdin ( ) ;
117121 } catch ( e ) {
0 commit comments