@@ -66,123 +66,122 @@ function main(o, config, configName, callback) {
6666 const subDir = ( config . defaults . flat ? '' : configName ) ;
6767
6868 if ( verbose ) console . log ( 'Making/cleaning output directories' ) ;
69- ff . mkdirp ( path . join ( outputDir , subDir ) , function ( ) {
70- ff . rimraf ( path . join ( outputDir , subDir ) + '/*' , function ( ) {
71- if ( config . directories ) {
72- for ( let directory of config . directories ) {
73- ff . mkdirp . sync ( path . join ( outputDir , subDir , directory ) ) ;
74- }
69+ ff . mkdirp . sync ( path . join ( outputDir , subDir ) ) ;
70+ ff . rimraf ( path . join ( outputDir , subDir ) + '/*' , function ( ) {
71+ if ( config . directories ) {
72+ for ( let directory of config . directories ) {
73+ ff . mkdirp . sync ( path . join ( outputDir , subDir , directory ) ) ;
7574 }
76- for ( let action of actions ) {
77- if ( verbose ) console . log ( 'Rendering ' + action . output ) ;
78- let content ;
79- if ( config . generator && config . generator . render ) {
80- content = config . generator . render ( action . template , model , config . partials ) ;
81- } else {
82- let template = Hogan . compile ( action . template ) ;
83- content = template . render ( model , config . partials ) ;
84- }
85- ff . createFile ( path . join ( outputDir , subDir , action . output ) , content , 'utf8' ) ;
75+ }
76+ for ( let action of actions ) {
77+ if ( verbose ) console . log ( 'Rendering ' + action . output ) ;
78+ let content ;
79+ if ( config . generator && config . generator . render ) {
80+ content = config . generator . render ( action . template , model , config . partials ) ;
81+ } else {
82+ let template = Hogan . compile ( action . template ) ;
83+ content = template . render ( model , config . partials ) ;
8684 }
87- if ( config . touch ) { // may not now be necessary
88- let touchTmp = Hogan . compile ( config . touch ) ;
89- let touchList = touchTmp . render ( model , config . partials ) ;
90- let files = touchList . split ( '\r' ) . join ( '' ) . split ( '\n' ) ;
91- for ( let file of files ) {
92- file = file . trim ( ) ;
93- if ( file ) {
94- if ( ! fs . existsSync ( path . join ( outputDir , subDir , file ) ) ) {
95- ff . createFile ( path . join ( outputDir , subDir , file ) , '' , 'utf8' ) ;
96- }
85+ ff . createFile ( path . join ( outputDir , subDir , action . output ) , content , 'utf8' ) ;
86+ }
87+ if ( config . touch ) { // may not now be necessary
88+ let touchTmp = Hogan . compile ( config . touch ) ;
89+ let touchList = touchTmp . render ( model , config . partials ) ;
90+ let files = touchList . split ( '\r' ) . join ( '' ) . split ( '\n' ) ;
91+ for ( let file of files ) {
92+ file = file . trim ( ) ;
93+ if ( file ) {
94+ if ( ! fs . existsSync ( path . join ( outputDir , subDir , file ) ) ) {
95+ ff . createFile ( path . join ( outputDir , subDir , file ) , '' , 'utf8' ) ;
9796 }
9897 }
9998 }
99+ }
100100
101- // generate license by default
102- if ( typeof config . license === 'undefined' ) {
103- config . license = true ;
104- }
101+ // generate license by default
102+ if ( typeof config . license === 'undefined' ) {
103+ config . license = true ;
104+ }
105105
106- if ( config . license ) {
107- const licenseType = config . apache ? 'LICENSE' : 'UNLICENSE' ;
108- ff . createFile ( path . join ( outputDir , subDir , 'LICENSE' ) , ff . readFileSync ( tpl ( { } , '_common' , licenseType ) , 'utf8' ) , 'utf8' ) ;
109- }
106+ if ( config . license ) {
107+ const licenseType = config . apache ? 'LICENSE' : 'UNLICENSE' ;
108+ ff . createFile ( path . join ( outputDir , subDir , 'LICENSE' ) , ff . readFileSync ( tpl ( { } , '_common' , licenseType ) , 'utf8' ) , 'utf8' ) ;
109+ }
110110
111- let outer = model ;
112-
113- if ( config . perApi ) {
114- let toplevel = clone ( model ) ;
115- delete toplevel . apiInfo ;
116- for ( let pa of config . perApi ) {
117- let fnTemplate = Hogan . compile ( pa . output ) ;
118- let template = Hogan . compile ( ff . readFileSync ( tpl ( config , configName , pa . input ) , 'utf8' ) ) ;
119- for ( let api of model . apiInfo . apis ) {
120- let cApi = Object . assign ( { } , config . defaults , pa . defaults || { } , toplevel , api ) ;
121- let filename = fnTemplate . render ( cApi , config . partials ) ;
122- if ( verbose ) console . log ( 'Rendering ' + filename + ' (dynamic:' + pa . input + ')' ) ;
123- ff . createFile ( path . join ( outputDir , subDir , filename ) , template . render ( cApi , config . partials ) , 'utf8' ) ;
124- }
111+ let outer = model ;
112+
113+ if ( config . perApi ) {
114+ let toplevel = clone ( model ) ;
115+ delete toplevel . apiInfo ;
116+ for ( let pa of config . perApi ) {
117+ let fnTemplate = Hogan . compile ( pa . output ) ;
118+ let template = Hogan . compile ( ff . readFileSync ( tpl ( config , configName , pa . input ) , 'utf8' ) ) ;
119+ for ( let api of model . apiInfo . apis ) {
120+ let cApi = Object . assign ( { } , config . defaults , pa . defaults || { } , toplevel , api ) ;
121+ let filename = fnTemplate . render ( cApi , config . partials ) ;
122+ if ( verbose ) console . log ( 'Rendering ' + filename + ' (dynamic:' + pa . input + ')' ) ;
123+ ff . createFile ( path . join ( outputDir , subDir , filename ) , template . render ( cApi , config . partials ) , 'utf8' ) ;
125124 }
126125 }
126+ }
127127
128- if ( config . perPath ) {
129- let toplevel = clone ( model ) ;
130- delete toplevel . apiInfo ;
131- for ( let pa of config . perPath ) {
132- let fnTemplate = Hogan . compile ( pa . output ) ;
133- let template = Hogan . compile ( ff . readFileSync ( tpl ( config , configName , pa . input ) , 'utf8' ) ) ;
134- for ( let pat of model . apiInfo . paths ) {
135- let cPath = Object . assign ( { } , config . defaults , pa . defaults || { } , toplevel , pat ) ;
136- let filename = fnTemplate . render ( cPath , config . partials ) ;
137- let dirname = path . dirname ( filename ) ;
138- if ( verbose ) console . log ( 'Rendering ' + filename + ' (dynamic:' + pa . input + ')' ) ;
139- ff . mkdirp . sync ( path . join ( outputDir , subDir , dirname ) ) ;
140- ff . createFile ( path . join ( outputDir , subDir , filename ) , template . render ( cPath , config . partials ) , 'utf8' ) ;
141- }
128+ if ( config . perPath ) {
129+ let toplevel = clone ( model ) ;
130+ delete toplevel . apiInfo ;
131+ for ( let pa of config . perPath ) {
132+ let fnTemplate = Hogan . compile ( pa . output ) ;
133+ let template = Hogan . compile ( ff . readFileSync ( tpl ( config , configName , pa . input ) , 'utf8' ) ) ;
134+ for ( let pat of model . apiInfo . paths ) {
135+ let cPath = Object . assign ( { } , config . defaults , pa . defaults || { } , toplevel , pat ) ;
136+ let filename = fnTemplate . render ( cPath , config . partials ) ;
137+ let dirname = path . dirname ( filename ) ;
138+ if ( verbose ) console . log ( 'Rendering ' + filename + ' (dynamic:' + pa . input + ')' ) ;
139+ ff . mkdirp . sync ( path . join ( outputDir , subDir , dirname ) ) ;
140+ ff . createFile ( path . join ( outputDir , subDir , filename ) , template . render ( cPath , config . partials ) , 'utf8' ) ;
142141 }
143142 }
143+ }
144144
145- if ( config . perModel ) {
146- let cModels = clone ( model . models ) ;
147- for ( let pm of config . perModel ) {
148- let fnTemplate = Hogan . compile ( pm . output ) ;
149- let template = Hogan . compile ( ff . readFileSync ( tpl ( config , configName , pm . input ) , 'utf8' ) ) ;
150- for ( let model of cModels ) {
151- outer . models = [ ] ;
152- let effModel = Object . assign ( { } , model , pm . defaults || { } ) ;
153- outer . models . push ( effModel ) ;
154- let filename = fnTemplate . render ( outer , config . partials ) ;
155- if ( verbose ) console . log ( 'Rendering ' + filename + ' (dynamic:' + pm . input + ')' ) ;
156- ff . createFile ( path . join ( outputDir , subDir , filename ) , template . render ( outer , config . partials ) , 'utf8' ) ;
157- }
145+ if ( config . perModel ) {
146+ let cModels = clone ( model . models ) ;
147+ for ( let pm of config . perModel ) {
148+ let fnTemplate = Hogan . compile ( pm . output ) ;
149+ let template = Hogan . compile ( ff . readFileSync ( tpl ( config , configName , pm . input ) , 'utf8' ) ) ;
150+ for ( let model of cModels ) {
151+ outer . models = [ ] ;
152+ let effModel = Object . assign ( { } , model , pm . defaults || { } ) ;
153+ outer . models . push ( effModel ) ;
154+ let filename = fnTemplate . render ( outer , config . partials ) ;
155+ if ( verbose ) console . log ( 'Rendering ' + filename + ' (dynamic:' + pm . input + ')' ) ;
156+ ff . createFile ( path . join ( outputDir , subDir , filename ) , template . render ( outer , config . partials ) , 'utf8' ) ;
158157 }
159158 }
159+ }
160160
161- if ( config . perOperation ) { // now may not be necessary
162- for ( let po of config . perOperation ) {
163- for ( let api of outer . apiInfo . apis ) {
164- let cOperations = clone ( api . operations ) ;
165- let fnTemplate = Hogan . compile ( po . output ) ;
166- let template = Hogan . compile ( ff . readFileSync ( tpl ( config , configName , po . input ) , 'utf8' ) ) ;
167- for ( let operation of cOperations . operation ) {
168- model . operations = [ ] ;
169- model . operations . push ( operation ) ;
170- let filename = fnTemplate . render ( outer , config . partials ) ;
171- if ( verbose ) console . log ( 'Rendering ' + filename + ' (dynamic:' + po . input + ')' ) ;
172- ff . createFile ( path . join ( outputDir , subDir , filename ) , template . render ( outer , config . partials ) , 'utf8' ) ;
173- }
161+ if ( config . perOperation ) { // now may not be necessary
162+ for ( let po of config . perOperation ) {
163+ for ( let api of outer . apiInfo . apis ) {
164+ let cOperations = clone ( api . operations ) ;
165+ let fnTemplate = Hogan . compile ( po . output ) ;
166+ let template = Hogan . compile ( ff . readFileSync ( tpl ( config , configName , po . input ) , 'utf8' ) ) ;
167+ for ( let operation of cOperations . operation ) {
168+ model . operations = [ ] ;
169+ model . operations . push ( operation ) ;
170+ let filename = fnTemplate . render ( outer , config . partials ) ;
171+ if ( verbose ) console . log ( 'Rendering ' + filename + ' (dynamic:' + po . input + ')' ) ;
172+ ff . createFile ( path . join ( outputDir , subDir , filename ) , template . render ( outer , config . partials ) , 'utf8' ) ;
174173 }
175174 }
176175 }
176+ }
177177
178- if ( callback ) callback ( null , true ) ;
179- } ) ;
178+ if ( callback ) callback ( null , true ) ;
180179 } ) ;
181180 } ) ;
182181}
183182
184183module . exports = {
185184 fileFunctions : ff ,
186- main : main
185+ main
187186} ;
188187
0 commit comments