1
- import { basename , dirname , resolve } from 'node:path'
1
+ import { basename , resolve } from 'node:path'
2
2
import { fileURLToPath } from 'node:url'
3
3
import { log , outro , spinner } from '@clack/prompts'
4
4
import { render } from 'ejs'
@@ -10,7 +10,7 @@ import { sortObject } from './utils.js'
10
10
import { writeConfigFile } from './config-file.js'
11
11
import { packageManagerExecute } from './package-manager.js'
12
12
13
- import type { Environment , Options } from './types.js'
13
+ import type { AddOn , Environment , Options } from './types.js'
14
14
15
15
function createCopyFiles ( environment : Environment , targetDir : string ) {
16
16
return async function copyFiles (
@@ -342,6 +342,34 @@ export async function createApp(
342
342
const isAddOnEnabled = ( id : string ) =>
343
343
options . chosenAddOns . find ( ( a ) => a . id === id )
344
344
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
+
345
373
// Setup the .vscode directory
346
374
switch ( options . toolchain ) {
347
375
case 'biome' :
@@ -437,33 +465,15 @@ export async function createApp(
437
465
438
466
// Copy all the asset files from the addons
439
467
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` )
464
476
}
465
-
466
- s ?. stop ( `${ addOn . name } setup complete` )
467
477
}
468
478
}
469
479
@@ -654,6 +664,15 @@ export async function createApp(
654
664
// Create the README.md
655
665
await templateFile ( templateDirBase , 'README.md.ejs' )
656
666
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
+
657
676
// Install dependencies
658
677
s ?. start ( `Installing dependencies via ${ options . packageManager } ...` )
659
678
await environment . execute (
0 commit comments