Skip to content

Commit

Permalink
feature: Add tsconfig action to nova:devtool command (#11)
Browse files Browse the repository at this point in the history
* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* feature: Add `tsconfig` action to `nova:devtool` command

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone authored Dec 24, 2024
1 parent 83e6fad commit e73fe85
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/Console/DevToolCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,18 +42,19 @@ 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)),
};
}

/**
* 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',
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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'));
Expand All @@ -113,7 +131,7 @@ protected function installNpmDependencies(Filesystem $filesystem, PackageManifes
], package_path('tailwind.config.js'));
}

return self::SUCCESS;
return $this->installTypeScriptConfiguration($filesystem, $manifest);
}

/**
Expand Down Expand Up @@ -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'
),
Expand Down

0 comments on commit e73fe85

Please sign in to comment.