From e90ccc01c423b3f4c2d945cb8238d324b1735fdd Mon Sep 17 00:00:00 2001 From: Paulo Rodrigues Pinto Date: Tue, 7 Nov 2017 01:08:05 +0000 Subject: [PATCH] Remove install command --- Command/InstallCommand.php | 92 --------------------------- Command/SetupCommand.php | 22 ++----- Resources/doc/setup.rst | 6 ++ Tests/Command/InstallCommandTest.php | 95 ---------------------------- Tests/Command/SetupCommandTest.php | 26 -------- 5 files changed, 12 insertions(+), 229 deletions(-) delete mode 100644 Command/InstallCommand.php delete mode 100644 Tests/Command/InstallCommandTest.php diff --git a/Command/InstallCommand.php b/Command/InstallCommand.php deleted file mode 100644 index 5a5195d..0000000 --- a/Command/InstallCommand.php +++ /dev/null @@ -1,92 +0,0 @@ -setName('rj_frontend:install') - ->setDescription('Install npm and bower dependencies') - ; - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - if (!$this->commandExists('npm')) { - return $output->writeln( -'npm is not installed - -node.js is probably not installed on your system. For node.js installation -instructions, refer to https://nodejs.org/en/download/package-manager -' - ); - } - - if (!$this->commandExists('bower')) { - return $output->writeln( -'bower is not installed - -You can install bower using npm: -npm install -g bower -' - ); - } - - $output->writeln('Running `npm install`'); - $this->runProcess($output, 'npm install'); - - $output->writeln('Running `bower install`'); - $this->runProcess($output, 'bower install'); - } - - /** - * @param OutputInterface $output - * @param string $command - */ - protected function runProcess($output, $command) - { - $process = new Process($command); - - $process->run(function ($type, $buffer) use ($output) { - if (Process::ERR === $type) { - $output->writeln("$buffer"); - } else { - $output->writeln($buffer); - } - }); - - if (!$process->isSuccessful()) { - throw new \RuntimeException($process->getErrorOutput()); - } - } - - /** - * @param string $command - * - * @return bool - */ - protected function commandExists($command) - { - $process = new Process("$command -v"); - $process->run(); - - if (!$process->isSuccessful()) { - return !preg_match('/: not found/', $process->getErrorOutput()); - } - - return true; - } -} diff --git a/Command/SetupCommand.php b/Command/SetupCommand.php index 46733bc..02188e0 100644 --- a/Command/SetupCommand.php +++ b/Command/SetupCommand.php @@ -5,7 +5,6 @@ use Rj\FrontendBundle\Command\Options\SimpleOptionHelper; use Rj\FrontendBundle\Command\Options\ChoiceOptionHelper; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -179,21 +178,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->createBowerJson($input, $output); $output->writeln(''); - $this->runInstallCommand($input, $output); - } - - /** - * @param InputInterface $input - * @param OutputInterface $output - */ - private function runInstallCommand(InputInterface $input, OutputInterface $output) - { - if ($input->getOption('dry-run')) { - return $output->writeln('Would have installed npm and bower dependencies'); - } - - $this->getApplication()->find('rj_frontend:install') - ->run(new ArrayInput(['command' => 'rj_frontend:install']), $output); + $output->writeln('All files generated.'); + $output->writeln(''); + $output->writeln('Make sure to install dependencies:'); + $output->writeln(''); + $output->writeln(' npm install'); + $output->writeln(''); } /** diff --git a/Resources/doc/setup.rst b/Resources/doc/setup.rst index 8341cd5..337741a 100644 --- a/Resources/doc/setup.rst +++ b/Resources/doc/setup.rst @@ -111,6 +111,12 @@ You can read about all available options with: Feel free to take a look at the generated ``gulpfile.js``. Even though the file is somewhat long, it should be straightforward to understand so you'll be able to adapt it to your use case, if need be. +Finally, install ``npm`` dependencies required by ``gulpfile.js``: + +.. code-block :: shell + + npm install + Livereload ---------- diff --git a/Tests/Command/InstallCommandTest.php b/Tests/Command/InstallCommandTest.php deleted file mode 100644 index dc30439..0000000 --- a/Tests/Command/InstallCommandTest.php +++ /dev/null @@ -1,95 +0,0 @@ -remove($this->baseDir = sys_get_temp_dir().'/rj_frontend'); - mkdir($this->baseDir); - - $application = new Application(); - $application->add($command = $this->getCommand()); - - $this->command = $application->find($command->getName()); - $this->commandTester = new CommandTester($this->command); - } - - /** - * @runInSeparateProcess - */ - public function testNpmNotInstalled() - { - $this->command->method('commandExists') - ->will($this->returnCallback(function () { - $args = func_get_args(); - - return $args[0] !== 'npm'; - })); - - $this->commandTester->execute([]); - $this->assertRegExp('/npm is not installed/', $this->commandTester->getDisplay()); - } - - /** - * @runInSeparateProcess - */ - public function testBowerNotInstalled() - { - $this->command->method('commandExists') - ->will($this->returnCallback(function () { - $args = func_get_args(); - - return $args[0] !== 'bower'; - })); - - $this->commandTester->execute([]); - $this->assertRegExp('/bower is not installed/', $this->commandTester->getDisplay()); - } - - /** - * @runInSeparateProcess - */ - public function testInstall() - { - $this->command->method('commandExists')->willReturn(true); - - $this->commandTester->execute([]); - $this->assertRegExp('/Running `npm install`/', $this->commandTester->getDisplay()); - $this->assertRegExp('/Running `bower install`/', $this->commandTester->getDisplay()); - } - - /** - * @return InstallCommand|PHPUnit_Framework_MockObject_MockObject - */ - private function getCommand() - { - return $this->getMockBuilder('Rj\FrontendBundle\Command\InstallCommand') - ->setMethods(['commandExists', 'runProcess']) - ->getMock(); - } -} diff --git a/Tests/Command/SetupCommandTest.php b/Tests/Command/SetupCommandTest.php index 201e787..7931c83 100644 --- a/Tests/Command/SetupCommandTest.php +++ b/Tests/Command/SetupCommandTest.php @@ -2,8 +2,6 @@ namespace Rj\FrontendBundle\Tests\Command; -use PHPUnit_Framework_MockObject_MockObject; -use Rj\FrontendBundle\Command\InstallCommand; use Rj\FrontendBundle\Command\SetupCommand; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; @@ -34,7 +32,6 @@ protected function setUp() $application = new Application(); - $application->add($this->getInstallCommand()); $application->add($command = new SetupCommand()); $this->command = $application->find($command->getName()); @@ -257,18 +254,6 @@ public function testCreateFiles() $this->assertNotEmpty(file_get_contents("$base/bower.json")); } - /** - * @runInSeparateProcess - */ - public function testInstallDependenciesDryRun() - { - $this->commandTester->execute([ - '--dry-run' => true, - ], ['interactive' => false]); - - $this->assertRegExp('/Would have installed npm and bower dependencies/', $this->commandTester->getDisplay()); - } - /** * @param array $options * @param array $expected @@ -309,17 +294,6 @@ private function assertOptions(array $options, array $expected, $interactive = t } } - /** - * @return InstallCommand|PHPUnit_Framework_MockObject_MockObject - */ - private function getInstallCommand() - { - return $this->getMockBuilder('Rj\FrontendBundle\Command\InstallCommand') - ->setMethods(['commandExists', 'runProcess']) - ->getMock() - ; - } - /** * @param $input *