1717
1818'use strict' ;
1919
20- /* eslint-disable no-console */
21-
2220const fs = require ( 'fs' ) . promises ;
2321const path = require ( 'path' ) ;
2422const yaml = require ( 'js-yaml' ) ;
@@ -51,8 +49,12 @@ const setLogger = (argv) => {
5149 }
5250 } ;
5351 process . on ( 'exit' , ( ) => {
52+ if ( typeof logger . output . error === 'undefined'
53+ && typeof logger . output . result === 'undefined' ) {
54+ logger . output . result = '' ;
55+ }
5456 const msg = JSON . stringify ( logger . output ) ;
55- console . log ( msg ) ;
57+ console . log ( msg ) ; // eslint-disable-line no-console
5658 } ) ;
5759 } else {
5860 logger = {
@@ -61,13 +63,13 @@ const setLogger = (argv) => {
6163 if ( typeof msg === 'object' ) {
6264 msg = JSON . stringify ( msg , null , 2 ) ;
6365 }
64- console . log ( msg ) ;
66+ console . log ( msg ) ; // eslint-disable-line no-console
6567 } ,
6668 error : ( msg ) => {
6769 if ( typeof msg === 'object' ) {
6870 msg = JSON . stringify ( msg , null , 2 ) ;
6971 }
70- console . error ( msg ) ;
72+ console . error ( msg ) ; // eslint-disable-line no-console
7173 }
7274 } ;
7375 }
@@ -185,7 +187,7 @@ const validateTemplateSet = (tsPath) => {
185187 templateList . map (
186188 tmpl => provider . fetch ( tmpl )
187189 . catch ( ( e ) => {
188- console . error (
190+ logger . error (
189191 `Template "${ tmpl } " failed validation:\n${ e . stack } \n`
190192 ) ;
191193 errorFound = true ;
@@ -195,12 +197,12 @@ const validateTemplateSet = (tsPath) => {
195197 ) )
196198 . then ( ( ) => {
197199 if ( errorFound ) {
198- console . error ( `Template set "${ tsName } " failed validation` ) ;
200+ logger . error ( `Template set "${ tsName } " failed validation` ) ;
199201 process . exit ( 1 ) ;
200202 }
201203 } )
202204 . catch ( ( e ) => {
203- console . error ( `Template set "${ tsName } " failed validation:\n${ e . stack } ` ) ;
205+ logger . error ( `Template set "${ tsName } " failed validation:\n${ e . stack } ` ) ;
204206 process . exit ( 1 ) ;
205207 } ) ;
206208} ;
@@ -210,7 +212,7 @@ const htmlPreview = (templatePath, parametersPath) => loadTemplateAndParameters(
210212 tmpl . getParametersSchema ( ) ,
211213 tmpl . getCombinedParameters ( parameters )
212214 ) )
213- . then ( htmlData => console . log ( htmlData ) ) ;
215+ . then ( htmlData => logger . log ( htmlData ) ) ;
214216
215217const packageTemplateSet = ( tsPath , dst ) => validateTemplateSet ( tsPath )
216218 . then ( ( ) => {
@@ -222,7 +224,7 @@ const packageTemplateSet = (tsPath, dst) => validateTemplateSet(tsPath)
222224
223225 return provider . buildPackage ( tsName , dst )
224226 . then ( ( ) => {
225- console . log ( `Template set "${ tsName } " packaged as ${ dst } ` ) ;
227+ logger . log ( `Template set "${ tsName } " packaged as ${ dst } ` ) ;
226228 } ) ;
227229 } ) ;
228230
0 commit comments