44
55namespace Tempest \Vite \Installer ;
66
7+ use Tempest \Console \Input \ConsoleArgumentBag ;
78use Tempest \Core \Installer ;
89use Tempest \Core \PublishesFiles ;
910use Tempest \Support \JavaScript \DependencyInstaller ;
@@ -23,24 +24,47 @@ final class ViteInstaller implements Installer
2324 public function __construct (
2425 private readonly DependencyInstaller $ javascript ,
2526 private readonly ViteConfig $ viteConfig ,
27+ private readonly ConsoleArgumentBag $ consoleArgumentBag ,
2628 ) {
2729 }
2830
31+ private function shouldInstallTailwind (): bool
32+ {
33+ $ argument = $ this ->consoleArgumentBag ->get ('tailwind ' );
34+
35+ if ($ argument === null || !is_bool ($ argument ->value )) {
36+ return $ this ->console ->confirm ('Install Tailwind CSS as well? ' , default: true );
37+ }
38+
39+ return (bool ) $ argument ->value ;
40+ }
41+
2942 public function install (): void
3043 {
44+ $ shouldInstallTailwind = $ this ->shouldInstallTailwind ();
45+ $ templateDirectory = $ shouldInstallTailwind
46+ ? 'Tailwind '
47+ : 'Vanilla ' ;
48+
3149 // Installs the dependencies
3250 $ this ->javascript ->installDependencies (
3351 cwd: root_path (),
3452 dependencies: [
3553 'vite ' ,
3654 'vite-plugin-tempest ' ,
55+ ...($ shouldInstallTailwind ? ['tailwindcss ' , '@tailwindcss/vite ' ] : [])
3756 ],
3857 dev: true ,
3958 );
4059
4160 // Publishes the Vite config
42- $ viteConfig = $ this ->publish (__DIR__ . '/Vanilla/vite.config.ts ' , destination: root_path ('vite.config.ts ' ));
43- $ main = $ this ->publish (__DIR__ . '/Vanilla/main.ts ' , destination: src_path ('main.ts ' ));
61+ $ viteConfig = $ this ->publish (__DIR__ . "/ {$ templateDirectory }/vite.config.ts " , destination: root_path ('vite.config.ts ' ));
62+ $ main = $ this ->publish (__DIR__ . "/ {$ templateDirectory }/main.ts " , destination: src_path ('main.ts ' ));
63+
64+ // Publishes Tailwind's `main.css` file if requested
65+ if ($ shouldInstallTailwind ) {
66+ $ this ->publish (__DIR__ . "/ {$ templateDirectory }/main.css " , destination: src_path ('main.css ' ));
67+ }
4468
4569 // Install package.json scripts
4670 $ this ->updateJson (root_path ('package.json ' ), function (array $ json ) {
@@ -75,7 +99,9 @@ public function install(): void
7599 $ packageManager = PackageManager::detect (root_path ());
76100
77101 $ this ->console ->instructions ([
78- '<strong>Vite is now installed in your project</strong>! ' ,
102+ $ shouldInstallTailwind
103+ ? '<strong>Vite and Tailwind CSS are now installed in your project</strong>! '
104+ : '<strong>Vite is now installed in your project</strong>! ' ,
79105 PHP_EOL ,
80106 $ main
81107 ? "Add <code> \\Tempest \\vite_tags(' {$ main }')</code> to your template "
0 commit comments