setDescription('Install bower dependencies') ->addOption('no-dev', 'd', InputOption::VALUE_NONE, 'Do not install dev dependencies') ->addOption('attempts', 'a', InputOption::VALUE_REQUIRED, 'Number of attempts to install dependencies.', 4); } protected function doExecute(InputInterface $input, OutputInterface $output) { $bower = $this->container['driver.bower']; $output->writeln("Using ".$bower->getProcessBuilderFactory()->getBinary()." for driver"); $version = trim($bower->command('-v')); if (!version_compare('1.0.0-alpha.1', $version, '<=')) { throw new RuntimeException(sprintf( 'Bower version 1.0.0-alpha.1 is required (version %s provided), please install bower-canary : `npm install -g bower-canary`', $version )); } $attempts = $input->getOption('attempts'); if (0 >= $attempts) { throw new InvalidArgumentException('Attempts number should be a positive value.'); } $output->write("Cleaning bower cache... "); $bower->command(array('cache', 'clean')); $output->writeln("OK"); $output->write("Removing assets... "); $this->container['filesystem']->remove($this->container['root.path'] . '/www/assets'); $output->writeln("OK"); $success = false; $n = 1; while ($attempts > 0) { try { $output->write("\rInstalling assets (attempt #$n)..."); $bower->command($input->getOption('no-dev') ? array('install', '--production') : 'install'); $success = true; $output->writeln("OK"); break; } catch (ExecutionFailureException $e) { $attempts--; $n++; } } if (!$success) { throw new RuntimeException('Unable to install bower dependencies'); } return 0; } }