Skip to content

Commit

Permalink
feat: migrate aloe to fs v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Nov 11, 2024
1 parent fe9ce26 commit f28e2a2
Show file tree
Hide file tree
Showing 39 changed files with 404 additions and 321 deletions.
4 changes: 1 addition & 3 deletions src/Command/AuthScaffoldCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Aloe\Command;

use Aloe\Installer;
use Leaf\FS;
use Illuminate\Support\Str;

class AuthScaffoldCommand extends \Aloe\Command
Expand Down Expand Up @@ -34,7 +33,6 @@ protected function handle()
$installablesDir = $this->installable($driver);

Installer::magicCopy($installablesDir);
Installer::installRoutes("$installablesDir/app/routes/");

$this->info('Authentication generated successfully.');

Expand All @@ -43,6 +41,6 @@ protected function handle()

protected function installable($driver)
{
return dirname(__DIR__) . '/Scaffold/' . Str::studly($driver . 'Auth');
return dirname(__DIR__) . '/Scaffold/' . Str::studly("{$driver}Auth");
}
}
6 changes: 3 additions & 3 deletions src/Command/DevToolsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Aloe\Command;

use Aloe\Installer;
use Leaf\FS;
use Leaf\FS\Storage;

class DevToolsCommand extends \Aloe\Command
{
Expand All @@ -18,7 +18,7 @@ protected function handle()

$this->comment('Installing leaf devtools routes...');

$rootFile = FS::readFile(Config::rootPath(PublicPath('index.php')));
$rootFile = Storage::read(Config::rootPath(PublicPath('index.php')));
$rootFile = str_replace(
"/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -51,7 +51,7 @@ protected function handle()

$rootFile = str_replace("\n\n\n", "\n", $rootFile);

FS::writeFile(Config::rootPath(PublicPath('index.php')), $rootFile);
Storage::writeFile(Config::rootPath(PublicPath('index.php')), $rootFile);

$this->info('Leaf devtools installed successfully!');

Expand Down
1 change: 0 additions & 1 deletion src/Command/MailSetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Aloe\Command;

use Aloe\Installer;
use Leaf\FS;

class MailSetupCommand extends \Aloe\Command
{
Expand Down
117 changes: 25 additions & 92 deletions src/Command/ViewInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,13 @@ protected function installBlade($output)
};

if ($isMVCApp) {
$paths = require "$directory/config/paths.php";
$viewsPath = trim($paths['views'] ?? 'app/views', '/');

\Leaf\FS::superCopy(__DIR__ . '/themes/blade', "$directory/$viewsPath");
\Leaf\FS\Directory::copy(__DIR__ . '/themes/blade', $directory);

$viewConfig = require "$directory/config/view.php";
$viewConfig['viewEngine'] = '\Leaf\Blade';
file_put_contents("$directory/config/view.php", '<?php return ' . var_export($viewConfig, true) . ';');
} else {
\Leaf\FS::superCopy(__DIR__ . '/themes/blade', $directory);
\Leaf\FS\Directory::copy(__DIR__ . '/themes/blade', $directory);
}

$output->writeln("\n🎉 <info>Blade setup successfully.</info>");
Expand Down Expand Up @@ -116,8 +113,7 @@ protected function installBareUi($output)
$paths = require "$directory/config/paths.php";
$viewsPath = trim($paths['views'] ?? 'app/views', '/');

\Leaf\FS::superCopy(__DIR__ . '/themes/bareui/theme', "$directory/$viewsPath");
\Leaf\FS::superCopy(__DIR__ . '/themes/bareui/config', "$directory/config");
\Leaf\FS\Directory::copy(__DIR__ . '/themes/bareui', $directory);

if (file_exists("$directory/$viewsPath/index.blade.php")) {
unlink("$directory/$viewsPath/index.blade.php");
Expand Down Expand Up @@ -147,7 +143,7 @@ protected function installBareUi($output)
file_put_contents($indexFile, $index);
}
} else {
\Leaf\FS::superCopy(__DIR__ . '/themes/bareui', $directory);
\Leaf\FS\Directory::copy(__DIR__ . '/themes/bareui', $directory);
}

$output->writeln("\n🎉 <info>Bare UI setup successfully.</info>");
Expand Down Expand Up @@ -185,17 +181,10 @@ protected function installInertia($output)
$isMVCApp = $this->isMVCApp();
$isBladeProject = $this->isBladeProject();

foreach (glob(__DIR__ . '/themes/inertia/root/{,.}[!.,!..]*', GLOB_MARK | GLOB_BRACE) as $file) {
if (basename($file) === 'vite.config.js' && file_exists("$directory/vite.config.js")) {
continue;
}

if (is_file($file)) {
copy($file, rtrim($directory, '/') . '/' . basename($file));
} else {
\Leaf\FS::superCopy($file, rtrim($directory, '/') . '/' . basename($file));
}
}
\Leaf\FS\Directory::copy(
__DIR__ . '/themes/inertia/' . ($isBladeProject ? 'blade' : 'bare-ui'),
$directory
);

if (!$isMVCApp) {
$viteConfig = file_get_contents("$directory/vite.config.js");
Expand All @@ -205,14 +194,6 @@ protected function installInertia($output)
$viteConfig
);
file_put_contents("$directory/vite.config.js", $viteConfig);
} else {
$paths = require "$directory/config/paths.php";
$viewsPath = trim($paths['views'] ?? 'app/views', '/');

\Leaf\FS::superCopy(
(__DIR__ . '/themes/inertia/views/' . ($isBladeProject ? 'blade' : 'bare-ui')),
"$directory/$viewsPath"
);
}

