Skip to content

Commit

Permalink
Integrate translations with yamlclean rubygem
Browse files Browse the repository at this point in the history
Cherry pick of #22 back to 1 branch
  • Loading branch information
kinglozzer authored and Damian Mooyman committed Nov 10, 2016
1 parent 85cfb91 commit 489b2bf
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/Steps/Release/UpdateTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Cow\Steps\Release;

use Exception;
use InvalidArgumentException;
use SilverStripe\Cow\Commands\Command;
use SilverStripe\Cow\Model\Module;
Expand Down Expand Up @@ -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);
Expand All @@ -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.";
Expand All @@ -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
*
Expand Down Expand Up @@ -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 <info>{$name}</info>"
);

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
*
Expand Down

0 comments on commit 489b2bf

Please sign in to comment.