@@ -41,7 +41,7 @@ export async function Scaffold({ ...options }: ScaffoldConfig) {
4141 log ( options , LogLevel . Info , "Data:" , options . data )
4242 for ( let template of options . templates ) {
4343 try {
44- const _isGlob = template . includes ( "*" )
44+ const _isGlob = glob . hasMagic ( template )
4545 if ( ! _isGlob && ! ( await pathExists ( template ) ) ) {
4646 const err : NodeJS . ErrnoException = new Error ( `ENOENT, no such file or directory ${ template } ` )
4747 err . code = "ENOENT"
@@ -61,37 +61,34 @@ export async function Scaffold({ ...options }: ScaffoldConfig) {
6161 log ( options , LogLevel . Debug , "before glob" )
6262 const files = await promisify ( glob ) ( template , {
6363 dot : true ,
64- debug : false ,
65- nodir : options . verbose === LogLevel . Debug ,
66- nobrace : true ,
67- noext : true ,
68- nocomment : true ,
69- nonegate : true ,
64+ debug : options . verbose === LogLevel . Debug ,
65+ nodir : true ,
7066 } )
7167 log ( options , LogLevel . Debug , "after glob" )
7268 for ( const inputFilePath of files ) {
73- if ( ! ( await isDir ( inputFilePath ) ) ) {
74- const relPath = makeRelativePath ( path . dirname ( removeGlob ( inputFilePath ) . replace ( _nonGlobTemplate , "" ) ) )
75- const basePath = path
76- . resolve ( process . cwd ( ) , relPath )
77- . replace ( process . cwd ( ) + "/" , "" )
78- . replace ( process . cwd ( ) , "" )
79- log (
80- options ,
81- LogLevel . Debug ,
82- `\nprocess.cwd(): ${ process . cwd ( ) } ` ,
83- `\norigTemplate: ${ origTemplate } ` ,
84- `\nrelPath: ${ relPath } ` ,
85- `\ntemplate: ${ template } ` ,
86- `\ninputFilePath: ${ inputFilePath } ` ,
87- `\nnonGlobTemplate: ${ _nonGlobTemplate } ` ,
88- `\nbasePath: ${ basePath } ` ,
89- `\nisDir: ${ _isDir } ` ,
90- `\nisGlob: ${ _isGlob } ` ,
91- `\n`
92- )
93- await handleTemplateFile ( inputFilePath , basePath , options , options . data )
69+ if ( await isDir ( inputFilePath ) ) {
70+ continue
9471 }
72+ const relPath = makeRelativePath ( path . dirname ( removeGlob ( inputFilePath ) . replace ( _nonGlobTemplate , "" ) ) )
73+ const basePath = path
74+ . resolve ( process . cwd ( ) , relPath )
75+ . replace ( process . cwd ( ) + "/" , "" )
76+ . replace ( process . cwd ( ) , "" )
77+ log (
78+ options ,
79+ LogLevel . Debug ,
80+ `\nprocess.cwd(): ${ process . cwd ( ) } ` ,
81+ `\norigTemplate: ${ origTemplate } ` ,
82+ `\nrelPath: ${ relPath } ` ,
83+ `\ntemplate: ${ template } ` ,
84+ `\ninputFilePath: ${ inputFilePath } ` ,
85+ `\nnonGlobTemplate: ${ _nonGlobTemplate } ` ,
86+ `\nbasePath: ${ basePath } ` ,
87+ `\nisDir: ${ _isDir } ` ,
88+ `\nisGlob: ${ _isGlob } ` ,
89+ `\n`
90+ )
91+ await handleTemplateFile ( inputFilePath , basePath , options , options . data )
9592 }
9693 } catch ( e : any ) {
9794 handleErr ( e )
@@ -112,12 +109,12 @@ async function handleTemplateFile(
112109 return new Promise ( async ( resolve , reject ) => {
113110 try {
114111 const inputPath = path . resolve ( process . cwd ( ) , templatePath )
115- const outputPathOpt = getOptionValueForFile ( inputPath , data , options . output )
112+ const outputPathOpt = getOptionValueForFile ( options , inputPath , data , options . output )
116113 const outputDir = path . resolve (
117114 process . cwd ( ) ,
118115 ...( [ outputPathOpt , basePath , options . createSubFolder ? options . name : undefined ] . filter ( Boolean ) as string [ ] )
119116 )
120- const outputPath = handlebarsParse ( path . join ( outputDir , path . basename ( inputPath ) ) , data )
117+ const outputPath = handlebarsParse ( options , path . join ( outputDir , path . basename ( inputPath ) ) , data ) . toString ( )
121118 log (
122119 options ,
123120 LogLevel . Debug ,
@@ -129,7 +126,7 @@ async function handleTemplateFile(
129126 `\nFull output path: ${ outputPath } ` ,
130127 `\n`
131128 )
132- const overwrite = getOptionValueForFile ( inputPath , data , options . overwrite ?? false )
129+ const overwrite = getOptionValueForFile ( options , inputPath , data , options . overwrite ?? false )
133130 const exists = await pathExists ( outputPath )
134131
135132 await createDirIfNotExists ( path . dirname ( outputPath ) , options )
@@ -140,7 +137,7 @@ async function handleTemplateFile(
140137 log ( options , LogLevel . Info , `File ${ outputPath } exists, overwriting` )
141138 }
142139 const templateBuffer = await readFile ( inputPath )
143- const outputContents = handlebarsParse ( templateBuffer , data )
140+ const outputContents = handlebarsParse ( options , templateBuffer , data )
144141
145142 if ( ! options . dryRun ) {
146143 await writeFile ( outputPath , outputContents )
0 commit comments