$package = json_decode(file_get_contents("$directory/package.json"), true);
Expand Down Expand Up @@ -270,41 +251,10 @@ protected function installReact($output)
};
}

\Leaf\FS::superCopy(__DIR__ . '/themes/react/root', $directory);

if ($isMVCApp) {
$paths = require "$directory/config/paths.php";
$viewsPath = trim($paths['views'] ?? 'app/views', '/');
$routesPath = trim($paths['routes'] ?? 'app/routes', '/');

\Leaf\FS::superCopy(__DIR__ . '/themes/react/routes', "$directory/$routesPath");
\Leaf\FS::superCopy(
(__DIR__ . '/themes/react/views/' . ($isBladeProject ? 'blade' : 'bare-ui')),
"$directory/$viewsPath"
);
} else {
\Leaf\FS::superCopy(__DIR__ . '/themes/react/routes', $directory);
\Leaf\FS::superCopy(
(__DIR__ . '/themes/react/views/' . ($isBladeProject ? 'blade' : 'bare-ui')),
$directory
);

$viteConfig = file_get_contents("$directory/vite.config.js");
$viteConfig = str_replace(
"leaf({",
"leaf({\nhotFile: 'hot',",
$viteConfig
);
file_put_contents("$directory/vite.config.js", $viteConfig);

$inertiaView = file_get_contents("$directory/_inertia.$ext.php");
$inertiaView = str_replace(
'<?php echo vite([\'/js/app.jsx\', "/js/Pages/{$page[\'component\']}.jsx"]); ?>',
'<?php echo vite([\'js/app.jsx\', "js/Pages/{$page[\'component\']}.jsx"], \'/\'); ?>',
$inertiaView
);
file_put_contents("$directory/_inertia.$ext.php", $inertiaView);
}
\Leaf\FS\Directory::copy(
__DIR__ . '/themes/react/' . ($isBladeProject ? 'blade' : 'bare-ui'),
$directory
);

$package = json_decode(file_get_contents("$directory/package.json"), true);
$package['type'] = 'module';
Expand Down Expand Up @@ -350,24 +300,15 @@ protected function installTailwind($output)

$isMVCApp = $this->isMVCApp();

foreach (glob(__DIR__ . '/themes/tailwind/root/{,.}[!.,!..]*', GLOB_MARK | GLOB_BRACE) as $file) {
if (basename($file) === 'vite.config.js' && file_exists("$directory/vite.config.js")) {
continue;
}

if (is_file($file)) {
copy($file, rtrim($directory, '/') . '/' . basename($file));
} else {
\Leaf\FS::superCopy($file, rtrim($directory, '/') . '/' . basename($file));
}
}
\Leaf\FS\Directory::copy(
__DIR__ . '/themes/tailwind/',
$directory
);

