From e73fe85c29606de0a8e0dbe3ed5893707e01b7d0 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 25 Dec 2024 07:09:03 +0800 Subject: [PATCH] feature: Add `tsconfig` action to `nova:devtool` command (#11) * wip Signed-off-by: Mior Muhammad Zaki * feature: Add `tsconfig` action to `nova:devtool` command Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- src/Console/DevToolCommand.php | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Console/DevToolCommand.php b/src/Console/DevToolCommand.php index 25205ec..87356dd 100644 --- a/src/Console/DevToolCommand.php +++ b/src/Console/DevToolCommand.php @@ -9,6 +9,7 @@ use Illuminate\Foundation\PackageManifest; use Illuminate\Support\Str; use InvalidArgumentException; +use Orchestra\Testbench\Foundation\Console\Actions\GeneratesFile; use Symfony\Component\Console\Attribute\AsCommand; use function Illuminate\Filesystem\join_paths; @@ -41,10 +42,11 @@ public function handle(Filesystem $filesystem, PackageManifest $manifest): int } return match ($action = $this->argument('action')) { - 'setup' => $this->setupNovaWorkbench($filesystem, $manifest), + 'setup' => $this->installNovaWorkbench($filesystem, $manifest), 'install' => $this->installNpmDependencies($filesystem, $manifest), 'enable-vue-devtool' => $this->enablesVueDevTool($filesystem, $manifest), 'disable-vue-devtool' => $this->disablesVueDevTool($filesystem, $manifest), + 'tsconfig' => $this->installTypeScriptConfiguration($filesystem, $manifest), default => throw new InvalidArgumentException(sprintf('Unable to handle [%s] action', $action)), }; } @@ -52,7 +54,7 @@ public function handle(Filesystem $filesystem, PackageManifest $manifest): int /** * Setup Nova Workbench. */ - protected function setupNovaWorkbench(Filesystem $filesystem, PackageManifest $manifest): int + protected function installNovaWorkbench(Filesystem $filesystem, PackageManifest $manifest): int { $this->executeCommand([ 'npm set progress=false', @@ -64,6 +66,24 @@ protected function setupNovaWorkbench(Filesystem $filesystem, PackageManifest $m ]); } + /** + * Install `tsconfig.json` configuration. + */ + protected function installTypeScriptConfiguration(Filesystem $filesystem, PackageManifest $manifest): int + { + (new GeneratesFile( + filesystem: $filesystem, + components: $this->components, + force: false, + confirmation: true, + ))->handle( + join_paths(__DIR__, 'stubs', 'tsconfig.json'), + package_path('tsconfig.json') + ); + + return self::SUCCESS; + } + /** * Install NPM dependencies. */ @@ -101,8 +121,6 @@ protected function installNpmDependencies(Filesystem $filesystem, PackageManifes 'npm install --dev '.implode(' ', $dependencies), ], package_path()); - $filesystem->copy(join_paths(__DIR__, 'stubs', 'tsconfig.json'), package_path('tsconfig.json')); - if (in_array('tailwindcss', $dependencies)) { $filesystem->copy(join_paths(__DIR__, 'stubs', 'postcss.config.js'), package_path('postcss.config.js')); $filesystem->copy(join_paths(__DIR__, 'stubs', 'tailwind.config.js'), package_path('tailwind.config.js')); @@ -113,7 +131,7 @@ protected function installNpmDependencies(Filesystem $filesystem, PackageManifes ], package_path('tailwind.config.js')); } - return self::SUCCESS; + return $this->installTypeScriptConfiguration($filesystem, $manifest); } /** @@ -188,6 +206,7 @@ protected function promptForMissingArgumentsUsing(): array 'install' => 'Install NPM Dependencies', 'enable-vue-devtool' => 'Enable Vue DevTool', 'disable-vue-devtool' => 'Disable Vue DevTool', + 'tsconfig' => 'Install `tsconfig.json` for Nova', ]), default: 'owner' ),