1- import { basename , dirname , resolve } from 'node:path'
1+ import { basename , resolve } from 'node:path'
22import { fileURLToPath } from 'node:url'
33import { log , outro , spinner } from '@clack/prompts'
44import { render } from 'ejs'
@@ -10,7 +10,7 @@ import { sortObject } from './utils.js'
1010import { writeConfigFile } from './config-file.js'
1111import { packageManagerExecute } from './package-manager.js'
1212
13- import type { Environment , Options } from './types.js'
13+ import type { AddOn , Environment , Options } from './types.js'
1414
1515function createCopyFiles ( environment : Environment , targetDir : string ) {
1616 return async function copyFiles (
@@ -342,6 +342,34 @@ export async function createApp(
342342 const isAddOnEnabled = ( id : string ) =>
343343 options . chosenAddOns . find ( ( a ) => a . id === id )
344344
345+ async function runAddOn ( addOn : AddOn ) {
346+ if ( addOn . files ) {
347+ for ( const file of Object . keys ( addOn . files ) ) {
348+ await copyAddOnFile (
349+ environment ,
350+ addOn . files [ file ] ,
351+ file ,
352+ resolve ( targetDir , file ) ,
353+ ( content , targetFileName ) =>
354+ templateFileFromContent ( targetFileName , content ) ,
355+ )
356+ }
357+ }
358+ if ( addOn . deletedFiles ) {
359+ for ( const file of addOn . deletedFiles ) {
360+ await environment . deleteFile ( resolve ( targetDir , file ) )
361+ }
362+ }
363+
364+ if ( addOn . command && addOn . command . command ) {
365+ await environment . execute (
366+ addOn . command . command ,
367+ addOn . command . args || [ ] ,
368+ resolve ( targetDir ) ,
369+ )
370+ }
371+ }
372+
345373 // Setup the .vscode directory
346374 switch ( options . toolchain ) {
347375 case 'biome' :
@@ -437,33 +465,15 @@ export async function createApp(
437465
438466 // Copy all the asset files from the addons
439467 const s = silent ? null : spinner ( )
440- for ( const phase of [ 'setup' , 'add-on' , 'example' ] ) {
441- for ( const addOn of options . chosenAddOns . filter (
442- ( addOn ) => addOn . phase === phase ,
443- ) ) {
444- s ?. start ( `Setting up ${ addOn . name } ...` )
445- if ( addOn . files ) {
446- for ( const file of Object . keys ( addOn . files ) ) {
447- await copyAddOnFile (
448- environment ,
449- addOn . files [ file ] ,
450- file ,
451- resolve ( targetDir , file ) ,
452- ( content , targetFileName ) =>
453- templateFileFromContent ( targetFileName , content ) ,
454- )
455- }
456- }
457-
458- if ( addOn . command ) {
459- await environment . execute (
460- addOn . command . command ,
461- addOn . command . args || [ ] ,
462- resolve ( targetDir ) ,
463- )
468+ for ( const type of [ 'add-on' , 'example' ] ) {
469+ for ( const phase of [ 'setup' , 'add-on' ] ) {
470+ for ( const addOn of options . chosenAddOns . filter (
471+ ( addOn ) => addOn . phase === phase && addOn . type === type ,
472+ ) ) {
473+ s ?. start ( `Setting up ${ addOn . name } ...` )
474+ await runAddOn ( addOn )
475+ s ?. stop ( `${ addOn . name } setup complete` )
464476 }
465-
466- s ?. stop ( `${ addOn . name } setup complete` )
467477 }
468478 }
469479
@@ -654,6 +664,15 @@ export async function createApp(
654664 // Create the README.md
655665 await templateFile ( templateDirBase , 'README.md.ejs' )
656666
667+ // Adding overlays
668+ for ( const addOn of options . chosenAddOns . filter (
669+ ( addOn ) => addOn . type === 'overlay' ,
670+ ) ) {
671+ s ?. start ( `Setting up overlay ${ addOn . name } ...` )
672+ await runAddOn ( addOn )
673+ s ?. stop ( `Overlay ${ addOn . name } setup complete` )
674+ }
675+
657676 // Install dependencies
658677 s ?. start ( `Installing dependencies via ${ options . packageManager } ...` )
659678 await environment . execute (
0 commit comments