@@ -11,8 +11,12 @@ const FileExclusions = ['.DS_Store', 'Thumbs.db'];
1111const FileActionRegExp = / ^ [ _ + a - z A - Z - ] * \( ( [ a - z A - Z ] + ) \) \. / ;
1212const FileCleanupRexExp = / ^ ( _ _ .* ?| \( [ a - z A - Z ] + \) ) \. / ;
1313
14- class FileUtilities {
15- static mergeJson ( context , file ) {
14+ const FileUtilities = {
15+ ClientTemplatesPath : 'client' ,
16+ ServerTemplatesPath : 'server' ,
17+ RootTemplatesPath : 'root' ,
18+
19+ mergeJson ( context , file ) {
1620 const content = context . fs . readJSON ( context . destinationPath ( file . dest ) , { } ) ;
1721 let newContent = context . fs . read ( context . templatePath ( file . src ) ) ;
1822 newContent = file . isTemplate ? ejs . render ( newContent , context , { filename : file . src } ) : newContent ;
@@ -21,9 +25,9 @@ class FileUtilities {
2125 _ . mergeWith ( content , newContent , ( a , b ) => ( _ . isArray ( a ) ? _ . uniq ( a . concat ( b ) ) : undefined ) ) ;
2226
2327 context . fs . writeJSON ( context . destinationPath ( file . dest ) , content ) ;
24- }
28+ } ,
2529
26- static async getFiles ( templatePath , generatorType ) {
30+ async getFiles ( templatePath , generatorType ) {
2731 let promises ;
2832 switch ( generatorType ) {
2933 case 'fullstack' :
@@ -46,9 +50,9 @@ class FileUtilities {
4650 server : files [ 1 ] ,
4751 root : files [ 2 ]
4852 } ;
49- }
53+ } ,
5054
51- static prepareFiles ( files , templatePath , destinationPath , basePath ) {
55+ prepareFiles ( files , templatePath , destinationPath , basePath ) {
5256 basePath = basePath || '' ;
5357
5458 // Removes excluded files
@@ -93,9 +97,9 @@ class FileUtilities {
9397 action
9498 } ;
9599 } ) ;
96- }
100+ } ,
97101
98- static writeFile ( context , file , prefixRules ) {
102+ writeFile ( context , file , prefixRules ) {
99103 const write =
100104 ( file . folderConditions . length === 0 || this . _checkConditions ( file . folderConditions , context , prefixRules ) ) &&
101105 ( file . fileConditions . length === 0 || this . _checkConditions ( file . fileConditions , context , prefixRules ) ) ;
@@ -131,14 +135,14 @@ class FileUtilities {
131135 throw error ;
132136 }
133137 }
134- }
138+ } ,
135139
136- static filterFiles ( files , patterns ) {
140+ filterFiles ( files , patterns ) {
137141 const filter = ignore ( ) . add ( patterns ) ;
138142 return files . filter ( ( file ) => ! filter . ignores ( path . relative ( file . base || '' , file . dest ) ) ) ;
139- }
143+ } ,
140144
141- static _getConditions ( name , prefix ) {
145+ _getConditions ( name , prefix ) {
142146 if ( name . startsWith ( prefix ) ) {
143147 let endIndex = name . indexOf ( '.' ) ;
144148 if ( endIndex === - 1 ) {
@@ -154,26 +158,22 @@ class FileUtilities {
154158 }
155159
156160 return [ ] ;
157- }
161+ } ,
158162
159- static _checkConditions ( conditions , context , rules ) {
163+ _checkConditions ( conditions , context , rules ) {
160164 return conditions . every ( ( condition ) => {
161165 if ( ! rules [ condition ] ) {
162166 throw new Error ( `Invalid condition: ${ condition } ` ) ;
163167 }
164168
165169 return rules [ condition ] ( context . props ) ;
166170 } ) ;
167- }
171+ } ,
168172
169- static _getAction ( name ) {
173+ _getAction ( name ) {
170174 const actionMatch = FileActionRegExp . exec ( name ) ;
171175 return actionMatch ? actionMatch [ 1 ] : null ;
172176 }
173- }
174-
175- FileUtilities . ClientTemplatesPath = 'client' ;
176- FileUtilities . ServerTemplatesPath = 'server' ;
177- FileUtilities . RootTemplatesPath = 'root' ;
177+ } ;
178178
179179module . exports = FileUtilities ;
0 commit comments