@@ -31,31 +31,42 @@ export async function Scaffold(config: ScaffoldConfig) {
3131 for ( let template of config . templates ) {
3232 try {
3333 // try {
34- const tplStat = await stat ( template )
35- if ( tplStat . isDirectory ( ) ) {
34+ const _isDir = await isDir ( template )
35+ const basePath = path
36+ . resolve ( process . cwd ( ) , _isDir ? template : path . dirname ( template . replace ( "*" , "" ) . replace ( "//" , "/" ) ) )
37+ . replace ( process . cwd ( ) , "." )
38+ if ( _isDir ) {
3639 template = template + "/**/*"
3740 }
38- // } catch (e) {
41+ // } catch (e: any ) {
3942 // if (e.code !== "ENOENT") {
4043 // throw e
4144 // }
4245 // }
43- const files = await promisify ( glob ) ( template , { dot : true } )
46+ const files = await promisify ( glob ) ( template , { dot : true , debug : false } )
4447 for ( const templatePath of files ) {
45- await handleTemplateFile ( templatePath , options , data )
48+ if ( ! ( await isDir ( templatePath ) ) ) {
49+ await handleTemplateFile ( templatePath , basePath , options , data )
50+ }
4651 }
47- } catch ( e ) {
52+ } catch ( e : any ) {
4853 handleErr ( e )
4954 }
5055 }
51- } catch ( e ) {
56+ } catch ( e : any ) {
5257 console . error ( e )
5358 throw e
5459 }
5560}
5661
62+ async function isDir ( path : string ) : Promise < boolean > {
63+ const tplStat = await stat ( path )
64+ return tplStat . isDirectory ( )
65+ }
66+
5767async function handleTemplateFile (
5868 templatePath : string ,
69+ basePath : string ,
5970 options : ScaffoldConfig ,
6071 data : Record < string , string >
6172) : Promise < void > {
@@ -92,7 +103,7 @@ async function handleTemplateFile(
92103 log ( options , `File ${ outputPath } already exists, skipping` )
93104 }
94105 resolve ( )
95- } catch ( e ) {
106+ } catch ( e : any ) {
96107 handleErr ( e )
97108 reject ( e )
98109 }
0 commit comments