@@ -8,11 +8,17 @@ const exportPatterns = require('./export');
88const init = require ( './init' ) ;
99const resolveConfig = require ( './resolve_config' ) ;
1010const serve = require ( './serve' ) ;
11+ const log = require ( './utils' ) . log ;
1112const error = require ( './utils' ) . error ;
1213const wrapAsync = require ( './utils' ) . wrapAsync ;
1314const pkg = require ( '../package.json' ) ;
1415
15- const trim = val => val . trim ( ) ;
16+ // Register error logging
17+ log . on ( 'error' , msg => console . log ( msg ) ) ; // eslint-disable-line
18+
19+ const registerDebugLogger = ( ) => {
20+ log . on ( 'debug' , msg => console . log ( msg ) ) ; // eslint-disable-line
21+ } ;
1622
1723/**
1824 * Hook up cli version, usage and options
2430 . action ( function ( cmd ) {
2531 checkArgs ( cmd ) ;
2632 } )
27- . option ( '-c, --config <path>' , 'Specify config file. Default looks up the project dir' , trim , './patternlab-config.json' ) ;
33+ . option ( '-c, --config <path>' , 'Specify config file. Default looks up the project dir' , val => val . trim ( ) , './patternlab-config.json' )
34+ . option ( '-v, --verbose' , 'Show verbose logging' ) ;
2835
2936/**
3037 * build
3744 . option ( '-p, --patterns-only' , 'Whether to only build patterns' )
3845 . action ( options => wrapAsync ( function * ( ) {
3946 try {
47+ if ( options . parent . verbose ) registerDebugLogger ( ) ;
4048 const config = yield resolveConfig ( options . parent . config ) ;
4149 yield copyFiles ( config . paths ) ;
4250 build ( config , options ) ;
5462 . command ( 'export' )
5563 . description ( 'Export a PatternLab patterns into a compressed format' )
5664 . action ( options => wrapAsync ( function * ( ) {
65+ if ( options . parent . verbose ) registerDebugLogger ( ) ;
5766 const config = yield resolveConfig ( options . parent . config ) ;
5867 exportPatterns ( config ) ;
5968 } ) ) ;
6776 . description ( 'Initialize a PatternLab project from scratch or import an edition and/or starterkit' )
6877 . option ( '-f, --force' , 'Overwrite existing files and folders' ) // TODO: Make a global --clean flag to avoid repetition
6978 . action ( options => wrapAsync ( function * ( ) {
79+ if ( options . parent . verbose ) registerDebugLogger ( ) ;
7080 yield init ( options ) ;
7181 } ) ) ;
7282
7989 . alias ( 'browse' )
8090 . description ( 'Starts a server to inspect files in browser' )
8191 . action ( options => wrapAsync ( function * ( ) {
92+ if ( options . parent . verbose ) registerDebugLogger ( ) ;
8293 const config = yield resolveConfig ( options . parent . config ) ;
8394 serve ( config ) ;
8495 } ) ) ;
8596
8697// Show additional help
8798cli . on ( '--help' , ( ) => {
99+ /* eslint-disable */
88100 console . log ( ' Examples:' ) ;
89101 console . log ( '' ) ;
90102 console . log ( ' $ patternlab init # Initialize a PatternLab project.' ) ;
91103 console . log ( ' $ patternlab <cmd> # Builds the PatternLab from the current dir' ) ;
92104 console . log ( ' $ patternlab <cmd> --config <path/to/patternlab-config> # PatternLab from a config in a specified directory' ) ;
93105 console . log ( '' ) ;
106+ /* eslint-enable */
94107} ) ;
95108
96109// Parse at the end because Node emit is immediate
0 commit comments