Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Phaseolies/Console/Commands/FrontendInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function handle(): int

$framework = strtolower($this->choice(
'Which client framework do you want to use?',
['Vanilla', 'React', 'Vue', 'Svelte'],
['Vanilla', 'React', 'Vue', 'Svelte', 'htmx'],
0
));

Expand Down Expand Up @@ -148,7 +148,7 @@ protected function writeFrontendFiles(array $options, array &$state): void
base_path('package.json') => $this->packageJson($framework, $cssStack, $typescript),
base_path('vite.config.js') => $this->viteConfig($framework, $typescript),
client_path('css/app.css') => $this->clientCss($cssStack),
client_path('js/' . $this->bootstrapFilename($typescript)) => $this->bootstrapFile($cssStack, $typescript),
client_path('js/' . $this->bootstrapFilename($typescript)) => $this->bootstrapFile($cssStack, $typescript, $framework),
client_path('js/' . $this->entryFilename($framework, $typescript)) => $this->entryFile($framework, $cssStack, $typescript),
base_path('resources/views/layouts/app.odo.php') => $this->appLayoutView($framework, $typescript),
base_path('resources/views/welcome.odo.php') => $this->welcomeView($framework, $typescript),
Expand Down Expand Up @@ -320,7 +320,7 @@ protected function entryFilename(string $framework, bool $typescript): string
return $typescript ? 'main.tsx' : 'main.jsx';
}

if (in_array($framework, ['vue', 'svelte'], true)) {
if (in_array($framework, ['vue', 'svelte', 'htmx'], true)) {
return $typescript ? 'main.ts' : 'main.js';
}

Expand Down Expand Up @@ -362,6 +362,10 @@ protected function packageJson(string $framework, string $cssStack, bool $typesc
$dependencies['bootstrap'] = '^5.3.3';
}

if ($framework === 'htmx') {
$dependencies['htmx.org'] = '^2.0.9';
}

if ($cssStack === 'tailwind') {
$devDependencies['postcss'] = '^8.4.49';
$devDependencies['tailwindcss'] = '^4.0.0';
Expand Down Expand Up @@ -475,18 +479,23 @@ protected function frameworkComponentFiles(string $framework, bool $typescript):
*
* @param string $cssStack
* @param bool $typescript
* @param string $framework
* @return string
*/
protected function bootstrapFile(string $cssStack, bool $typescript): string
protected function bootstrapFile(string $cssStack, bool $typescript, string $framework = 'vanilla'): string
{
$bootstrapVendorImport = $cssStack === 'bootstrap'
? "import 'bootstrap/dist/js/bootstrap.bundle.min.js';\n"
: '';
$htmxVendorImport = $framework === 'htmx'
? "import 'htmx.org';\n"
: '';

return $this->renderFrontendStub(
'entries/' . ($typescript ? 'bootstrap.ts.stub' : 'bootstrap.js.stub'),
[
'bootstrapVendorImport' => $bootstrapVendorImport,
'htmxVendorImport' => $htmxVendorImport,
]
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Phaseolies/Console/Commands/FrontendUninstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ protected function isGeneratedPackageJson(string $contents): bool
'react-dom',
'vue',
'svelte',
'htmx.org',
'bootstrap',
'postcss',
'tailwindcss',
Expand Down Expand Up @@ -399,4 +400,5 @@ protected function isGeneratedPostcssConfig(string $contents): bool
return str_contains($contents, "export default")
&& str_contains($contents, "'@tailwindcss/postcss': {}");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ window.__DOPPAR_FRONTEND__ = {
csrfToken: csrfToken ?? null,
headers: csrfToken ? { 'X-CSRF-TOKEN': csrfToken } : {},
};
{{ htmxVendorImport }}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ declare global {
};
}
}
{{ htmxVendorImport }}
2 changes: 1 addition & 1 deletion tests/Console/FrontendInstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testClientBootstrapExposesCsrfHeaderFromMetaToken(): void
$command = new FrontendInstallCommand();
$method = new \ReflectionMethod($command, 'bootstrapFile');

$bootstrap = $method->invoke($command, 'bootstrap', true);
$bootstrap = $method->invoke($command, 'bootstrap', 'vanilla', true);

$this->assertStringContainsString("meta[name=\"csrf-token\"]", $bootstrap);
$this->assertStringContainsString("headers: csrfToken ? { 'X-CSRF-TOKEN': csrfToken } : {}", $bootstrap);
Expand Down
Loading