@@ -34,6 +34,7 @@ program
3434 . option ( '-b, --basedir <path>' , 'path used as root directory to resolve absolute includes' )
3535 . option ( '-P, --pretty' , 'compile pretty HTML output' )
3636 . option ( '-c, --client' , 'compile function for client-side' )
37+ . option ( '-B, --big <path>' , 'create all template functions in one file (works only with directory as source, implies --client and --name-after-file)' )
3738 . option ( '-n, --name <str>' , 'the name of the compiled template (requires --client)' )
3839 . option ( '-D, --no-debug' , 'compile without debugging (smaller functions)' )
3940 . option ( '-w, --watch' , 'watch files for changes and automatically re-render' )
@@ -136,6 +137,13 @@ var watchList = {};
136137// function for rendering
137138var render = program . watch ? tryRender : renderFile ;
138139
140+ var bigMode = files . length && files . every ( _ => fs . lstatSync ( _ ) . isDirectory ( ) ) && ! ! program . big ;
141+ var bigModeFirstFileWrote = false ;
142+ if ( bigMode ) {
143+ options . client = true ;
144+ program . nameAfterFile = true ;
145+ }
146+
139147// compile files
140148
141149if ( files . length ) {
@@ -185,6 +193,7 @@ function watchFile(path, base, rootPath) {
185193 if ( curr . mtime . getTime ( ) === 0 ) return ;
186194 // istanbul ignore if
187195 if ( curr . mtime . getTime ( ) === prev . mtime . getTime ( ) ) return ;
196+ bigModeFirstFileWrote = false ;
188197 watchList [ path ] . forEach ( function ( file ) {
189198 tryRender ( file , rootPath ) ;
190199 } ) ;
@@ -204,7 +213,7 @@ function errorToString(e) {
204213 *
205214 * This is used in watch mode.
206215 */
207- function tryRender ( path , rootPath ) {
216+ function tryRender ( path , rootPatр ) {
208217 try {
209218 renderFile ( path , rootPath ) ;
210219 } catch ( e ) {
@@ -286,8 +295,15 @@ function renderFile(path, rootPath) {
286295 var dir = resolve ( dirname ( path ) ) ;
287296 mkdirp . sync ( dir ) ;
288297 var output = options . client ? fn : fn ( options ) ;
289- fs . writeFileSync ( path , output ) ;
290- consoleLog ( ' ' + chalk . gray ( 'rendered' ) + ' ' + chalk . cyan ( '%s' ) , normalize ( path ) ) ;
298+ if ( bigMode ) {
299+
300+ fs [ ! bigModeFirstFileWrote ? 'writeFileSync' : 'appendFileSync' ] ( program . big , output ) ;
301+ bigModeFirstFileWrote = true ;
302+ consoleLog ( ' ' + chalk . gray ( `appended ${ path } to ` ) + ' ' + chalk . cyan ( '%s' ) , normalize ( program . big ) ) ;
303+ } else {
304+ fs . writeFileSync ( path , output ) ;
305+ consoleLog ( ' ' + chalk . gray ( 'rendered' ) + ' ' + chalk . cyan ( '%s' ) , normalize ( path ) ) ;
306+ }
291307 // Found directory
292308 } else if ( stat . isDirectory ( ) ) {
293309 var files = fs . readdirSync ( path ) ;
0 commit comments