From 99c4d536c1c09230a1cc7ff206f9af812fe27865 Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Wed, 9 Sep 2026 10:29:03 -0500 Subject: [PATCH 1/3] refactor: The configuration for initializing the project with NPM has been modified --- .../Commands/Lion/Npm/NpmInitCommand.php | 103 +++++++++--------- .../Commands/Selection/MenuCommand.php | 26 ++--- 2 files changed, 60 insertions(+), 69 deletions(-) diff --git a/src/LionBundle/Commands/Lion/Npm/NpmInitCommand.php b/src/LionBundle/Commands/Lion/Npm/NpmInitCommand.php index b628dc00..61a82f1f 100644 --- a/src/LionBundle/Commands/Lion/Npm/NpmInitCommand.php +++ b/src/LionBundle/Commands/Lion/Npm/NpmInitCommand.php @@ -13,71 +13,72 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Initialize a project with Vite.JS/Astro - * - * @package Lion\Bundle\Commands\Lion\Npm + * Initialize a project with Vite.JS/Astro. */ class NpmInitCommand extends MenuCommand { /** - * List of available project templates - * - * @const PROJECTS_TEMPLATE + * Defines a Vite.js project. + */ + public const string PROJECT_VITE = 'Vite.JS'; + + /** + * Define an Astro-type project. + */ + public const string PROJECT_ASTRO = 'Astro'; + + /** + * List of available project templates. */ private const array PROJECTS_TEMPLATE = [ - 'Vite.JS', - 'Astro', + self::PROJECT_VITE, + self::PROJECT_ASTRO, ]; + /** - * List of templates available to create electron-vite projects - * - * @const VITE_ELECTRON_TEMPLATES + * List of templates available to create vite projects. */ - private const array VITE_ELECTRON_TEMPLATES = [ + public const array TEMPLATES_VITE = [ 'Vanilla', 'Vue', 'React', + 'Preact', + 'Lit', 'Svelte', 'Solid', + 'Qwik', + 'Electron', ]; /** - * List of templates available to create vite projects - * - * @const VITE_TEMPLATES + * List of templates available to create electron-vite projects. */ - private const array VITE_TEMPLATES = [ + public const array TEMPLATES_VITE_ELECTRON = [ 'Vanilla', 'Vue', 'React', - 'Preact', - 'Lit', 'Svelte', 'Solid', - 'Qwik', - 'Electron', ]; /** - * List of languages available to create a project - * - * @const TYPES + * List of languages available to create a project. */ - private const array TYPES = [ + public const array TYPES = [ 'js', 'ts', ]; /** * Adds functions to execute commands, allows you to create an Application - * object to run applications with your custom commands + * object to run applications with your custom commands. * * @property Kernel $kernel */ private Kernel $kernel; /** - * Project name + * Project name. * * @var string $project */ @@ -92,7 +93,7 @@ public function setKernel(Kernel $kernel): NpmInitCommand } /** - * Configures the current command + * Configures the current command. * * @return void */ @@ -100,21 +101,21 @@ protected function configure(): void { $this ->setName('npm:init') - ->setDescription('Command to create Javascript projects with Vite.JS/Astro') - ->addArgument('project', InputArgument::OPTIONAL, "Project's name", 'app'); + ->setDescription('Command to create Javascript projects with Vite.JS/Astro.') + ->addArgument('project', InputArgument::OPTIONAL, "Project's name.", 'app'); } /** * Initializes the command after the input has been bound and before the input - * is validated + * is validated. * * This is mainly useful when a lot of commands extends one main command where - * some things need to be initialized based on the input arguments and options + * some things need to be initialized based on the input arguments and options. * * @param InputInterface $input InputInterface is the interface implemented by - * all input classes + * all input classes. * @param OutputInterface $output OutputInterface is the interface implemented - * by all Output classes + * by all Output classes. * * @return void */ @@ -124,20 +125,20 @@ protected function initialize(InputInterface $input, OutputInterface $output): v } /** - * Executes the current command + * Executes the current command. * * This method is not abstract because you can use this class as a concrete * class. In this case, instead of defining the execute() method, you set the - * code to execute by passing a Closure to the setCode() method + * code to execute by passing a Closure to the setCode() method. * * @param InputInterface $input InputInterface is the interface implemented by - * all input classes + * all input classes. * @param OutputInterface $output OutputInterface is the interface implemented - * by all Output classes + * by all Output classes. * * @return int * - * @throws LogicException When this abstract method is not implemented + * @throws LogicException When this abstract method is not implemented. */ protected function execute(InputInterface $input, OutputInterface $output): int { @@ -156,7 +157,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->project = $project; if (isSuccess($this->store->exist("resources/{$this->project}/"))) { - $output->writeln($this->warningOutput("\t>> RESOURCES: a resource with this name already exists")); + $output->writeln($this->warningOutput("\t>> RESOURCES: a resource with this name already exists.")); return parent::FAILURE; } @@ -168,34 +169,34 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($this->warningOutput("\t>> RESOURCES: {$this->project}")); $output->writeln($this->successOutput( - "\t>> RESOURCES: 'resources/{$this->project}/' project has been generated successfully" + "\t>> RESOURCES: 'resources/{$this->project}/' project has been generated successfully." )); return parent::SUCCESS; } /** - * Initializes the projects to be created + * Initializes the projects to be created. * * @return void */ private function initProjects(): void { - $projectType = $this->selectedTemplate($this->input, $this->output, self::PROJECTS_TEMPLATE, 'Vite.JS', 0); + $projectType = $this->selectedTemplate(self::PROJECTS_TEMPLATE, self::PROJECT_VITE, 0); if ('Astro' === $projectType) { $this->createAstroProject(); } else { /** @var string $template */ $template = $this->str - ->of($this->selectedTemplate($this->input, $this->output, self::VITE_TEMPLATES)) + ->of($this->selectedTemplate(self::TEMPLATES_VITE)) ->lower() ->get(); if ('electron' === $template) { /** @var string $electronTemplate */ $electronTemplate = $this->str - ->of($this->selectedTemplate($this->input, $this->output, self::VITE_ELECTRON_TEMPLATES)) + ->of($this->selectedTemplate(self::TEMPLATES_VITE_ELECTRON)) ->lower() ->get(); @@ -207,7 +208,7 @@ private function initProjects(): void } /** - * Starting an Astro Project + * Starting an Astro Project. * * @return void */ @@ -221,15 +222,15 @@ private function createAstroProject(): void } /** - * Create a vite project and install its dependencies + * Create a vite project and install its dependencies. * - * @param string $template Project template + * @param string $template Project template. * * @return void */ private function createViteProject(string $template): void { - $type = $this->selectedTypes($this->input, $this->output, self::TYPES); + $type = $this->selectedTypes(self::TYPES); $command = "cd resources/ && echo | npm create vite@latest {$this->project}"; @@ -239,15 +240,15 @@ private function createViteProject(string $template): void } /** - * Create an electron-vite project and install its dependencies + * Create an electron-vite project and install its dependencies. * - * @param string $template Project template + * @param string $template Project template. * * @return void */ private function createElectronViteProject(string $template): void { - $type = $this->selectedTypes($this->input, $this->output, self::TYPES); + $type = $this->selectedTypes(self::TYPES); $command = "cd resources/ && echo | npm create @quick-start/electron"; diff --git a/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php b/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php index 6fce1417..fe067267 100644 --- a/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php +++ b/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php @@ -176,23 +176,17 @@ protected function selectedProject(InputInterface $input, OutputInterface $outpu } /** - * Open a menu to select a template to create a project with vite + * Open a menu to select a template to create a project with vite. * - * @param InputInterface $input [InputInterface is the interface - * implemented by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] - * @param array $templates [List of available templates] - * @param string $defaultTemplate [Default template] - * @param int $defaultIndex [Default index] + * @param array $templates List of available templates. + * @param string $defaultTemplate Default template. + * @param int $defaultIndex Default index. * * @return string * * @internal */ protected function selectedTemplate( - InputInterface $input, - OutputInterface $output, array $templates, string $defaultTemplate = 'React', int $defaultIndex = 2 @@ -207,7 +201,7 @@ protected function selectedTemplate( ); /** @var string $template */ - $template = $helper->ask($input, $output, $choiceQuestion); + $template = $helper->ask($this->input, $this->output, $choiceQuestion); return $template; } @@ -215,17 +209,13 @@ protected function selectedTemplate( /** * Selection menu for different types of languages * - * @param InputInterface $input [InputInterface is the interface - * implemented by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] - * @param array $types [description] + * @param list $types Types of technologies. * * @return string * * @internal */ - protected function selectedTypes(InputInterface $input, OutputInterface $output, array $types): string + protected function selectedTypes(array $types): string { /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); @@ -233,7 +223,7 @@ protected function selectedTypes(InputInterface $input, OutputInterface $output, $choiceQuestion = new ChoiceQuestion("Select type {$this->warningOutput("(default: 'js')")}", $types, 0); /** @var string $type */ - $type = $helper->ask($input, $output, $choiceQuestion); + $type = $helper->ask($this->input, $this->output, $choiceQuestion); return $type; } From fec87fee63cd43eca0cf4f571f75607dcc6b10fb Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Wed, 9 Sep 2026 10:38:03 -0500 Subject: [PATCH 2/3] chore: A setting has been added to silence the execution of npm commands --- .../Commands/Lion/Npm/NpmInitCommand.php | 16 ++++---- .../Commands/Lion/Npm/NpmInstallCommand.php | 40 +++++++++--------- .../Commands/Lion/Npm/NpmRunBuildCommand.php | 37 ++++++++--------- .../Commands/Lion/Npm/NpmRunDevCommand.php | 31 +++++++------- .../Commands/Lion/Npm/NpmRunTestCommand.php | 32 ++++++++------- .../Commands/Lion/Npm/NpmUninstallCommand.php | 41 +++++++++---------- .../Commands/Lion/Npm/NpmUpdateCommand.php | 33 +++++++-------- .../Commands/Npm/NpmInitCommand.php | 6 +-- .../Commands/Npm/NpmInstallCommand.php | 6 +-- .../Commands/Npm/NpmRunBuildCommand.php | 6 +-- .../Commands/Npm/NpmRunDevCommand.php | 4 +- .../Commands/Npm/NpmRunTestCommand.php | 5 ++- .../Commands/Npm/NpmUninstallCommand.php | 6 +-- .../Commands/Npm/NpmUpdateCommand.php | 4 +- .../Commands/Selection/MenuCommand.php | 17 +++----- 15 files changed, 129 insertions(+), 155 deletions(-) diff --git a/src/LionBundle/Commands/Lion/Npm/NpmInitCommand.php b/src/LionBundle/Commands/Lion/Npm/NpmInitCommand.php index 61a82f1f..d16c8cfc 100644 --- a/src/LionBundle/Commands/Lion/Npm/NpmInitCommand.php +++ b/src/LionBundle/Commands/Lion/Npm/NpmInitCommand.php @@ -106,11 +106,11 @@ protected function configure(): void } /** - * Initializes the command after the input has been bound and before the input - * is validated. + * Initializes the command after the input has been bound and before the input is + * validated. * - * This is mainly useful when a lot of commands extends one main command where - * some things need to be initialized based on the input arguments and options. + * This is mainly useful when a lot of commands extends one main command where some + * things need to be initialized based on the input arguments and options. * * @param InputInterface $input InputInterface is the interface implemented by * all input classes. @@ -157,7 +157,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->project = $project; if (isSuccess($this->store->exist("resources/{$this->project}/"))) { - $output->writeln($this->warningOutput("\t>> RESOURCES: a resource with this name already exists.")); + $output->writeln($this->warningOutput("\t>> RESOURCES: A resource with this name already exists.")); return parent::FAILURE; } @@ -214,7 +214,7 @@ private function initProjects(): void */ private function createAstroProject(): void { - $command = "cd resources/ && echo | npm create astro@latest {$this->project} "; + $command = "cd resources/ && echo | npm create --silent astro@latest {$this->project} "; $command .= "-- --no-install --no-git --yes --skip-houston"; @@ -232,7 +232,7 @@ private function createViteProject(string $template): void { $type = $this->selectedTypes(self::TYPES); - $command = "cd resources/ && echo | npm create vite@latest {$this->project}"; + $command = "cd resources/ && echo | npm create --silent vite@latest {$this->project}"; $command .= " -- --template {$template}" . ('js' === $type ? '' : '-ts'); @@ -250,7 +250,7 @@ private function createElectronViteProject(string $template): void { $type = $this->selectedTypes(self::TYPES); - $command = "cd resources/ && echo | npm create @quick-start/electron"; + $command = "cd resources/ && echo | npm create --silent @quick-start/electron"; $command .= " {$this->project} -- --template {$template}" . ('js' === $type ? '' : '-ts') . ' --skip'; diff --git a/src/LionBundle/Commands/Lion/Npm/NpmInstallCommand.php b/src/LionBundle/Commands/Lion/Npm/NpmInstallCommand.php index 7950bff3..8e6614ac 100644 --- a/src/LionBundle/Commands/Lion/Npm/NpmInstallCommand.php +++ b/src/LionBundle/Commands/Lion/Npm/NpmInstallCommand.php @@ -14,14 +14,13 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Install the Vite.JS project dependencies - * - * @package Lion\Bundle\Commands\Lion\Npm + * Install the project dependencies using NPM. */ class NpmInstallCommand extends MenuCommand { /** - * [Kernel class object] + * Adds functions to execute commands, allows you to create an Application + * object to run applications with your custom commands. * * @property Kernel $kernel */ @@ -36,7 +35,7 @@ public function setKernel(Kernel $kernel): NpmInstallCommand } /** - * Configures the current command + * Configures the current command. * * @return void */ @@ -44,31 +43,30 @@ 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', []); + ->setDescription('Command to install dependencies with npm for a certain vite project.') + ->addArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Package name.', []); } /** * Executes the current command * - * This method is not abstract because you can use this class - * as a concrete class. In this case, instead of defining the - * execute() method, you set the code to execute by passing - * a Closure to the setCode() method + * This method is not abstract because you can use this class as a concrete + * class. In this case, instead of defining the execute() method, you set the + * code to execute by passing a Closure to the setCode() method. * - * @param InputInterface $input [InputInterface is the interface implemented - * by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] + * @param InputInterface $input InputInterface is the interface implemented by + * all input classes + * @param OutputInterface $output OutputInterface is the interface implemented + * by all Output classes. * * @return int * - * @throws Exception - * @throws LogicException [When this abstract method is not implemented] + * @throws Exception If there are no projects available. + * @throws LogicException When this abstract method is not implemented. */ protected function execute(InputInterface $input, OutputInterface $output): int { - $project = $this->selectedProject($input, $output); + $project = $this->selectedProject(); /** @var array $packagesList */ $packagesList = $input->getArgument('packages'); @@ -85,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** @var string $command */ $command = $this->str - ->of("cd resources/{$project}/ && npm install {$packages}") + ->of("cd resources/{$project}/ && npm install --silent {$packages}") ->trim() ->get(); @@ -96,9 +94,9 @@ 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}")); + $output->writeln($this->successOutput("\t>> RESOURCES: Dependencies have been installed: {$join}")); } else { - $output->writeln($this->successOutput("\t>> RESOURCES: dependencies have been installed")); + $output->writeln($this->successOutput("\t>> RESOURCES: Dependencies have been installed")); } return parent::SUCCESS; diff --git a/src/LionBundle/Commands/Lion/Npm/NpmRunBuildCommand.php b/src/LionBundle/Commands/Lion/Npm/NpmRunBuildCommand.php index e24dea28..206838a7 100644 --- a/src/LionBundle/Commands/Lion/Npm/NpmRunBuildCommand.php +++ b/src/LionBundle/Commands/Lion/Npm/NpmRunBuildCommand.php @@ -13,15 +13,13 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Generate the dist of the Vite.JS project - * - * @package Lion\Bundle\Commands\Lion\Npm + * Generates the project's distribution folder (dist). */ class NpmRunBuildCommand extends MenuCommand { /** - * [Adds functions to execute commands, allows you to create an Application - * object to run applications with your custom commands] + * Adds functions to execute commands, allows you to create an Application + * object to run applications with your custom commands. * * @property Kernel $kernel */ @@ -36,7 +34,7 @@ public function setKernel(Kernel $kernel): NpmRunBuildCommand } /** - * Configures the current command + * Configures the current command. * * @return void */ @@ -44,38 +42,37 @@ protected function configure(): void { $this ->setName('npm:build') - ->setDescription('Command to generate dist for a vite project'); + ->setDescription('Command to generate dist for a vite project.'); } /** - * Executes the current command + * Executes the current command. * - * This method is not abstract because you can use this class - * as a concrete class. In this case, instead of defining the - * execute() method, you set the code to execute by passing - * a Closure to the setCode() method + * This method is not abstract because you can use this class as a concrete + * class. In this case, instead of defining the execute() method, you set the + * code to execute by passing a Closure to the setCode() method. * - * @param InputInterface $input [InputInterface is the interface implemented - * by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] + * @param InputInterface $input InputInterface is the interface implemented by + * all input classes. + * @param OutputInterface $output OutputInterface is the interface implemented + * by all Output classes. * * @return int * * @throws Exception - * @throws LogicException [When this abstract method is not implemented] + * @throws LogicException When this abstract method is not implemented. */ protected function execute(InputInterface $input, OutputInterface $output): int { - $project = $this->selectedProject($input, $output); + $project = $this->selectedProject(); $projectPath = "resources/{$project}/"; - $this->kernel->execute("cd {$projectPath} && npm run build"); + $this->kernel->execute("cd {$projectPath} && npm run --silent build"); $output->writeln($this->warningOutput("\n\t>> RESOURCES: {$project}")); - $output->writeln($this->successOutput("\t>> RESOURCES: project dist has been generated: {$projectPath}")); + $output->writeln($this->successOutput("\t>> RESOURCES: Project dist has been generated: {$projectPath}")); return parent::SUCCESS; } diff --git a/src/LionBundle/Commands/Lion/Npm/NpmRunDevCommand.php b/src/LionBundle/Commands/Lion/Npm/NpmRunDevCommand.php index 900f1516..b08fb4e7 100644 --- a/src/LionBundle/Commands/Lion/Npm/NpmRunDevCommand.php +++ b/src/LionBundle/Commands/Lion/Npm/NpmRunDevCommand.php @@ -12,16 +12,14 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Run the local vite environment for development - * - * @package Lion\Bundle\Commands\Lion\Npm + * Run the local vite environment for development. * * @codeCoverageIgnore */ class NpmRunDevCommand extends MenuCommand { /** - * Configures the current command + * Configures the current command. * * @return void */ @@ -29,30 +27,29 @@ protected function configure(): void { $this ->setName('npm:dev') - ->setDescription('Starts the Vite development server'); + ->setDescription('Starts the Vite development server.'); } /** - * Executes the current command + * Executes the current command. * - * This method is not abstract because you can use this class - * as a concrete class. In this case, instead of defining the - * execute() method, you set the code to execute by passing - * a Closure to the setCode() method + * This method is not abstract because you can use this class as a concrete + * class. In this case, instead of defining the execute() method, you set the + * code to execute by passing a Closure to the setCode() method. * - * @param InputInterface $input [InputInterface is the interface implemented - * by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] + * @param InputInterface $input InputInterface is the interface implemented by + * all input classes. + * @param OutputInterface $output OutputInterface is the interface implemented + * by all Output classes. * * @return int * - * @throws Exception - * @throws LogicException [When this abstract method is not implemented] + * @throws Exception If there are no projects available. + * @throws LogicException When this abstract method is not implemented. */ protected function execute(InputInterface $input, OutputInterface $output): int { - $project = $this->selectedProject($input, $output); + $project = $this->selectedProject(); ProcessCommand::run("cd resources/{$project} && npm run dev"); diff --git a/src/LionBundle/Commands/Lion/Npm/NpmRunTestCommand.php b/src/LionBundle/Commands/Lion/Npm/NpmRunTestCommand.php index 2f40b1d2..a393099c 100644 --- a/src/LionBundle/Commands/Lion/Npm/NpmRunTestCommand.php +++ b/src/LionBundle/Commands/Lion/Npm/NpmRunTestCommand.php @@ -12,10 +12,13 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +/** + * Run the tests using NPM. + */ class NpmRunTestCommand extends MenuCommand { /** - * Configures the current command + * Configures the current command. * * @return void */ @@ -23,33 +26,32 @@ protected function configure(): void { $this ->setName('npm:test') - ->setDescription('Run the tests configured in a vite project'); + ->setDescription('Run the tests configured in a vite project.'); } /** - * Executes the current command + * Executes the current command. * - * This method is not abstract because you can use this class - * as a concrete class. In this case, instead of defining the - * execute() method, you set the code to execute by passing - * a Closure to the setCode() method + * This method is not abstract because you can use this class as a concrete + * class. In this case, instead of defining the execute() method, you set the + * code to execute by passing a Closure to the setCode() method. * - * @param InputInterface $input [InputInterface is the interface implemented - * by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] + * @param InputInterface $input InputInterface is the interface implemented by + * all input classes. + * @param OutputInterface $output OutputInterface is the interface implemented + * by all Output classes. * * @return int * - * @throws Exception - * @throws LogicException [When this abstract method is not implemented] + * @throws Exception If there are no projects available. + * @throws LogicException When this abstract method is not implemented. */ protected function execute(InputInterface $input, OutputInterface $output): int { - $project = $this->selectedProject($input, $output); + $project = $this->selectedProject(); ProcessCommand::run("cd resources/{$project} && npm run test"); - return Command::SUCCESS; + return parent::SUCCESS; } } diff --git a/src/LionBundle/Commands/Lion/Npm/NpmUninstallCommand.php b/src/LionBundle/Commands/Lion/Npm/NpmUninstallCommand.php index 6093ae35..7910eac4 100644 --- a/src/LionBundle/Commands/Lion/Npm/NpmUninstallCommand.php +++ b/src/LionBundle/Commands/Lion/Npm/NpmUninstallCommand.php @@ -14,15 +14,13 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Uninstall the Vite.JS project dependencies - * - * @package Lion\Bundle\Commands\Lion\Npm + * Uninstall project dependencies using NPM. */ class NpmUninstallCommand extends MenuCommand { /** - * [Adds functions to execute commands, allows you to create an Application - * object to run applications with your custom commands] + * Adds functions to execute commands, allows you to create an Application + * object to run applications with your custom commands. * * @property Kernel $kernel */ @@ -37,7 +35,7 @@ public function setKernel(Kernel $kernel): NpmUninstallCommand } /** - * Configures the current command + * Configures the current command. * * @return void */ @@ -45,31 +43,30 @@ protected function configure(): void { $this ->setName('npm:uninstall') - ->setDescription('Command to uninstall dependencies with npm from a vite project') - ->addArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Package name', []); + ->setDescription('Command to uninstall dependencies with npm from a vite project.') + ->addArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Package name.', []); } /** - * Executes the current command + * Executes the current command. * - * This method is not abstract because you can use this class - * as a concrete class. In this case, instead of defining the - * execute() method, you set the code to execute by passing - * a Closure to the setCode() method + * This method is not abstract because you can use this class as a concrete + * class. In this case, instead of defining the execute() method, you set the + * code to execute by passing a Closure to the setCode() method. * - * @param InputInterface $input [InputInterface is the interface implemented - * by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] + * @param InputInterface $input InputInterface is the interface implemented by + * all input classes. + * @param OutputInterface $output OutputInterface is the interface implemented + * by all Output classes. * * @return int * - * @throws Exception - * @throws LogicException [When this abstract method is not implemented] + * @throws Exception If there are no projects available. + * @throws LogicException When this abstract method is not implemented. */ protected function execute(InputInterface $input, OutputInterface $output): int { - $project = $this->selectedProject($input, $output); + $project = $this->selectedProject(); /** @var array $packagesList */ $packagesList = $input->getArgument('packages'); @@ -86,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** @var string $command */ $command = $this->str - ->of("cd resources/{$project}/ && npm uninstall {$packages}") + ->of("cd resources/{$project}/ && npm uninstall --silent {$packages}") ->trim() ->get(); @@ -95,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($this->warningOutput("\n\t>> RESOURCES: {$project}")); $output->writeln($this->successOutput( - "\t>> RESOURCES: dependencies have been uninstalled: {$this->arr->of(explode(' ', $packages))->join(', ')}" + "\t>> RESOURCES: Dependencies have been uninstalled: {$this->arr->of(explode(' ', $packages))->join(', ')}" )); return parent::SUCCESS; diff --git a/src/LionBundle/Commands/Lion/Npm/NpmUpdateCommand.php b/src/LionBundle/Commands/Lion/Npm/NpmUpdateCommand.php index 943f21a6..a450d6ab 100644 --- a/src/LionBundle/Commands/Lion/Npm/NpmUpdateCommand.php +++ b/src/LionBundle/Commands/Lion/Npm/NpmUpdateCommand.php @@ -13,15 +13,13 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Update Vite.JS project dependencies - * - * @package Lion\Bundle\Commands\Lion\Npm + * Update project dependencies using NPM. */ class NpmUpdateCommand extends MenuCommand { /** - * [Adds functions to execute commands, allows you to create an Application - * object to run applications with your custom commands] + * Adds functions to execute commands, allows you to create an Application + * object to run applications with your custom commands. * * @property Kernel $kernel */ @@ -44,21 +42,20 @@ protected function configure(): void { $this ->setName('npm:update') - ->setDescription('Command to install dependencies with npm for a vite project'); + ->setDescription('Command to install dependencies with npm for a vite project.'); } /** - * Executes the current command + * Executes the current command. * - * This method is not abstract because you can use this class - * as a concrete class. In this case, instead of defining the - * execute() method, you set the code to execute by passing - * a Closure to the setCode() method + * This method is not abstract because you can use this class as a concrete + * class. In this case, instead of defining the execute() method, you set the + * code to execute by passing a Closure to the setCode() method. * - * @param InputInterface $input [InputInterface is the interface implemented - * by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] + * @param InputInterface $input InputInterface is the interface implemented by + * all input classes. + * @param OutputInterface $output OutputInterface is the interface implemented + * by all Output classes. * * @return int * @@ -67,13 +64,13 @@ protected function configure(): void */ protected function execute(InputInterface $input, OutputInterface $output): int { - $project = $this->selectedProject($input, $output); + $project = $this->selectedProject(); - $this->kernel->execute("cd resources/{$project}/ && npm update"); + $this->kernel->execute("cd resources/{$project}/ && npm update --silent"); $output->writeln($this->warningOutput("\n\t>> RESOURCES: {$project}")); - $output->writeln($this->successOutput("\t>> RESOURCES: dependencies have been updated")); + $output->writeln($this->successOutput("\t>> RESOURCES: Dependencies have been updated.")); return parent::SUCCESS; } diff --git a/src/LionBundle/Commands/Npm/NpmInitCommand.php b/src/LionBundle/Commands/Npm/NpmInitCommand.php index d231ae9f..d8a1c9c0 100644 --- a/src/LionBundle/Commands/Npm/NpmInitCommand.php +++ b/src/LionBundle/Commands/Npm/NpmInitCommand.php @@ -7,14 +7,12 @@ use Lion\Bundle\Commands\Lion\Npm\NpmInitCommand as LionNpmInitCommand; /** - * Initialize a project with Vite.JS - * - * @package Lion\Bundle\Commands\Lion\Npm + * Initialize a project with Vite.JS/Astro. */ class NpmInitCommand extends LionNpmInitCommand { /** - * Configures the current command + * Configures the current command. * * @return void */ diff --git a/src/LionBundle/Commands/Npm/NpmInstallCommand.php b/src/LionBundle/Commands/Npm/NpmInstallCommand.php index 6362b74b..30b15253 100644 --- a/src/LionBundle/Commands/Npm/NpmInstallCommand.php +++ b/src/LionBundle/Commands/Npm/NpmInstallCommand.php @@ -7,14 +7,12 @@ use Lion\Bundle\Commands\Lion\Npm\NpmInstallCommand as LionNpmInstallCommand; /** - * Install the Vite.JS project dependencies - * - * @package Lion\Bundle\Commands\Lion\Npm + * Install the project dependencies using NPM. */ class NpmInstallCommand extends LionNpmInstallCommand { /** - * Configures the current command + * Configures the current command. * * @return void */ diff --git a/src/LionBundle/Commands/Npm/NpmRunBuildCommand.php b/src/LionBundle/Commands/Npm/NpmRunBuildCommand.php index 8bca98a6..c7591ff8 100644 --- a/src/LionBundle/Commands/Npm/NpmRunBuildCommand.php +++ b/src/LionBundle/Commands/Npm/NpmRunBuildCommand.php @@ -7,14 +7,12 @@ use Lion\Bundle\Commands\Lion\Npm\NpmRunBuildCommand as LionNpmRunBuildCommand; /** - * Generate the dist of the Vite.JS project - * - * @package Lion\Bundle\Commands\Lion\Npm + * Generates the project's distribution folder (dist). */ class NpmRunBuildCommand extends LionNpmRunBuildCommand { /** - * Configures the current command + * Configures the current command. * * @return void */ diff --git a/src/LionBundle/Commands/Npm/NpmRunDevCommand.php b/src/LionBundle/Commands/Npm/NpmRunDevCommand.php index 2a976f70..104d57ac 100644 --- a/src/LionBundle/Commands/Npm/NpmRunDevCommand.php +++ b/src/LionBundle/Commands/Npm/NpmRunDevCommand.php @@ -7,9 +7,7 @@ use Lion\Bundle\Commands\Lion\Npm\NpmRunDevCommand as NpmNpmRunDevCommand; /** - * Run the local vite environment for development - * - * @package Lion\Bundle\Commands\Npm + * Run the local vite environment for development. */ class NpmRunDevCommand extends NpmNpmRunDevCommand { diff --git a/src/LionBundle/Commands/Npm/NpmRunTestCommand.php b/src/LionBundle/Commands/Npm/NpmRunTestCommand.php index c33f1141..a910b57b 100644 --- a/src/LionBundle/Commands/Npm/NpmRunTestCommand.php +++ b/src/LionBundle/Commands/Npm/NpmRunTestCommand.php @@ -4,10 +4,13 @@ use Lion\Bundle\Commands\Lion\Npm\NpmRunTestCommand as LionNpmRunTestCommand; +/** + * Run the tests using NPM. + */ class NpmRunTestCommand extends LionNpmRunTestCommand { /** - * Configures the current command + * Configures the current command. * * @return void */ diff --git a/src/LionBundle/Commands/Npm/NpmUninstallCommand.php b/src/LionBundle/Commands/Npm/NpmUninstallCommand.php index f4e46284..e9d6db39 100644 --- a/src/LionBundle/Commands/Npm/NpmUninstallCommand.php +++ b/src/LionBundle/Commands/Npm/NpmUninstallCommand.php @@ -7,14 +7,12 @@ use Lion\Bundle\Commands\Lion\Npm\NpmUninstallCommand as LionNpmUninstallCommand; /** - * Uninstall the Vite.JS project dependencies - * - * @package Lion\Bundle\Commands\Lion\Npm + * Uninstall project dependencies using NPM. */ class NpmUninstallCommand extends LionNpmUninstallCommand { /** - * Configures the current command + * Configures the current command. * * @return void */ diff --git a/src/LionBundle/Commands/Npm/NpmUpdateCommand.php b/src/LionBundle/Commands/Npm/NpmUpdateCommand.php index 73db8a06..94edd8ba 100644 --- a/src/LionBundle/Commands/Npm/NpmUpdateCommand.php +++ b/src/LionBundle/Commands/Npm/NpmUpdateCommand.php @@ -7,9 +7,7 @@ use Lion\Bundle\Commands\Lion\Npm\NpmUpdateCommand as LionNpmUpdateCommand; /** - * Update Vite.JS project dependencies - * - * @package Lion\Bundle\Commands\Lion\Npm + * Update project dependencies using NPM. */ class NpmUpdateCommand extends LionNpmUpdateCommand { diff --git a/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php b/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php index fe067267..7b8cf3ad 100644 --- a/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php +++ b/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php @@ -112,20 +112,15 @@ protected function initialize(InputInterface $input, OutputInterface $output): v } /** - * Selection menu to obtain a Vite.JS project - * - * @param InputInterface $input [InputInterface is the interface - * implemented by all input classes] - * @param OutputInterface $output [OutputInterface is the interface - * implemented by all Output classes] + * Selection menu to obtain a Vite.JS project. * * @return string * - * @throws Exception [If there are no projects available] + * @throws Exception If there are no projects available. * * @internal */ - protected function selectedProject(InputInterface $input, OutputInterface $output): string + protected function selectedProject(): string { $projects = []; @@ -148,14 +143,14 @@ protected function selectedProject(InputInterface $input, OutputInterface $outpu } if (empty($projects)) { - throw new Exception('there are no projects available', Http::INTERNAL_SERVER_ERROR); + throw new Exception('There are no projects available.', Http::INTERNAL_SERVER_ERROR); } /** @var string $defaultProject */ $defaultProject = reset($projects); if (count($projects) <= 1) { - $output->writeln($this->warningOutput('(default: ' . $defaultProject . ')')); + $this->output->writeln($this->warningOutput('(default: ' . $defaultProject . ')')); return $defaultProject; } @@ -170,7 +165,7 @@ protected function selectedProject(InputInterface $input, OutputInterface $outpu ); /** @var string $response */ - $response = $helper->ask($input, $output, $choiseQuestion); + $response = $helper->ask($this->input, $this->output, $choiseQuestion); return $response; } From 86ad82142b31d6adfdfbd79a32afddab22dde70d Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Wed, 9 Sep 2026 11:24:27 -0500 Subject: [PATCH 3/3] test: Test coverage is added --- .../Commands/Lion/Npm/NpmInitCommandTest.php | 12 +++--- .../Lion/Npm/NpmInstallCommandTest.php | 7 ++-- .../Lion/Npm/NpmRunBuildCommandTest.php | 9 ++--- .../Lion/Npm/NpmUninstallCommandTest.php | 9 ++--- .../Lion/Npm/NpmUpdateCommandTest.php | 7 ++-- .../Commands/Selection/MenuCommandTest.php | 39 +++++++------------ 6 files changed, 33 insertions(+), 50 deletions(-) diff --git a/tests/Commands/Lion/Npm/NpmInitCommandTest.php b/tests/Commands/Lion/Npm/NpmInitCommandTest.php index c2761582..5f1c88b2 100644 --- a/tests/Commands/Lion/Npm/NpmInitCommandTest.php +++ b/tests/Commands/Lion/Npm/NpmInitCommandTest.php @@ -7,28 +7,27 @@ use DI\DependencyException; use DI\NotFoundException; use Lion\Bundle\Commands\Lion\Npm\NpmInitCommand; -use Lion\Command\Command; use Lion\Command\Kernel; use Lion\Dependency\Injection\Container; use Lion\Test\Test; use PHPUnit\Framework\Attributes\Test as Testing; use ReflectionException; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; class NpmInitCommandTest extends Test { private const string PROJECT_NAME = 'test-app'; private const string OUTPUT_MESSAGE = 'project has been generated successfully'; - private const string OUTPUT_MESSAGE_ERROR = 'a resource with this name already exists'; + private const string OUTPUT_MESSAGE_ERROR = 'A resource with this name already exists'; private CommandTester $commandTester; private NpmInitCommand $npmInitCommand; /** - * @throws ReflectionException - * @throws DependencyException - * @throws NotFoundException + * @throws DependencyException Error while resolving the entry. + * @throws NotFoundException No entry found for the given name. */ protected function setUp(): void { @@ -52,7 +51,8 @@ protected function tearDown(): void } /** - * @throws ReflectionException + * @throws ReflectionException If the property does not exist in the reflected + * class. */ #[Testing] public function setKernel(): void diff --git a/tests/Commands/Lion/Npm/NpmInstallCommandTest.php b/tests/Commands/Lion/Npm/NpmInstallCommandTest.php index 4fe93180..534edeb1 100644 --- a/tests/Commands/Lion/Npm/NpmInstallCommandTest.php +++ b/tests/Commands/Lion/Npm/NpmInstallCommandTest.php @@ -21,16 +21,15 @@ 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_INSTALL = 'Dependencies have been installed'; private CommandTester $commandTesterNpmIn; private CommandTester $commandTesterNpmI; private NpmInstallCommand $npmInstallCommand; /** - * @throws DependencyException - * @throws NotFoundException - * @throws ReflectionException + * @throws DependencyException Error while resolving the entry. + * @throws NotFoundException No entry found for the given name. */ protected function setUp(): void { diff --git a/tests/Commands/Lion/Npm/NpmRunBuildCommandTest.php b/tests/Commands/Lion/Npm/NpmRunBuildCommandTest.php index 49dfcc69..ddeb3aae 100644 --- a/tests/Commands/Lion/Npm/NpmRunBuildCommandTest.php +++ b/tests/Commands/Lion/Npm/NpmRunBuildCommandTest.php @@ -23,8 +23,8 @@ class NpmRunBuildCommandTest extends Test private const string PROJECT_NAME = 'test-app'; private const string DIST_PATH = 'resources/' . self::PROJECT_NAME . '/dist/'; 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_BUILD = 'project dist has been generated'; + private const string OUTPUT_MESSAGE_INSTALL = 'Dependencies have been installed'; + private const string OUTPUT_MESSAGE_BUILD = 'Project dist has been generated'; private CommandTester $commandTesterNpmInit; private CommandTester $commandTesterNpmInstall; @@ -32,9 +32,8 @@ class NpmRunBuildCommandTest extends Test private NpmRunBuildCommand $npmRunBuildCommand; /** - * @throws NotFoundException - * @throws DependencyException - * @throws ReflectionException + * @throws DependencyException Error while resolving the entry. + * @throws NotFoundException No entry found for the given name. */ protected function setUp(): void { diff --git a/tests/Commands/Lion/Npm/NpmUninstallCommandTest.php b/tests/Commands/Lion/Npm/NpmUninstallCommandTest.php index e2bbc566..2d5705ae 100644 --- a/tests/Commands/Lion/Npm/NpmUninstallCommandTest.php +++ b/tests/Commands/Lion/Npm/NpmUninstallCommandTest.php @@ -22,8 +22,8 @@ class NpmUninstallCommandTest 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_UNINSTALL = 'dependencies have been uninstalled'; + private const string OUTPUT_MESSAGE_INSTALL = 'Dependencies have been installed'; + private const string OUTPUT_MESSAGE_UNINSTALL = 'Dependencies have been uninstalled'; private CommandTester $commandTesterNpmIn; private CommandTester $commandTesterNpmI; @@ -31,9 +31,8 @@ class NpmUninstallCommandTest extends Test private NpmUninstallCommand $npmUninstallCommand; /** - * @throws NotFoundException - * @throws DependencyException - * @throws ReflectionException + * @throws DependencyException Error while resolving the entry. + * @throws NotFoundException No entry found for the given name. */ protected function setUp(): void { diff --git a/tests/Commands/Lion/Npm/NpmUpdateCommandTest.php b/tests/Commands/Lion/Npm/NpmUpdateCommandTest.php index 6c3537f0..7c1c7f6e 100644 --- a/tests/Commands/Lion/Npm/NpmUpdateCommandTest.php +++ b/tests/Commands/Lion/Npm/NpmUpdateCommandTest.php @@ -21,16 +21,15 @@ class NpmUpdateCommandTest 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_UPDATE = 'dependencies have been updated'; + private const string OUTPUT_MESSAGE_UPDATE = 'Dependencies have been updated'; private CommandTester $commandTesterNpmIn; private CommandTester $commandTesterNpmU; private NpmUpdateCommand $npmUpdateCommand; /** - * @throws DependencyException - * @throws NotFoundException - * @throws ReflectionException + * @throws DependencyException Error while resolving the entry. + * @throws NotFoundException No entry found for the given name. */ protected function setUp(): void { diff --git a/tests/Helpers/Commands/Selection/MenuCommandTest.php b/tests/Helpers/Commands/Selection/MenuCommandTest.php index 68f86e2c..3768e78d 100644 --- a/tests/Helpers/Commands/Selection/MenuCommandTest.php +++ b/tests/Helpers/Commands/Selection/MenuCommandTest.php @@ -7,6 +7,7 @@ use DI\DependencyException; use DI\NotFoundException; use Exception; +use Lion\Bundle\Commands\Lion\Npm\NpmInitCommand; use Lion\Bundle\Helpers\Commands\Migrations\MigrationFactory; use Lion\Bundle\Helpers\Commands\Selection\MenuCommand; use Lion\Database\Connection; @@ -119,7 +120,7 @@ public function setStore(): void public function selectedProjectNotAvailable(): void { $this->expectException(Exception::class); - $this->expectExceptionMessageIs('there are no projects available'); + $this->expectExceptionMessageIs('There are no projects available.'); $this->expectExceptionCode(Http::INTERNAL_SERVER_ERROR); $this->createDirectory(self::RESOURCES_PATH); @@ -132,7 +133,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $project = $this->selectedProject($input, $output); + $project = $this->selectedProject(); $output->write("({$project})"); @@ -169,7 +170,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $project = $this->selectedProject($input, $output); + $project = $this->selectedProject(); $output->write("({$project})"); @@ -209,7 +210,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $project = $this->selectedProject($input, $output); + $project = $this->selectedProject(); $output->write("({$project})"); @@ -263,7 +264,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $project = $this->selectedProject($input, $output); + $project = $this->selectedProject(); $output->write("({$project})"); @@ -291,6 +292,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int } /** + * @param string $output + * @param list $inputs + * * @throws DependencyException * @throws NotFoundException */ @@ -299,18 +303,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int public function selectedTemplate(string $output, array $inputs): void { $command = new class () extends MenuCommand { - private const array VITE_TEMPLATES = [ - 'Vanilla', - 'Vue', - 'React', - 'Preact', - 'Lit', - 'Svelte', - 'Solid', - 'Qwik', - 'Electron', - ]; - protected function configure(): void { $this->setName('test:menu:command'); @@ -318,11 +310,11 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $template = $this->selectedTemplate($input, $output, self::VITE_TEMPLATES); + $template = $this->selectedTemplate(NpmInitCommand::TEMPLATES_VITE); $output->write("({$template})"); - return Command::SUCCESS; + return parent::SUCCESS; } }; @@ -347,11 +339,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int public function selectedTypes(): void { $command = new class () extends MenuCommand { - private const array TYPES = [ - 'js', - 'ts', - ]; - protected function configure(): void { $this->setName('test:menu:command'); @@ -359,11 +346,11 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $type = $this->selectedTypes($input, $output, self::TYPES); + $type = $this->selectedTypes(NpmInitCommand::TYPES); $output->write("({$type})"); - return Command::SUCCESS; + return parent::SUCCESS; } };