diff --git a/readme.md b/readme.md index 6435a45..7e3b81f 100644 --- a/readme.md +++ b/readme.md @@ -48,4 +48,6 @@ Outside of doing core releases, you can use this for specific modules * `module:translate ` Updates translations for modules and commits this to source control. If you don't specify a list of modules then all modules will be translated. Specify 'installer' for root module. +You can use `--push` option to push to origin at the end, or `--exclude` if your list of modules is the list +to exclude. By default all modules are included, unless whitelisted or excluded. diff --git a/src/Commands/Module/Module.php b/src/Commands/Module/Module.php index b3add2c..a3f3dc7 100644 --- a/src/Commands/Module/Module.php +++ b/src/Commands/Module/Module.php @@ -22,6 +22,7 @@ protected function configure() { ); $this->addOption('directory', 'd', InputOption::VALUE_REQUIRED, 'Module directory'); $this->addOption('exclude', 'e', InputOption::VALUE_NONE, "Makes list of modules exclusive instead of inclusive"); + $this->addOption('push', 'p', InputOption::VALUE_NONE, "Push to git origin if successful"); } /** @@ -52,6 +53,10 @@ protected function getInputModules() { * @return bool */ protected function getInputExclude() { - return $this->input->getOption('exclude'); + return (bool)$this->input->getOption('exclude'); + } + + protected function getInputPush() { + return (bool)$this->input->getOption('push'); } } diff --git a/src/Commands/Module/Translate.php b/src/Commands/Module/Translate.php index 72bcabf..87ed4cf 100644 --- a/src/Commands/Module/Translate.php +++ b/src/Commands/Module/Translate.php @@ -22,8 +22,9 @@ protected function fire() { $directory = $this->getInputDirectory(); $modules = $this->getInputModules(); $listIsExclusive = $this->getInputExclude(); + $push = $this->getInputPush(); - $translate = new UpdateTranslations($this, $directory, $modules, $listIsExclusive); + $translate = new UpdateTranslations($this, $directory, $modules, $listIsExclusive, $push); $translate->run($this->input, $this->output); //$step->run($this->input, $this->output); } diff --git a/src/Steps/Release/UpdateTranslations.php b/src/Steps/Release/UpdateTranslations.php index f3d3cdc..7e9d813 100644 --- a/src/Steps/Release/UpdateTranslations.php +++ b/src/Steps/Release/UpdateTranslations.php @@ -62,6 +62,13 @@ class UpdateTranslations extends Step { */ protected $listIsExclusive; + /** + * Flag whether we should do push on each git repo + * + * @var bool + */ + protected $push; + /** * Create a new translation step * @@ -69,13 +76,15 @@ class UpdateTranslations extends Step { * @param string $directory Where to translate * @param array $modules Optional list of modules to limit translation to * @param bool $listIsExclusive If this list is exclusive. If false, this is inclusive + * @param bool $push Do git push at end */ - public function __construct(Command $command, $directory, $modules = array(), $listIsExclusive = false) { + public function __construct(Command $command, $directory, $modules = array(), $listIsExclusive = false, $doPush = false) { parent::__construct($command); $this->modules = $modules; $this->listIsExclusive = $listIsExclusive; $this->project = new Project($directory); + $this->push = $doPush; } /** @@ -276,10 +285,23 @@ public function commitChanges(OutputInterface $output, $modules) { $jsPath = $module->getJSLangDirectory(); $langPath = $module->getLangDirectory(); foreach(array_merge((array)$jsPath, (array)$langPath) as $path) { - $repo->run("add", array($path . "/*")); + if(is_dir($path)) { + $repo->run("add", array($path . "/*")); + } + } + + // Commit changes if any exist + $status = $repo->run("status"); + if(stripos($status, 'Changes to be committed:')) { + $this->log($output, "Comitting changes for module " . $module->getName()); + $repo->run("commit", array("-m", "Update translations")); + } + + // Do push if selected + if($this->push) { + $this->log($output, "Pushing upstream for module " . $module->getName()); + $repo->run("push", array("origin")); } - - $repo->run("commit", array("-m", "Update translations")); } }