@@ -33,9 +33,13 @@ program
3333 . command ( 'build' , { isDefault : true } )
3434 . description ( 'Run a metalsmith build' )
3535 . option ( '-c, --config <path>' , 'configuration file location' , 'metalsmith.json' )
36+ . option ( '--debug' , 'Set or override debug namespaces' )
37+ . option ( '--dry-run' , 'Process metalsmith files without outputting to the file system' )
3638 . action ( buildCommand )
3739
38- function buildCommand ( { config } ) {
40+ program . parse ( process . argv )
41+
42+ function buildCommand ( { config, ...options } ) {
3943 const dir = process . cwd ( )
4044 const path = isAbsolute ( config ) ? config : resolve ( dir , config )
4145
@@ -67,6 +71,7 @@ function buildCommand({ config }) {
6771 if ( json . frontmatter != null ) metalsmith . frontmatter ( json . frontmatter )
6872 if ( json . ignore != null ) metalsmith . ignore ( json . ignore )
6973 if ( isObject ( json . env ) ) metalsmith . env ( expandEnvVars ( json . env , process . env ) )
74+ if ( options . debug ) metalsmith . env ( 'DEBUG' , options . debug )
7075
7176 // set a flag plugins can check to target CLI-specific behavior
7277 metalsmith . env ( 'CLI' , true )
@@ -103,15 +108,18 @@ function buildCommand({ config }) {
103108 }
104109 } )
105110
106- /**
107- * Build.
108- */
109-
110- metalsmith . build ( function ( err ) {
111- if ( err ) fatal ( err . message , err . stack )
112- log ( 'success' , `successfully built to ${ metalsmith . destination ( ) } ` )
113- } )
111+ function onBuild ( message ) {
112+ return ( err ) => {
113+ if ( err ) fatal ( err . message , err . stack )
114+ log ( 'success' , message )
115+ }
116+ }
114117
118+ if ( options . dryRun ) {
119+ metalsmith . process ( onBuild ( `successfully ran a dry-run of the ${ config } build` ) )
120+ } else {
121+ metalsmith . build ( onBuild ( `successfully built to ${ metalsmith . destination ( ) } ` ) )
122+ }
115123}
116124
117125/**
0 commit comments