diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GitHubPagesDeploy/Console/Application.php | 24 | ||||
-rw-r--r-- | src/GitHubPagesDeploy/Console/Command/DeployCommand.php | 33 | ||||
-rw-r--r-- | src/GitHubPagesDeploy/GitHubPagesDeploy.php | 53 | ||||
-rw-r--r-- | src/bootstrap.php | 15 |
4 files changed, 125 insertions, 0 deletions
diff --git a/src/GitHubPagesDeploy/Console/Application.php b/src/GitHubPagesDeploy/Console/Application.php new file mode 100644 index 0000000..a7791ad --- /dev/null +++ b/src/GitHubPagesDeploy/Console/Application.php @@ -0,0 +1,24 @@ +<?php + +namespace GitHubPagesDeploy\Console; + +use Symfony\Component\Console\Application as BaseApplication; +use GitHubPagesDeploy\Console\Command\DeployCommand; + +class Application extends BaseApplication +{ + const NAME = 'GitHub Pages Deploy'; + const VERSION = '@package_version@'; + + public function __construct() + { + parent::__construct(static::NAME, static::VERSION); + } + + protected function getDefaultCommands() + { + $defaultCommands = parent::getDefaultCommands(); + $defaultCommands[] = new DeployCommand(); + return $defaultCommands; + } +} diff --git a/src/GitHubPagesDeploy/Console/Command/DeployCommand.php b/src/GitHubPagesDeploy/Console/Command/DeployCommand.php new file mode 100644 index 0000000..70c7d8a --- /dev/null +++ b/src/GitHubPagesDeploy/Console/Command/DeployCommand.php @@ -0,0 +1,33 @@ +<?php + +namespace GitHubPagesDeploy\Console\Command; + +use GitHubPagesDeploy\GitHubPagesDeploy; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class DeployCommand extends Command +{ + protected function configure() + { + $this + ->setName('deploy') + ->setDescription('Deploys the list of GitHub Pages repositories.') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $deploy = GitHubPagesDeploy::fromFile(); + $repositories = $deploy->getRepositories(); + if (empty($repositories)) { + $output->writeln('<info>gh-pages-deploy.json is empty.</info>'); + } + else { + $deploy->update(); + } + } +} diff --git a/src/GitHubPagesDeploy/GitHubPagesDeploy.php b/src/GitHubPagesDeploy/GitHubPagesDeploy.php new file mode 100644 index 0000000..c7f1a17 --- /dev/null +++ b/src/GitHubPagesDeploy/GitHubPagesDeploy.php @@ -0,0 +1,53 @@ +<?php + +namespace GitHubPagesDeploy; + +use GitWrapper\GitWrapper; +use GitWrapper\GitWorkingCopy; + +class GitHubPagesDeploy +{ + protected $repositories; + + public function __construct($repositories = array()) + { + $this->repositories = $repositories; + } + + public static function fromFile($file = 'gh-pages-deploy.json') + { + $results = array(); + + if (is_file($file)) { + $contents = file_get_contents($file); + $results = json_decode($contents); + } + + return new GitHubPagesDeploy($results); + } + + public function update() + { + // Create the wrapper. + $wrapper = new GitWrapper(); + $wrapper->streamOutput(); + + foreach ($this->repositories as $dir => $repo) { + $git = null; + if (!is_dir($dir)) { + $git = $wrapper->cloneRepository($repo, $dir); + } + else { + $git = new GitWorkingCopy($wrapper, $dir); + } + + $git->checkout('gh-pages'); + $git->pull(); + } + } + + public function getRepositories() + { + return $this->repositories; + } +} diff --git a/src/bootstrap.php b/src/bootstrap.php new file mode 100644 index 0000000..4ffa9d1 --- /dev/null +++ b/src/bootstrap.php @@ -0,0 +1,15 @@ +<?php + +function includeIfExists($file) +{ + return file_exists($file) ? include $file : false; +} + +if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../autoload.php'))) { + echo 'You must set up the project dependencies, run the following commands:'.PHP_EOL. + 'curl -sS https://getcomposer.org/installer | php'.PHP_EOL. + 'php composer.phar install'.PHP_EOL; + exit(1); +} + +return $loader; |