@@ -4,32 +4,32 @@ import { IScaffold } from './index'
44
55class Scaffold {
66 private config : IScaffold . IConfig
7+ private locals = { } as any
8+ public scaffoldName = process . argv [ 2 ]
79 private DefaultConfig : IScaffold . IConfig = {
810 templates : [ ] ,
9- output : path . resolve ( process . cwd ( ) )
11+ output : path . resolve ( process . cwd ( ) ) ,
12+ locals : {
13+ Name : this . scaffoldName [ 0 ] . toUpperCase ( ) + this . scaffoldName . slice ( 1 ) ,
14+ name : this . scaffoldName [ 0 ] . toLowerCase ( ) + this . scaffoldName . slice ( 1 )
15+ }
1016 }
1117
1218 constructor ( config : IScaffold . IConfig ) {
1319 // this.config = utils.merge<IScaffold.IConfig>(this.DefaultConfig, config)
20+ if ( ! this . scaffoldName ) {
21+ throw new Error ( 'Must provide scaffold name' )
22+ }
1423 this . config = ( Object as any ) . assign ( { } , this . DefaultConfig , config )
24+ this . locals = ( Object as any ) . assign ( { } , this . DefaultConfig . locals , config . locals )
1525 console . info ( 'Config loaded:' , this . config )
26+ console . info ( 'Locals:' , this . locals )
1627 }
1728
1829 private parseLocals ( text : string ) : string {
1930 let out = text . toString ( )
2031 const pattern = / { { \s * ( .+ ) \s * } } / gi
21- return out . replace ( pattern , ( match : string , $1 : string ) => {
22- const upperName = 'MyComponent'
23- const lowerName = 'myComponent'
24-
25- const replaceMap = {
26- Name : upperName ,
27- name : lowerName ,
28- property : 'someProp'
29- } as any
30-
31- return replaceMap [ $1 ]
32- } )
32+ return out . replace ( pattern , ( match : string , $1 : string ) => this . locals [ $1 ] )
3333 }
3434
3535 private getFileList ( pathList : string [ ] ) : string [ ] {
@@ -91,7 +91,10 @@ class Scaffold {
9191const templateDir = process . cwd ( ) + '/examples'
9292const scf = new Scaffold ( {
9393 templates : [ templateDir + '/test-input/Component' ] ,
94- output : templateDir + '/test-output'
94+ output : templateDir + '/test-output' ,
95+ locals : {
96+ property : 'myProp'
97+ }
9598} )
9699
97100scf . run ( )
0 commit comments