From 489b2bf308892b174f6ad2bda6032bca3014b16f Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Wed, 19 Oct 2016 12:02:45 +0100 Subject: [PATCH] Integrate translations with yamlclean rubygem Cherry pick of https://github.com/silverstripe/cow/pull/22 back to 1 branch --- src/Steps/Release/UpdateTranslations.php | 48 +++++++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Steps/Release/UpdateTranslations.php b/src/Steps/Release/UpdateTranslations.php index 50c6434..3a268aa 100644 --- a/src/Steps/Release/UpdateTranslations.php +++ b/src/Steps/Release/UpdateTranslations.php @@ -2,6 +2,7 @@ namespace SilverStripe\Cow\Steps\Release; +use Exception; use InvalidArgumentException; use SilverStripe\Cow\Commands\Command; use SilverStripe\Cow\Model\Module; @@ -90,9 +91,11 @@ public function run(InputInterface $input, OutputInterface $output) if ($this->getVersionConstraint()) { $this->log($output, sprintf("Note: Modules filtered by version %s", $this->getVersionConstraint())); } - $this->checkVersion($output); + $this->checkTransifexVersion($output); + $this->checkYamlCleanDependency($output); $this->storeJavascript($output, $modules); $this->pullSource($output, $modules); + $this->cleanYaml($output, $modules); $this->mergeJavascriptMasters($output); $this->collectStrings($output, $modules); $this->generateJavascript($output, $modules); @@ -107,7 +110,7 @@ public function run(InputInterface $input, OutputInterface $output) * @param OutputInterface $output * @throws InvalidArgumentException */ - protected function checkVersion(OutputInterface $output) + protected function checkTransifexVersion(OutputInterface $output) { $error = "translate requires transifex {$this->txVersion} at least. " . "Run 'pip install transifex-client==0.11b3' to update."; @@ -122,6 +125,22 @@ protected function checkVersion(OutputInterface $output) $this->log($output, "Using transifex CLI version: $result"); } + /** + * Test that yamlclean ruby gem is installed + * + * @param OutputInterface $output + * @throws InvalidArgumentException + */ + protected function checkYamlCleanDependency(OutputInterface $output) + { + $error = "translate requires the yamlclean ruby gem. Run 'gem install yamlclean'"; + try { + $this->runCommand($output, 'yamlclean'); + } catch (Exception $e) { + throw new InvalidArgumentException($error); + } + } + /** * Backup local javascript masters * @@ -217,6 +236,31 @@ protected function pullSource(OutputInterface $output, $modules) } } + /** + * Tidy yaml files using yamlclean ruby gem + * + * @param OutputInterface $output + * @param Module[] $modules List of modules + */ + protected function cleanYaml(OutputInterface $output, $modules) + { + foreach ($modules as $module) { + $name = $module->getName(); + $this->log( + $output, + "Cleaning YAML sources for {$name}" + ); + + foreach (glob($module->getLangDirectory()."/*.yml") as $sourceFile) { + $cleanCommand = sprintf( + 'echo "$(yamlclean %1$s)" > %1$s', + $sourceFile + ); + $this->runCommand($output, $cleanCommand); + } + } + } + /** * Run text collector on the given modules *