Skip to content

Commit 19b7b38

Browse files
committed
feat: add support for other package managers
1 parent b4659da commit 19b7b38

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

src/Utils/Core.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ public static function findNodeJS(): string
7676
* Get the node command for the environment.
7777
* @return string
7878
*/
79-
public static function findNpm(): string
79+
public static function findNpm($packageManager = 'npm'): string
8080
{
81-
$npmPath = getcwd() . '/npm';
81+
$npmPath = getcwd() . "/$packageManager";
8282

8383
if (file_exists($npmPath)) {
8484
return $npmPath;
8585
}
8686

87-
return 'npm';
87+
return $packageManager;
8888
}
8989

9090
/**

src/ViewBuildCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Leaf\Console;
66

77
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Input\InputOption;
89
use Symfony\Component\Console\Input\InputInterface;
910
use Symfony\Component\Console\Output\OutputInterface;
1011

@@ -16,13 +17,14 @@ protected function configure()
1617
{
1718
$this
1819
->setHelp('Run your frontend dev command')
19-
->setDescription('Run your frontend dev server');
20+
->setDescription('Run your frontend dev server')
21+
->addOption('pm', 'pm', InputOption::VALUE_OPTIONAL, 'Package manager to use', 'npm');
2022
}
2123

2224
protected function execute(InputInterface $input, OutputInterface $output): int
2325
{
2426
$directory = getcwd();
25-
$npm = Utils\Core::findNpm();
27+
$npm = Utils\Core::findNpm($input->getOption('pm'));
2628

2729
if (!is_dir("$directory/node_modules")) {
2830
$output->writeln("<info>Installing dependencies...</info>");

src/ViewDevCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Leaf\Console;
66

77
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Input\InputOption;
89
use Symfony\Component\Console\Input\InputInterface;
910
use Symfony\Component\Console\Output\OutputInterface;
1011

@@ -17,13 +18,14 @@ protected function configure()
1718
$this
1819
->setAliases(['view:serve'])
1920
->setHelp('Run your frontend dev command')
20-
->setDescription('Run your frontend dev server');
21+
->setDescription('Run your frontend dev server')
22+
->addOption('pm', 'pm', InputOption::VALUE_OPTIONAL, 'Package manager to use', 'npm');
2123
}
2224

2325
protected function execute(InputInterface $input, OutputInterface $output): int
2426
{
2527
$directory = getcwd();
26-
$npm = Utils\Core::findNpm();
28+
$npm = Utils\Core::findNpm($input->getOption('pm'));
2729

2830
if (!is_dir("$directory/node_modules")) {
2931
$output->writeln("<info>Installing dependencies...</info>");

src/ViewInstallCommand.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ protected function configure()
2525
->addOption('react', null, InputOption::VALUE_NONE, 'Install react')
2626
->addOption('tailwind', null, InputOption::VALUE_NONE, 'Install tailwind')
2727
->addOption('vite', null, InputOption::VALUE_NONE, 'Setup vite files')
28-
->addOption('vue', null, InputOption::VALUE_NONE, 'Install vue');
28+
->addOption('vue', null, InputOption::VALUE_NONE, 'Install vue')
29+
->addOption('pm', 'pm', InputOption::VALUE_OPTIONAL, 'Package manager to use', 'npm');
2930
}
3031

3132
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -39,23 +40,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3940
}
4041

4142
if ($input->getOption('inerita')) {
42-
return $this->installInertia($output);
43+
return $this->installInertia($input, $output);
4344
}
4445

4546
if ($input->getOption('react')) {
46-
return $this->installReact($output);
47+
return $this->installReact($input, $output);
4748
}
4849

4950
if ($input->getOption('tailwind')) {
50-
return $this->installTailwind($output);
51+
return $this->installTailwind($input, $output);
5152
}
5253

5354
if ($input->getOption('vite')) {
54-
return $this->installVite($output);
55+
return $this->installVite($input, $output);
5556
}
5657

5758
if ($input->getOption('vue')) {
58-
return $this->installVue($output);
59+
return $this->installVue($input, $output);
5960
}
6061

6162
$output->writeln('<error>You didn\'t select an option to install</error>');
@@ -157,13 +158,13 @@ protected function installBareUi($output)
157158
/**
158159
* Install inerita
159160
*/
160-
protected function installInertia($output)
161+
protected function installInertia($input, $output)
161162
{
162163
$directory = getcwd();
163-
$npm = Utils\Core::findNpm();
164+
$npm = Utils\Core::findNpm($input->getOption('pm'));
164165
$composer = Utils\Core::findComposer();
165166

166-
$success = Utils\Core::run("$npm install @leafphp/vite-plugin vite", $output);
167+
$success = Utils\Core::run("$npm add @leafphp/vite-plugin vite", $output);
167168

168169
if (!$success) {
169170
$output->writeln("❌ <error>Failed to install vite</error>");
@@ -230,14 +231,14 @@ protected function installInertia($output)
230231
/**
231232
* Install react
232233
*/
233-
protected function installReact($output)
234+
protected function installReact($input, $output)
234235
{
235236
$output->writeln("📦 <info>Installing react...</info>\n");
236237

237238
$directory = getcwd();
238-
$npm = Utils\Core::findNpm();
239+
$npm = Utils\Core::findNpm($input->getOption('pm'));
239240
$composer = Utils\Core::findComposer();
240-
$success = Utils\Core::run("$npm install @leafphp/vite-plugin @vitejs/plugin-react @inertiajs/react react react-dom", $output);
241+
$success = Utils\Core::run("$npm add @leafphp/vite-plugin @vitejs/plugin-react @inertiajs/react react react-dom", $output);
241242

242243
if (!$success) {
243244
$output->writeln("❌ <error>Failed to install react</error>");
@@ -321,15 +322,15 @@ protected function installReact($output)
321322
/**
322323
* Install tailwind
323324
*/
324-
protected function installTailwind($output)
325+
protected function installTailwind($input, $output)
325326
{
326327
$directory = getcwd();
327-
$npm = Utils\Core::findNpm();
328+
$npm = Utils\Core::findNpm($input->getOption('pm'));
328329
$composer = Utils\Core::findComposer();
329330

330331
$output->writeln("📦 <info>Installing tailwind...</info>\n");
331332

332-
$success = Utils\Core::run("$npm install tailwindcss postcss autoprefixer @leafphp/vite-plugin vite", $output);
333+
$success = Utils\Core::run("$npm add tailwindcss postcss autoprefixer @leafphp/vite-plugin vite", $output);
333334

334335
if (!$success) {
335336
$output->writeln("❌ <error>Failed to install tailwind</error>");
@@ -427,13 +428,13 @@ protected function installTailwind($output)
427428
/**
428429
* Install vite
429430
*/
430-
protected function installVite($output)
431+
protected function installVite($input, $output)
431432
{
432433
$directory = getcwd();
433-
$npm = Utils\Core::findNpm();
434+
$npm = Utils\Core::findNpm($input->getOption('pm'));
434435
$composer = Utils\Core::findComposer();
435436

436-
$success = Utils\Core::run("$npm install @leafphp/vite-plugin vite", $output);
437+
$success = Utils\Core::run("$npm add @leafphp/vite-plugin vite", $output);
437438

438439
if (!$success) {
439440
$output->writeln("❌ <error>Failed to install vite</error>");
@@ -483,14 +484,14 @@ protected function installVite($output)
483484
/**
484485
* Install vue
485486
*/
486-
protected function installVue($output)
487+
protected function installVue($input, $output)
487488
{
488489
$output->writeln("📦 <info>Installing Vue...</info>\n");
489490

490491
$directory = getcwd();
491-
$npm = Utils\Core::findNpm();
492+
$npm = Utils\Core::findNpm($input->getOption('pm'));
492493
$composer = Utils\Core::findComposer();
493-
$success = Utils\Core::run("$npm install @leafphp/vite-plugin @vitejs/plugin-vue @inertiajs/vue3 vue", $output);
494+
$success = Utils\Core::run("$npm add @leafphp/vite-plugin @vitejs/plugin-vue @inertiajs/vue3 vue", $output);
494495

495496
if (!$success) {
496497
$output->writeln("❌ <error>Failed to install Vue</error>");

0 commit comments

Comments
 (0)