@@ -289,31 +289,33 @@ async function handleConfigCopy(options: Options) {
289289}
290290
291291/**
292- * Copy template if no .ts files in src/ .
292+ * Handle putting template files in place .
293293 */
294- export async function handleTemplate ( ) {
294+ async function handleTemplate ( ) {
295295 const cwd = process . cwd ( ) ;
296- const sourceDirName = path . join ( __dirname , '../../template' ) ;
297- const targetDirName = path . join ( cwd , 'src' ) ;
296+ const templates = path . join ( __dirname , '../../template' ) ;
298297
299- try {
300- fs . mkdirSync ( targetDirName ) ;
301- } catch ( e ) {
302- const err = e as Error & { code ?: string } ;
303- if ( err . code !== 'EEXIST' ) {
304- throw err ;
305- }
306- }
298+ const items = await fs . readdir ( templates ) ;
307299
308- // Only install the template if no ts files exist in target directory.
309- const files = fs . readdirSync ( targetDirName ) ;
310- const tsFiles = files . filter ( ( file : string ) =>
311- file . toLowerCase ( ) . endsWith ( '.ts' )
312- ) ;
300+ for ( const item of items ) {
301+ const targetDirName = path . join ( cwd , item ) ;
302+
303+ // Create folder
304+ fs . mkdirSync ( targetDirName , { recursive : true } ) ;
313305
314- if ( tsFiles . length === 0 ) {
315- console . log ( `${ chalk . green ( '\u2714' ) } ` , 'Installing default template...' ) ;
316- fs . copySync ( sourceDirName , targetDirName , { overwrite : false } ) ;
306+ // Only install the template if no ts files exist in target directory.
307+ const files = fs . readdirSync ( targetDirName ) ;
308+ const tsFiles = files . filter ( ( file : string ) =>
309+ file . toLowerCase ( ) . endsWith ( '.ts' )
310+ ) ;
311+
312+ // Copy files
313+ if ( tsFiles . length === 0 ) {
314+ console . log ( `${ chalk . green ( '\u2714' ) } ` , `Installing ${ item } template...` ) ;
315+ await fs . copy ( path . join ( templates , item ) , targetDirName , {
316+ overwrite : false ,
317+ } ) ;
318+ }
317319 }
318320}
319321
0 commit comments