From 0b9e6dd65eee0cba2ed0796f31928adef91eea1c Mon Sep 17 00:00:00 2001
From: Alexander Kras'ko <0m3r.mail@gmail.com>
Date: Tue, 23 Jul 2019 14:21:35 +0300
Subject: [PATCH] Rename command to swissup:theme:create
---
Console/Command/ThemeBootstrap.php | 181 ----------------------
Console/Command/ThemeBootstrapCommand.php | 112 -------------
etc/di.xml | 2 +-
3 files changed, 1 insertion(+), 294 deletions(-)
delete mode 100644 Console/Command/ThemeBootstrap.php
delete mode 100644 Console/Command/ThemeBootstrapCommand.php
diff --git a/Console/Command/ThemeBootstrap.php b/Console/Command/ThemeBootstrap.php
deleted file mode 100644
index f168a7f..0000000
--- a/Console/Command/ThemeBootstrap.php
+++ /dev/null
@@ -1,181 +0,0 @@
-
-
- {{THEME_NAME}}
- {{PARENT_THEME_NAME}}
-
-EOT;
-
- /**
- * @var Filesystem\Directory\ReadInterface
- */
- private $appRead;
-
- /**
- * @var Filesystem\Directory\WriteInterface
- */
- private $appWrite;
-
- /**
- * Bootstrap constructor.
- *
- * @param Filesystem $fs
- * @throws FileSystemException
- */
- public function __construct(Filesystem $fs)
- {
- $this->appRead = $fs->getDirectoryRead(DirectoryList::APP);
- $this->appWrite = $fs->getDirectoryWrite(DirectoryList::APP);
- }
-
- /**
- * @param string $themeName
- * @return int
- * @throws FileSystemException
- */
- public function generateRegistration(string $themeName): int
- {
- $destinationPath = $this->getThemePath($themeName);
-
- $content = self::THEME_REGISTRATION_TEMPLATE;
- $content = str_replace(
- '{{THEME_NAME}}',
- ThemeBootstrapCommand::SECTION . DIRECTORY_SEPARATOR . $themeName,
- $content
- );
-
- return $this->appWrite->writeFile(
- $destinationPath . DIRECTORY_SEPARATOR . 'registration.php',
- $content
- );
- }
-
- /**
- *
- * @param string $themeName
- * @return boolean
- */
- public function isExist(string $themeName)
- {
- $path = $this->getThemePath($themeName);
- return $this->appWrite->isExist($path);
- }
-
- /**
- * @param string $themeName
- * @param string $parentThemeName
- * @return int
- * @throws FileSystemException
- */
- public function generateThemeXml(string $themeName, string $parentThemeName): int
- {
- $content = self::THEME_XML;
- $content = str_replace(
- '{{THEME_NAME}}',
- str_replace('/', ' ', $themeName . ' theme'),
- $content
- );
- $content = str_replace(
- '{{PARENT_THEME_NAME}}',
- $parentThemeName,
- $content
- );
- $destinationPath = $this->getThemePath($themeName);
-
- return $this->appWrite->writeFile(
- $destinationPath . DIRECTORY_SEPARATOR . 'theme.xml',
- $content
- );
- }
-
- /**
- * @param string $themeName
- * @param string $parentThemePackageName
- * @return int
- * @throws FileSystemException
- */
- public function generateComposerJson(string $themeName, string $parentThemePackageName): int
- {
- // local/argento-stripes-custom
- // swissup/theme-frontend-argento-stripe
- $content = self::THEME_COMPOSER_TEMPLATE;
- $content = str_replace(
- '{{THEME_PACKAGE_NAME}}',
- strtolower($themeName),
- // strtolower($themeName) . '-custom',
- $content
- );
- $content = str_replace(
- '{{PARENT_THEME_PACKAGE_NAME}}',
- $parentThemePackageName,
- $content
- );
- $destinationPath = $this->getThemePath($themeName);
-
- return $this->appWrite->writeFile(
- $destinationPath . DIRECTORY_SEPARATOR . 'composer.json',
- $content
- );
- }
-
- /**
- * @param string $themeName
- * @return int
- * @throws FileSystemException
- */
- public function generateCustomCss(string $themeName): int
- {
- $content = '/* Autogenerated */';
- $destinationPath = $this->getThemePath($themeName);
-
- return $this->appWrite->writeFile(
- $destinationPath . DIRECTORY_SEPARATOR . 'web/css/source/_argento_custom.less',
- $content
- );
- }
-
- /**
- * @param $themeName
- * @return string
- */
- protected function getThemePath($themeName): string
- {
- return $destinationPath = $this->appRead->getAbsolutePath(
- ThemeBootstrapCommand::THEME_DIR . DIRECTORY_SEPARATOR . $themeName
- );
- }
-}
diff --git a/Console/Command/ThemeBootstrapCommand.php b/Console/Command/ThemeBootstrapCommand.php
deleted file mode 100644
index 4b1d7af..0000000
--- a/Console/Command/ThemeBootstrapCommand.php
+++ /dev/null
@@ -1,112 +0,0 @@
-bootstrap = $bootstrap;
- parent::__construct($name);
- }
-
- /**
- * Define Symfony\Console compatible command
- */
- protected function configure()
- {
- $this->setName('swissup:theme:bootstrap')
- ->setDescription('Bootstrap Local Swissup theme')
- ->addArgument('name', InputArgument::REQUIRED, 'Put the theme name you want to create (Local/argento-stripes)')
- ->addArgument('parent', InputArgument::REQUIRED, 'Put the parent short theme name (stripes)');
-
- $this->addOption(
- 'css',
- null,
- InputOption::VALUE_OPTIONAL,
- 'Should I create custom css?',
- false
- );
-
- parent::configure();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $this->prepareOutput($output);
-
- $themeName = $input->getArgument('name');
- if (strpos($themeName, '/') === false) {
- $themeName = 'Local/' . $themeName;
- }
- $parent = $input->getArgument('parent');
- $parentThemeName = 'Swissup/argento-' . $parent;
- $parentThemePackageName = 'swissup/theme-frontend-argento-' . $parent;
-
- if ($this->bootstrap->isExist($themeName)) {
- $output->writeln('Theme dir already exist');
- return 9;
- }
- $registration = $this->bootstrap->generateRegistration($themeName);
- $themeXml = $this->bootstrap->generateThemeXml($themeName, $parentThemeName);
- $composerjson = $this->bootstrap->generateComposerJson($themeName, $parentThemePackageName);
-
- $withCss = $input->getOption('css');
- $withCss = ($withCss !== false);
- if ($withCss) {
- $this->bootstrap->generateCustomCss($themeName);
- }
-
- if ($registration < 1 || $themeXml < 1 || $composerjson < 1) {
- $output->writeln('Failed to generate files');
- return 9;
- }
-
- $output->writeln('New Local Swissup theme bootstrap done! Happy coding!');
- $output->writeln('Please run setup:upgrade from Magento CLI');
- }
-
- /**
- * @param OutputInterface $output
- * @return OutputInterface
- */
- protected function prepareOutput(OutputInterface $output)
- {
- $error = new OutputFormatterStyle('red', 'black', ['bold', 'blink']);
- $warn = new OutputFormatterStyle('yellow', 'black', ['bold', 'blink']);
- $success = new OutputFormatterStyle('green', 'black', ['bold', 'blink']);
- $special = new OutputFormatterStyle('blue', 'black', ['bold', 'blink']);
- $output->getFormatter()->setStyle('error', $error);
- $output->getFormatter()->setStyle('warn', $warn);
- $output->getFormatter()->setStyle('success', $success);
- $output->getFormatter()->setStyle('special', $special);
-
- return $output;
- }
-}
diff --git a/etc/di.xml b/etc/di.xml
index 4c9b0c7..78206e3 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -21,7 +21,7 @@
- Swissup\Core\Console\Command\ModuleCommand
- Swissup\Core\Console\Command\ModuleListCommand
- Swissup\Core\Console\Command\ModuleInstallCommand
- - Swissup\Core\Console\Command\ThemeBootstrapCommand
+ - Swissup\Core\Console\Command\ThemeCreateCommand