@@ -427,6 +427,142 @@ describe("alepha init", () => {
427427 } ) ;
428428 } ) ;
429429
430+ // ─────────────────────────────────────────────────────────────────────────────
431+ // Tailwind CSS (--tailwind flag)
432+ // ─────────────────────────────────────────────────────────────────────────────
433+
434+ describe ( "--tailwind flag" , ( ) => {
435+ it ( "should add tailwindcss devDependencies" , async ( ) => {
436+ const { fs, cli, cmd, json } = createTestEnv ( ) ;
437+ await setupProject ( fs , json ) ;
438+
439+ await cli . run ( cmd . init , { argv : "--tailwind" , root : "/project" } ) ;
440+
441+ const pkg = await fs . readJsonFile < {
442+ devDependencies ?: Record < string , string > ;
443+ } > ( "/project/package.json" ) ;
444+ expect ( pkg . devDependencies ?. tailwindcss ) . toBeDefined ( ) ;
445+ expect ( pkg . devDependencies ?. [ "@tailwindcss/vite" ] ) . toBeDefined ( ) ;
446+ } ) ;
447+
448+ it ( "should create vite.config.ts with tailwind plugin" , async ( ) => {
449+ const { fs, cli, cmd, json } = createTestEnv ( ) ;
450+ await setupProject ( fs , json ) ;
451+
452+ await cli . run ( cmd . init , { argv : "--tailwind" , root : "/project" } ) ;
453+
454+ expect ( fs . wasWritten ( "/project/vite.config.ts" ) ) . toBe ( true ) ;
455+ expect (
456+ fs . wasWrittenMatching ( "/project/vite.config.ts" , / t a i l w i n d c s s / ) ,
457+ ) . toBe ( true ) ;
458+ expect (
459+ fs . wasWrittenMatching ( "/project/vite.config.ts" , / @ t a i l w i n d c s s \/ v i t e / ) ,
460+ ) . toBe ( true ) ;
461+ expect (
462+ fs . wasWrittenMatching ( "/project/vite.config.ts" , / d e f i n e C o n f i g / ) ,
463+ ) . toBe ( true ) ;
464+ } ) ;
465+
466+ it ( "should add @import tailwindcss to main.css" , async ( ) => {
467+ const { fs, cli, cmd, json } = createTestEnv ( ) ;
468+ await setupProject ( fs , json ) ;
469+
470+ await cli . run ( cmd . init , { argv : "--tailwind" , root : "/project" } ) ;
471+
472+ expect ( fs . wasWritten ( "/project/src/main.css" ) ) . toBe ( true ) ;
473+ expect (
474+ fs . wasWrittenMatching ( "/project/src/main.css" , / @ i m p o r t " t a i l w i n d c s s " / ) ,
475+ ) . toBe ( true ) ;
476+ } ) ;
477+
478+ it ( "should imply --react" , async ( ) => {
479+ const { fs, cli, cmd, json } = createTestEnv ( ) ;
480+ await setupProject ( fs , json ) ;
481+
482+ await cli . run ( cmd . init , { argv : "--tailwind" , root : "/project" } ) ;
483+
484+ // React web structure should be created
485+ expect ( fs . wasWritten ( "/project/src/web/index.ts" ) ) . toBe ( true ) ;
486+ expect ( fs . wasWritten ( "/project/src/main.browser.ts" ) ) . toBe ( true ) ;
487+ } ) ;
488+
489+ it ( "should not create vite.config.ts without --tailwind" , async ( ) => {
490+ const { fs, cli, cmd, json } = createTestEnv ( ) ;
491+ await setupProject ( fs , json ) ;
492+
493+ await cli . run ( cmd . init , { argv : "--react" , root : "/project" } ) ;
494+
495+ expect ( fs . wasWritten ( "/project/vite.config.ts" ) ) . toBe ( false ) ;
496+ } ) ;
497+ } ) ;
498+
499+ // ─────────────────────────────────────────────────────────────────────────────
500+ // Non-empty directory guard (codegen flags)
501+ // ─────────────────────────────────────────────────────────────────────────────
502+
503+ describe ( "non-empty directory guard" , ( ) => {
504+ it ( "should reject codegen into non-empty directory" , async ( ) => {
505+ const { fs, cli, cmd, json } = createTestEnv ( ) ;
506+ await setupProject ( fs , json ) ;
507+ await fs . writeFile ( "/project/src/existing.ts" , "export {}" ) ;
508+
509+ await expect (
510+ cli . run ( cmd . init , { argv : "--api" , root : "/project" } ) ,
511+ ) . rejects . toThrowError ( / T a r g e t d i r e c t o r y i s n o t e m p t y / ) ;
512+ } ) ;
513+
514+ it ( "should allow codegen when only package.json exists" , async ( ) => {
515+ const { fs, cli, cmd, json } = createTestEnv ( ) ;
516+ await setupProject ( fs , json ) ;
517+
518+ await cli . run ( cmd . init , { argv : "--api" , root : "/project" } ) ;
519+
520+ expect ( fs . wasWritten ( "/project/src/api/index.ts" ) ) . toBe ( true ) ;
521+ } ) ;
522+
523+ it ( "should allow codegen into non-empty directory with --force" , async ( ) => {
524+ const { fs, cli, cmd, json } = createTestEnv ( ) ;
525+ await setupProject ( fs , json ) ;
526+ await fs . writeFile ( "/project/src/existing.ts" , "export {}" ) ;
527+
528+ await cli . run ( cmd . init , {
529+ argv : "--api --force" ,
530+ root : "/project" ,
531+ } ) ;
532+
533+ expect ( fs . wasWritten ( "/project/src/api/index.ts" ) ) . toBe ( true ) ;
534+ } ) ;
535+
536+ it ( "should allow non-codegen init in non-empty directory" , async ( ) => {
537+ const { fs, cli, cmd, json } = createTestEnv ( ) ;
538+ await setupProject ( fs , json ) ;
539+ await fs . writeFile ( "/project/src/existing.ts" , "export {}" ) ;
540+
541+ // No codegen flags — should not throw
542+ await cli . run ( cmd . init , { root : "/project" } ) ;
543+
544+ expect ( fs . wasWritten ( "/project/tsconfig.json" ) ) . toBe ( true ) ;
545+ } ) ;
546+
547+ it ( "should check each codegen flag independently" , async ( ) => {
548+ for ( const flag of [
549+ "--react" ,
550+ "--ui" ,
551+ "--auth" ,
552+ "--admin" ,
553+ "--tailwind" ,
554+ ] ) {
555+ const { fs, cli, cmd, json } = createTestEnv ( ) ;
556+ await setupProject ( fs , json ) ;
557+ await fs . writeFile ( "/project/src/existing.ts" , "export {}" ) ;
558+
559+ await expect (
560+ cli . run ( cmd . init , { argv : flag , root : "/project" } ) ,
561+ ) . rejects . toThrowError ( / T a r g e t d i r e c t o r y i s n o t e m p t y / ) ;
562+ }
563+ } ) ;
564+ } ) ;
565+
430566 // ─────────────────────────────────────────────────────────────────────────────
431567 // Path Argument
432568 // ─────────────────────────────────────────────────────────────────────────────
0 commit comments