Skip to content
This repository was archived by the owner on Aug 8, 2025. It is now read-only.

Commit 8da18c8

Browse files
committed
add vue
1 parent 7b69a3e commit 8da18c8

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

php-saas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (file_exists(__DIR__.'/../../autoload.php')) {
77
require __DIR__.'/vendor/autoload.php';
88
}
99

10-
$app = new Symfony\Component\Console\Application('PHP-SaaS Cli', '0.6.0');
10+
$app = new Symfony\Component\Console\Application('PHP-SaaS Cli', '0.7.0');
1111
$app->add(new PHPSaaS\Cli\NewCommand);
1212

1313
$app->run();

src/NewCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function collectInputs(): void
120120
{
121121
$this->frontend = select('Which frontend stack would you like to use?', [
122122
'react' => 'React',
123-
'vue' => 'Vue (coming soon)',
123+
'vue' => 'Vue',
124124
], hint: 'The frontend stacks are integrated with Inertia.js');
125125

126126
$this->tests = select('Which testing framework would you like to use?', [

src/Traits/Frontend.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22

33
namespace PHPSaaS\Cli\Traits;
44

5-
use RuntimeException;
6-
75
trait Frontend
86
{
97
protected function setupFrontend(): void
108
{
11-
if ($this->frontend === 'vue') {
12-
throw new RuntimeException('Vue stack is not supported yet.');
13-
}
14-
159
$this->fileSystem->moveDirectory($this->tmpPath.'/'.$this->frontend.'/src', $this->path.'/resources/js');
1610

1711
$filesToCopy = [
@@ -24,10 +18,21 @@ protected function setupFrontend(): void
2418
foreach ($filesToCopy as $file) {
2519
$this->fileSystem->copy($this->tmpPath.'/'.$this->frontend.'/'.$file, $this->path.'/'.$file);
2620
}
21+
22+
$block = '@vite([\'resources/js/app.ts\', "resources/js/pages/{$page[\'component\']}.%s"])';
23+
$this->replaceBlocks(
24+
[
25+
'resources/views/app.blade.php',
26+
],
27+
'vite',
28+
sprintf($block, $this->frontend === 'react' ? 'tsx' : 'vue'),
29+
);
2730
}
2831

2932
protected function cleanupFrontend(): void
3033
{
31-
//
34+
$this->removeBlockTags([
35+
'resources/views/app.blade.php',
36+
], 'vite');
3237
}
3338
}

src/Traits/InteractWithBlocks.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,34 @@ protected function removeBlockTags(array $files, string $block): int
8181

8282
return $tagsRemoved;
8383
}
84+
85+
protected function replaceBlocks(array $files, string $block, string $replacement): void
86+
{
87+
foreach ($files as $file) {
88+
$filePath = $this->path.'/'.$file;
89+
90+
if (! file_exists($filePath)) {
91+
continue;
92+
}
93+
94+
$content = file_get_contents($filePath);
95+
96+
$patterns = [
97+
// PHP comments
98+
"/\/\/ <php-saas:{$block}>.*?\/\/ <\/php-saas:{$block}>\n?/s",
99+
// JSX/TSX comments
100+
"/\{\s*\/\*<php-saas:{$block}>\*\/\s*\}.*?\{\s*\/\*<\/php-saas:{$block}>\*\/\s*\}\n?/s",
101+
// HTML comments
102+
"/<!--<php-saas:{$block}>-->.*?<!--<\/php-saas:{$block}>-->\n?/s",
103+
// .env comments
104+
"/# <php-saas:{$block}>.*?# <\/php-saas:{$block}>\n?/s",
105+
];
106+
107+
$newContent = preg_replace($patterns, $replacement, $content);
108+
109+
if ($newContent !== $content) {
110+
file_put_contents($filePath, $newContent);
111+
}
112+
}
113+
}
84114
}

0 commit comments

Comments
 (0)