@@ -34,6 +34,7 @@ program
34
34
. option ( '-b, --basedir <path>' , 'path used as root directory to resolve absolute includes' )
35
35
. option ( '-P, --pretty' , 'compile pretty HTML output' )
36
36
. 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)' )
37
38
. option ( '-n, --name <str>' , 'the name of the compiled template (requires --client)' )
38
39
. option ( '-D, --no-debug' , 'compile without debugging (smaller functions)' )
39
40
. option ( '-w, --watch' , 'watch files for changes and automatically re-render' )
@@ -136,6 +137,13 @@ var watchList = {};
136
137
// function for rendering
137
138
var render = program . watch ? tryRender : renderFile ;
138
139
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
+
139
147
// compile files
140
148
141
149
if ( files . length ) {
@@ -185,6 +193,7 @@ function watchFile(path, base, rootPath) {
185
193
if ( curr . mtime . getTime ( ) === 0 ) return ;
186
194
// istanbul ignore if
187
195
if ( curr . mtime . getTime ( ) === prev . mtime . getTime ( ) ) return ;
196
+ bigModeFirstFileWrote = false ;
188
197
watchList [ path ] . forEach ( function ( file ) {
189
198
tryRender ( file , rootPath ) ;
190
199
} ) ;
@@ -286,8 +295,15 @@ function renderFile(path, rootPath) {
286
295
var dir = resolve ( dirname ( path ) ) ;
287
296
mkdirp . sync ( dir ) ;
288
297
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
+ }
291
307
// Found directory
292
308
} else if ( stat . isDirectory ( ) ) {
293
309
var files = fs . readdirSync ( path ) ;
0 commit comments