From 5fab27712df5f7a51ab1f0488ae641fe4f2654b4 Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Wed, 9 Sep 2026 11:48:07 -0500 Subject: [PATCH 1/2] feat: The flag (--dev) is added to install the dependencies --- .../Commands/Lion/Npm/NpmInstallCommand.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/LionBundle/Commands/Lion/Npm/NpmInstallCommand.php b/src/LionBundle/Commands/Lion/Npm/NpmInstallCommand.php index 8e6614ac..0c239ad5 100644 --- a/src/LionBundle/Commands/Lion/Npm/NpmInstallCommand.php +++ b/src/LionBundle/Commands/Lion/Npm/NpmInstallCommand.php @@ -11,6 +11,7 @@ use LogicException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -44,7 +45,8 @@ protected function configure(): void $this ->setName('npm:install') ->setDescription('Command to install dependencies with npm for a certain vite project.') - ->addArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Package name.', []); + ->addArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Package name.', []) + ->addOption('dev', 'D', InputOption::VALUE_NONE, 'Install packages as devDependencies (--save-dev).'); } /** @@ -68,6 +70,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $project = $this->selectedProject(); + /** @var bool $isDev */ + $isDev = $input->getOption('dev'); + /** @var array $packagesList */ $packagesList = $input->getArgument('packages'); @@ -81,9 +86,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int ->trim() ->get(); + $devFlag = $isDev ? '--save-dev' : ''; + /** @var string $command */ $command = $this->str - ->of("cd resources/{$project}/ && npm install --silent {$packages}") + ->of("cd resources/{$project}/ && npm install --silent {$devFlag} {$packages}") ->trim() ->get(); @@ -94,7 +101,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ('' != $packages) { $join = $this->arr->of(explode(' ', $packages))->join(', '); - $output->writeln($this->successOutput("\t>> RESOURCES: Dependencies have been installed: {$join}")); + $devText = $isDev ? ' (devDependencies)' : ''; + + $output->writeln( + $this->successOutput("\t>> RESOURCES: Dependencies have been installed{$devText}: {$join}") + ); } else { $output->writeln($this->successOutput("\t>> RESOURCES: Dependencies have been installed")); } From a432a7a27fa6e890f01e43ad3ccb490639cbb785 Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Wed, 9 Sep 2026 11:48:17 -0500 Subject: [PATCH 2/2] test: Test coverage is added --- .../Lion/Npm/NpmInstallCommandTest.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/Commands/Lion/Npm/NpmInstallCommandTest.php b/tests/Commands/Lion/Npm/NpmInstallCommandTest.php index 534edeb1..f5d997e2 100644 --- a/tests/Commands/Lion/Npm/NpmInstallCommandTest.php +++ b/tests/Commands/Lion/Npm/NpmInstallCommandTest.php @@ -22,6 +22,7 @@ class NpmInstallCommandTest extends Test private const string PROJECT_NAME = 'test-app'; private const string OUTPUT_MESSAGE_INIT_PROJECT = 'project has been generated successfully'; private const string OUTPUT_MESSAGE_INSTALL = 'Dependencies have been installed'; + private const string OUTPUT_MESSAGE_DEV_INSTALL = 'Dependencies have been installed (devDependencies)'; private CommandTester $commandTesterNpmIn; private CommandTester $commandTesterNpmI; @@ -76,10 +77,42 @@ public function execute(): void { $this->assertSame(Command::SUCCESS, $this->commandTesterNpmIn->execute(['project' => self::PROJECT_NAME])); $this->assertStringContainsString(self::OUTPUT_MESSAGE_INIT_PROJECT, $this->commandTesterNpmIn->getDisplay()); + $this->assertSame(Command::SUCCESS, $this->commandTesterNpmI->execute(['packages' => ['']])); + $this->assertSame(Command::SUCCESS, $this->commandTesterNpmI->execute(['packages' => ['axios']])); $this->assertStringContainsString(self::OUTPUT_MESSAGE_INSTALL, $this->commandTesterNpmI->getDisplay()); + $this->assertSame(Command::SUCCESS, $this->commandTesterNpmI->execute(['packages' => ['dayjs jwt-decode']])); $this->assertStringContainsString(self::OUTPUT_MESSAGE_INSTALL, $this->commandTesterNpmI->getDisplay()); } + + #[Testing] + public function executeWithDevOption(): void + { + $this->assertSame(Command::SUCCESS, $this->commandTesterNpmIn->execute(['project' => self::PROJECT_NAME])); + $this->assertStringContainsString(self::OUTPUT_MESSAGE_INIT_PROJECT, $this->commandTesterNpmIn->getDisplay()); + + $this->assertSame( + Command::SUCCESS, + $this->commandTesterNpmI->execute([ + 'packages' => ['typescript'], + '--dev' => true, + ]) + ); + + $this->assertStringContainsString(self::OUTPUT_MESSAGE_DEV_INSTALL, $this->commandTesterNpmI->getDisplay()); + $this->assertStringContainsString('typescript', $this->commandTesterNpmI->getDisplay()); + + $this->assertSame( + Command::SUCCESS, + $this->commandTesterNpmI->execute([ + 'packages' => ['@types/node', 'prettier'], + '-D' => true, + ]) + ); + + $this->assertStringContainsString(self::OUTPUT_MESSAGE_DEV_INSTALL, $this->commandTesterNpmI->getDisplay()); + $this->assertStringContainsString('@types/node, prettier', $this->commandTesterNpmI->getDisplay()); + } }