Skip to content

Commit cfe1564

Browse files
authored
feat(vite): add Tailwind CSS option to the installer (tempestphp#926)
1 parent 2a2c454 commit cfe1564

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

src/Tempest/Core/src/Commands/InstallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __invoke(?string $installer = null): void
3535
return;
3636
}
3737

38-
if (! $this->confirm("Running the <em>{$installer->name}</em> installer, continue?")) {
38+
if (! $this->confirm("Running the <em>{$installer->name}</em> installer, continue?", default: true)) {
3939
$this->error('Aborted.');
4040

4141
return;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'tailwindcss';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './main.css'
2+
3+
console.log('🌊')
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from 'vite'
2+
import tempest from 'vite-plugin-tempest'
3+
import tailwindcss from '@tailwindcss/vite'
4+
5+
export default defineConfig({
6+
plugins: [
7+
tailwindcss(),
8+
tempest(),
9+
],
10+
})

src/Tempest/Vite/src/Installer/Vanilla/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import tempest from 'vite-plugin-tempest'
44
export default defineConfig({
55
plugins: [
66
tempest(),
7-
]
7+
],
88
})

src/Tempest/Vite/src/Installer/ViteInstaller.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Tempest\Vite\Installer;
66

7+
use Tempest\Console\Input\ConsoleArgumentBag;
78
use Tempest\Core\Installer;
89
use Tempest\Core\PublishesFiles;
910
use 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

Comments
 (0)