Skip to content

Commit 83e6fad

Browse files
authored
feature: Command Improvements (#10)
* wip 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]> * 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]>
1 parent 5fdf845 commit 83e6fad

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

bin/sync

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Illuminate\Support\Collection::make([
3131

3232
$files->copy("{$workingPath}/vendor/laravel/nova/src/Console/stubs/base-resource.stub", "{$workingPath}/stubs/base-resource.stub");
3333
transform([
34-
"{{ namespace }}" => "Workbench\App\Nova",
34+
"{{ namespace }}" => "{{WorkbenchAppNamespace}}\Nova",
3535
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/stubs/base-resource.stub"));
3636

3737
$files->copy("{$workingPath}/vendor/laravel/nova/src/Console/stubs/main-dashboard.stub", "{$workingPath}/stubs/main-dashboard.stub");
@@ -40,15 +40,15 @@ transform([
4040
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/stubs/main-dashboard.stub"));
4141

4242
transform([
43-
"namespace App\Nova;" => "namespace Workbench\App\Nova;",
43+
"namespace App\Nova;" => "namespace {{WorkbenchAppNamespace}}\Nova;",
4444
"use Laravel\Nova\Fields\Gravatar;".PHP_EOL => "",
45-
"@var class-string<\App\Models\User>" => "@var class-string<\Workbench\App\Models\User>",
46-
" public static \$model = \App\Models\User::class;" => " public static \$model = \Workbench\App\Models\User::class;",
45+
"@var class-string<\App\Models\User>" => "@var class-string<\{{WorkbenchAppNamespace}}\Models\User>",
46+
" public static \$model = \App\Models\User::class;" => " public static \$model = \{{WorkbenchAppNamespace}}\Models\User::class;",
4747
" Gravatar::make()->maxWidth(50),".PHP_EOL.PHP_EOL => "",
4848
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/stubs/user-resource.stub"));
4949

5050
transform([
51-
"namespace App\Providers;" => "namespace Workbench\App\Providers;",
51+
"namespace App\Providers;" => "namespace {{WorkbenchAppNamespace}}\Providers;",
5252
PHP_EOL."use App\Models\User;" => "",
5353
"use Laravel\Nova\Nova;" => "use Laravel\Nova\DevTool\DevTool as Nova;",
5454
"->withAuthenticationRoutes()" => "->withAuthenticationRoutes(default: true)",

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"php": "^8.1",
99
"composer-runtime-api": "^2.2",
1010
"fakerphp/faker": "^1.24",
11-
"orchestra/workbench": "^8.16|^9.12",
11+
"orchestra/workbench": "^8.17|^9.13",
1212
"symfony/polyfill-php83": "^1.31"
1313
},
1414
"require-dev": {

src/Console/DevToolCommand.php

+28-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use function Laravel\Prompts\select;
1717
use function Orchestra\Testbench\default_skeleton_path;
1818
use function Orchestra\Testbench\package_path;
19+
use function Orchestra\Testbench\workbench_path;
1920

2021
#[AsCommand(name: 'nova:devtool', description: 'Configure Laravel Nova DevTool')]
2122
class DevToolCommand extends Command implements PromptsForMissingInput
@@ -40,13 +41,29 @@ public function handle(Filesystem $filesystem, PackageManifest $manifest): int
4041
}
4142

4243
return match ($action = $this->argument('action')) {
44+
'setup' => $this->setupNovaWorkbench($filesystem, $manifest),
4345
'install' => $this->installNpmDependencies($filesystem, $manifest),
4446
'enable-vue-devtool' => $this->enablesVueDevTool($filesystem, $manifest),
4547
'disable-vue-devtool' => $this->disablesVueDevTool($filesystem, $manifest),
4648
default => throw new InvalidArgumentException(sprintf('Unable to handle [%s] action', $action)),
4749
};
4850
}
4951

52+
/**
53+
* Setup Nova Workbench.
54+
*/
55+
protected function setupNovaWorkbench(Filesystem $filesystem, PackageManifest $manifest): int
56+
{
57+
$this->executeCommand([
58+
'npm set progress=false',
59+
'npm install --save-dev "vendor/laravel/nova-devtool"',
60+
], package_path());
61+
62+
return $this->call('workbench:install', [
63+
'--devtool' => true,
64+
]);
65+
}
66+
5067
/**
5168
* Install NPM dependencies.
5269
*/
@@ -62,7 +79,14 @@ protected function installNpmDependencies(Filesystem $filesystem, PackageManifes
6279

6380
$dependencies = multiselect(
6481
label: 'Dependencies to install?',
65-
options: ['axios', 'lodash', 'tailwindcss', 'vue'],
82+
options: [
83+
'@inertiajs/vue3',
84+
'axios',
85+
'lodash',
86+
'tailwindcss',
87+
'vue',
88+
'vuex',
89+
],
6690
default: [],
6791
);
6892

@@ -159,11 +183,12 @@ protected function promptForMissingArgumentsUsing(): array
159183
return [
160184
'action' => fn () => select(
161185
label: 'Which action to be executed?',
162-
options: [
186+
options: array_filter([
187+
'setup' => is_dir(workbench_path()) ? null : 'Setup Nova Workbench',
163188
'install' => 'Install NPM Dependencies',
164189
'enable-vue-devtool' => 'Enable Vue DevTool',
165190
'disable-vue-devtool' => 'Disable Vue DevTool',
166-
],
191+
]),
167192
default: 'owner'
168193
),
169194
];

0 commit comments

Comments
 (0)