/** * Method overridden to add output customizations and use the output object * for application logging. */ public function run(InputInterface $input = null, OutputInterface $output = null) { if (null === $output) { $output = new ConsoleOutput(); $output->setFormatter(new OutputFormatter($output->isDecorated())); } return parent::run($input, $output); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $bundlezip = $input->getOption('zip-file'); if (!$bundlezip) { $helper = $this->getHelper('question'); $question = new Question('<info>Please enter the name of the zip file:</info> <comment>[webflow]</comment> ', 'webflow'); $bundlezip = $helper->ask($input, $output, $question); } $withZip = $bundlezip . ".zip"; // Theme Name $theme = $input->getOption('theme-name'); if (!$theme) { $helper = $this->getHelper('question'); $question = new Question('<info>Please enter theme name:</info> <comment>[webflow]</comment> ', 'webflow'); $theme = $helper->ask($input, $output, $question); } // Theme Description // $themeDesc = $input->getOption('theme-description'); // if(!$themeDesc){ // $helper = $this->getHelper('question'); // $question = new Question('<info>Please enter theme description:</info> <comment>[These is a webflow theme]</comment> ', 'These is a webflow theme'); // $themeDesc = $helper->ask($input, $output, $question); // } $themeDesc = 'These is a webflow theme'; $path = getcwd() . '/temp'; $zip = new ZipArchive(); if ($zip->open($withZip) === TRUE) { $zip->extractTo($path); $zip->close(); $output->writeln('<info>Starting Theme creation process</info>'); } else { $output->writeln('<comment>Failed to open the archive!</comment>'); return false; } $directory = "{$path}/{$bundlezip}/"; $htmlfiles = glob($directory . "*.html"); $themeMachine = strtolower(str_replace(" ", "_", $theme)); $Root = getcwd() . '/themes'; $themeDir = "{$Root}/{$theme}"; $create = new ClutchCli(); $output = new ConsoleOutput(); $output->setFormatter(new OutputFormatter(true)); $rows = 8; $progressBar = new ProgressBar($output, $rows); $progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%'); $progressBar->setBarCharacter('<fg=magenta>=</>'); $progressBar->setProgressCharacter("🏃"); $progressBar->setOverwrite(true); for ($i = 0; $i < $rows; $i++) { $create->Components($themeDir, $theme, $htmlfiles, 'data-component', 'components'); $create->Components($themeDir, $theme, $htmlfiles, 'data-node', 'nodes'); $create->Components($themeDir, $theme, $htmlfiles, 'data-menu', 'menus'); $progressBar->advance(2); $create->Directory($path, $Root, $themeDir, $theme, $bundlezip); $progressBar->advance(); $vars = array('{{themeName}}' => $theme, '{{themeMachine}}' => $themeMachine, '{{themeDescription}}' => $themeDesc); $progressBar->advance(); $create->ThemeTemplates($themeDir, $theme, $vars); $progressBar->advance(); $create->deleteDirectory($path); $progressBar->advance(); \Drupal::service('theme_handler')->rebuildThemeData(); $progressBar->advance(); \Drupal::service('theme_handler')->reset(); \Drupal::service('theme_handler')->refreshInfo(); \Drupal::service('theme_handler')->listInfo(); // $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']); // $this->getChain()->addCommand('clutch:sync', ['theme' => $theme]); $progressBar->advance(); $output->writeln('<comment>' . "\r\n" . 'Your theme ' . $theme . ' is now created.</comment>'); return true; } $progressBar->finish(); }
<?php use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Formatter\OutputFormatter; use Igorw\Fab\FabOutputFormatterStyle; require 'vendor/autoload.php'; $app = new Application(); $app->register('foo')->setDefinition(array(new InputArgument('bar', InputArgument::REQUIRED, 'Bar')))->setDescription('Does foo with bar')->setCode(function (InputInterface $input, OutputInterface $output) { $bar = $input->getArgument('bar'); $output->writeln(sprintf('This is the foo for <info>%s</info>', $bar)); $output->writeln(sprintf('<comment>%s</comment>', sha1($bar))); }); $input = new ArgvInput(); $output = new ConsoleOutput(); $output->setFormatter(new OutputFormatter(true, ['info' => new FabOutputFormatterStyle(), 'comment' => new FabOutputFormatterStyle()])); $app->run($input, $output);