Skip to content

Commit e73fe85

Browse files
authored
feature: Add tsconfig action to nova:devtool command (#11)
* 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]>
1 parent 83e6fad commit e73fe85

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/Console/DevToolCommand.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Foundation\PackageManifest;
1010
use Illuminate\Support\Str;
1111
use InvalidArgumentException;
12+
use Orchestra\Testbench\Foundation\Console\Actions\GeneratesFile;
1213
use Symfony\Component\Console\Attribute\AsCommand;
1314

1415
use function Illuminate\Filesystem\join_paths;
@@ -41,18 +42,19 @@ public function handle(Filesystem $filesystem, PackageManifest $manifest): int
4142
}
4243

4344
return match ($action = $this->argument('action')) {
44-
'setup' => $this->setupNovaWorkbench($filesystem, $manifest),
45+
'setup' => $this->installNovaWorkbench($filesystem, $manifest),
4546
'install' => $this->installNpmDependencies($filesystem, $manifest),
4647
'enable-vue-devtool' => $this->enablesVueDevTool($filesystem, $manifest),
4748
'disable-vue-devtool' => $this->disablesVueDevTool($filesystem, $manifest),
49+
'tsconfig' => $this->installTypeScriptConfiguration($filesystem, $manifest),
4850
default => throw new InvalidArgumentException(sprintf('Unable to handle [%s] action', $action)),
4951
};
5052
}
5153

5254
/**
5355
* Setup Nova Workbench.
5456
*/
55-
protected function setupNovaWorkbench(Filesystem $filesystem, PackageManifest $manifest): int
57+
protected function installNovaWorkbench(Filesystem $filesystem, PackageManifest $manifest): int
5658
{
5759
$this->executeCommand([
5860
'npm set progress=false',
@@ -64,6 +66,24 @@ protected function setupNovaWorkbench(Filesystem $filesystem, PackageManifest $m
6466
]);
6567
}
6668

69+
/**
70+
* Install `tsconfig.json` configuration.
71+
*/
72+
protected function installTypeScriptConfiguration(Filesystem $filesystem, PackageManifest $manifest): int
73+
{
74+
(new GeneratesFile(
75+
filesystem: $filesystem,
76+
components: $this->components,
77+
force: false,
78+
confirmation: true,
79+
))->handle(
80+
join_paths(__DIR__, 'stubs', 'tsconfig.json'),
81+
package_path('tsconfig.json')
82+
);
83+
84+
return self::SUCCESS;
85+
}
86+
6787
/**
6888
* Install NPM dependencies.
6989
*/
@@ -101,8 +121,6 @@ protected function installNpmDependencies(Filesystem $filesystem, PackageManifes
101121
'npm install --dev '.implode(' ', $dependencies),
102122
], package_path());
103123

104-
$filesystem->copy(join_paths(__DIR__, 'stubs', 'tsconfig.json'), package_path('tsconfig.json'));
105-
106124
if (in_array('tailwindcss', $dependencies)) {
107125
$filesystem->copy(join_paths(__DIR__, 'stubs', 'postcss.config.js'), package_path('postcss.config.js'));
108126
$filesystem->copy(join_paths(__DIR__, 'stubs', 'tailwind.config.js'), package_path('tailwind.config.js'));
@@ -113,7 +131,7 @@ protected function installNpmDependencies(Filesystem $filesystem, PackageManifes
113131
], package_path('tailwind.config.js'));
114132
}
115133

116-
return self::SUCCESS;
134+
return $this->installTypeScriptConfiguration($filesystem, $manifest);
117135
}
118136

119137
/**
@@ -188,6 +206,7 @@ protected function promptForMissingArgumentsUsing(): array
188206
'install' => 'Install NPM Dependencies',
189207
'enable-vue-devtool' => 'Enable Vue DevTool',
190208
'disable-vue-devtool' => 'Disable Vue DevTool',
209+
'tsconfig' => 'Install `tsconfig.json` for Nova',
191210
]),
192211
default: 'owner'
193212
),

0 commit comments

Comments
 (0)