Skip to content

Commit

Permalink
Set up self-update and rollback commands, box config, composer depend…
Browse files Browse the repository at this point in the history
…encies, stub
  • Loading branch information
hollodotme committed Aug 13, 2016
1 parent ac40a8a commit 179765c
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 26 deletions.
38 changes: 38 additions & 0 deletions bin/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(string_types = 1);
/**
* @author hollodotme
*/

namespace IceHawk\StaticPageGenerator;

use IceHawk\StaticPageGenerator\ConsoleCommands\RollBack;
use IceHawk\StaticPageGenerator\ConsoleCommands\SelfUpdate;
use Symfony\Component\Console\Application;

error_reporting( -1 );
ini_set( 'display_errors', 'On' );

require(__DIR__ . '/../vendor/autoload.php');

define( 'PHAR_DIR', dirname( __DIR__ ) );
define( 'WORKING_DIR', getcwd() );

try
{
$app = new Application( 'Static page generator', '@package_version@' );
$app->addCommands(
[
new GenerateComponent( 'generate:component' ),
new SelfUpdate( 'self-update' ),
new RollBack( 'rollback' ),
]
);
$code = $app->run();
exit($code);
}
catch ( \Throwable $e )
{
echo "Uncaught " . get_class( $e ) . " with message: " . $e->getMessage() . "\n";
echo $e->getTraceAsString();
exit(1);
}
31 changes: 31 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"chmod": "0755",
"compression": "GZ",
"compactors": [
"Herrera\\Box\\Compactor\\Php"
],
"directories": [
"src/"
],
"files": [
"LICENSE"
],
"finder": [
{
"name": "*.php",
"exclude": [
"bin",
"tm"
],
"in": "vendor"
}
],
"extract": false,
"git-version": "package_version",
"intercept": true,
"main": "bin/main.php",
"metadata": "Static page generator",
"output": "build/static-page-generator.phar",
"shebang": "#!/usr/bin/env php",
"stub": true
}
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"source": "https://github.com/icehawk/static-page-generator"
},
"require": {
"php": ">=7.0"
"php": ">=7.0",
"symfony/console": "^3.1",
"psr/log": "^1.0",
"padraic/phar-updater": "^1.0"
},
"require-dev": {
"tm/tooly-composer-script": "^1.0"
Expand All @@ -34,6 +37,10 @@
},
"extra": {
"tools": {
"box": {
"url": "https://github.com/box-project/box2/releases/download/2.7.4/box-2.7.4.phar",
"only-dev": true
},
"phpunit": {
"url": "https://phar.phpunit.de/phpunit.phar",
"only-dev": true
Expand All @@ -52,4 +59,4 @@
}
}
}
}
}
49 changes: 49 additions & 0 deletions src/ConsoleCommands/RollBack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php declare(string_types = 1);
/**
* @author hollodotme
*/

namespace IceHawk\StaticPageGenerator\ConsoleCommands;

use Humbug\SelfUpdate\Strategy\GithubStrategy;
use Humbug\SelfUpdate\Updater;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class RollBack
* @package IceHawk\StaticPageGenerator\ConsoleCommands
*/
final class RollBack extends Command
{
protected function configure()
{
$this->setDescription( 'Rolls back this PHAR to the previous version.' );
}

protected function execute( InputInterface $input, OutputInterface $output )
{
$logger = new ConsoleLogger( $output );
$updater = new Updater( null, false, Updater::STRATEGY_GITHUB );

/** @var GithubStrategy $strategy */
$strategy = $updater->getStrategy();

$strategy->setPackageName( 'icehawk/static-page-generator' );
$strategy->setPharName( 'static-page-generator.phar' );
$strategy->setCurrentLocalVersion( '@package_version@' );

if ( $updater->rollback() )
{
$logger->info( 'Roll back successful!' );
}
else
{
$logger->alert( 'Roll back failed.' );
}

return 0;
}
}
77 changes: 77 additions & 0 deletions src/ConsoleCommands/SelfUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php declare(string_types = 1);
/**
* @author hollodotme
*/

namespace IceHawk\StaticPageGenerator\ConsoleCommands;

use Humbug\SelfUpdate\Strategy\GithubStrategy;
use Humbug\SelfUpdate\Updater;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class SelfUpdate
* @package IceHawk\StaticPageGenerator\ConsoleCommands
*/
final class SelfUpdate extends Command
{
protected function configure()
{
$this->setAliases( [ 'selfupdate' ] );
$this->setDescription( 'Updates this PHAR to latest version.' );

$this->addOption(
'stability', 's', InputOption::VALUE_OPTIONAL,
sprintf(
'Specify the stability (%s, %s or %s)',
GithubStrategy::STABLE,
GithubStrategy::UNSTABLE,
GithubStrategy::ANY
),
GithubStrategy::STABLE
);
}

protected function execute( InputInterface $input, OutputInterface $output )
{
$logger = new ConsoleLogger( $output );
$updater = new Updater( null, false, Updater::STRATEGY_GITHUB );

/** @var GithubStrategy $strategy */
$strategy = $updater->getStrategy();

$strategy->setPackageName( 'icehawk/static-page-generator' );
$strategy->setPharName( 'static-page-generator.phar' );
$strategy->setCurrentLocalVersion( '@package_version@' );

$stability = $input->getOption( 'stability' );
$strategy->setStability( $stability );

if ( $updater->hasUpdate() )
{
$newVersion = $updater->getNewVersion();

$logger->info( sprintf( 'The current stable version available is: %s', $newVersion ) );
$logger->info( 'Updating...' );

if ( $updater->update() )
{
$logger->info( sprintf( 'Successful! You now have version %s installed', $newVersion ) );
}
}
elseif ( false === $updater->getNewVersion() )
{
$logger->alert( 'There is no stable version available.' );
}
else
{
$logger->info( '@package_version@ is the latest stable version.' );
}

return 0;
}
}
18 changes: 9 additions & 9 deletions src/Exceptions/StaticPageGeneratorException.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php



<?php declare(strict_types = 1);
/**
* @author hollodotme
*/

namespace IceHawk\StaticPageGenerator\Exceptions;





/**
* Class StaticPageGeneratorException
* @package IceHawk\StaticPageGenerator\Exceptions
*/
class StaticPageGeneratorException extends \Exception
{

}
}
15 changes: 0 additions & 15 deletions src/StaticPageGenerator.php

This file was deleted.

0 comments on commit 179765c

Please sign in to comment.