if ($isMVCApp) {
$paths = require "$directory/config/paths.php";
$viewsPath = trim($paths['views'] ?? 'app/views', '/');

\Leaf\FS::superCopy(__DIR__ . '/themes/tailwind/view', "$directory/$viewsPath");

if (file_exists("$directory/app/views/js/app.js")) {
$jsApp = file_get_contents("$directory/app/views/js/app.js");
if (strpos($jsApp, "import '../css/app.css';") === false) {
Expand All @@ -382,8 +323,6 @@ protected function installTailwind($output)
}
}
} else {
\Leaf\FS::superCopy(__DIR__ . '/themes/tailwind/view', $directory);

$viteConfig = file_get_contents("$directory/vite.config.js");
$viteConfig = str_replace(
["hotFile: 'hot',", 'hotFile: "hot",'],
Expand All @@ -395,6 +334,7 @@ protected function installTailwind($output)
"leaf({\nhotFile: 'hot',",
$viteConfig
);

file_put_contents("$directory/vite.config.js", $viteConfig);

if (file_exists("$directory/js/app.js")) {
Expand Down Expand Up @@ -455,7 +395,7 @@ protected function installVite($output)
$isMVCApp = $this->isMVCApp();

if (!file_exists("$directory/vite.config.js")) {
\Leaf\FS::superCopy(__DIR__ . '/themes/vite', $directory);
\Leaf\FS\Directory::copy(__DIR__ . '/themes/vite', $directory);
}

if (!$isMVCApp) {
Expand Down Expand Up @@ -523,21 +463,14 @@ protected function installVue($output)
};
}

\Leaf\FS::superCopy(__DIR__ . '/themes/vue/root', $directory);

if ($isMVCApp) {
$paths = require "$directory/config/paths.php";
$viewsPath = trim($paths['views'] ?? 'app/views', '/');
$routesPath = trim($paths['routes'] ?? 'app/routes', '/');
\Leaf\FS\Directory::copy(
__DIR__ . '/themes/vue/' . ($isBladeProject ? 'blade' : 'bare-ui'),
$directory
);

\Leaf\FS::superCopy(__DIR__ . '/themes/vue/routes', "$directory/$routesPath");
\Leaf\FS::superCopy(
(__DIR__ . '/themes/vue/views/' . ($isBladeProject ? 'blade' : 'bare-ui')),
"$directory/$viewsPath"
);
} else {
\Leaf\FS::superCopy(__DIR__ . '/themes/vue/routes', $directory);
\Leaf\FS::superCopy(
if (!$isMVCApp) {
\Leaf\FS\Directory::copy(__DIR__ . '/themes/vue/routes', $directory);
\Leaf\FS\Directory::copy(
(__DIR__ . '/themes/vue/views/' . ($isBladeProject ? 'blade' : 'bare-ui')),
$directory
);
Expand Down
13 changes: 13 additions & 0 deletions src/Command/themes/react/blade/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'vite';
import leaf from '@leafphp/vite-plugin';
import react from '@vitejs/plugin-react';

export default defineConfig({
plugins: [
leaf({
input: ['app/views/js/app.jsx'],
refresh: true,
}),
react(),
],
});
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/Command/themes/vue/blade/app/routes/_frontend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

app()->get('/hello', function () {
inertia('Hello');
});
File renamed without changes.
20 changes: 20 additions & 0 deletions src/Command/themes/vue/blade/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from "vite";
import leaf from "@leafphp/vite-plugin";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
plugins: [
leaf({
input: ["app/views/js/app.jsx"],
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
],
});
50 changes: 26 additions & 24 deletions src/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Aloe;

use Leaf\FS;
use Aloe\Command\Config;
use Leaf\FS\Directory;

/**
* Aloe Installer
Expand All @@ -23,39 +23,41 @@ class Installer
*/
public static function magicCopy($installablesDir)
{
$installables = FS::listFolders($installablesDir);
// $installables = FS::listFolders($installablesDir);

foreach ($installables as $installableDir) {
$dir = FS::listDir($installableDir);
$trueDir = str_replace($installablesDir, '', $installableDir);
// foreach ($installables as $installableDir) {
// $dir = FS::listDir($installableDir);
// $trueDir = str_replace($installablesDir, '', $installableDir);

foreach ($dir as $installable) {
FS::superCopy(
"$installableDir/$installable",
Config::rootpath("$trueDir/$installable")
);
}
}
// foreach ($dir as $installable) {
// FS::superCopy(
// "$installableDir/$installable",
// Config::rootpath("$trueDir/$installable")
// );
// }
// }

Directory::copy($installablesDir, Config::rootpath());
}

/**
* Install routes from routes folder into leaf workspace
*/
public static function installRoutes($routesDir, $routeFile = 'index.php')
{
$routeHome = Config::rootpath(RoutesPath($routeFile));
$routeData = FS::readFile($routeHome);
$routes = FS::listDir($routesDir);
// $routeHome = Config::rootpath(RoutesPath($routeFile));
// $routeData = FS::readFile($routeHome);
// $routes = FS::listDir($routesDir);

foreach ($routes as $route) {
$data = str_replace(
"require __DIR__ . '/$route';",
"",
$routeData
);
FS::writeFile($routeHome, $data);
FS::append($routeHome, "require __DIR__ . '/$route';");
}
// foreach ($routes as $route) {
// $data = str_replace(
// "require __DIR__ . '/$route';",
// "",
// $routeData
// );
// FS::writeFile($routeHome, $data);
// FS::append($routeHome, "require __DIR__ . '/$route';");
// }
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Package
* ----
* Meta info on aloe cli
*
*
* @since 1.2.4
*/
class Package
Expand Down
Loading

0 comments on commit f28e2a2

Please sign in to comment.