diff --git a/Mage/Compiler.php b/Mage/Compiler.php new file mode 100644 index 0000000..b0ba738 --- /dev/null +++ b/Mage/Compiler.php @@ -0,0 +1,50 @@ + + */ +class Mage_Compiler +{ + + /** + * Compiles the library + * + * @param string $file + */ + public function compile($file = 'mage.phar') + { + + if (file_exists($file)) { + unlink($file); + } + + $phar = new Phar($file, 0, 'mage.phar'); + $phar->setSignatureAlgorithm(Phar::SHA1); + + $phar->startBuffering(); + + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__), RecursiveIteratorIterator::CHILD_FIRST); + /** @var $path SplFileInfo */ + foreach ($iterator as $path) { + if ($path->isFile()) { + $phar->addFromString(str_replace(dirname(__DIR__).'/', '', $path->getPathname()), file_get_contents($path)); + } + } + + $phar->addFromString('mage', str_replace( + '$baseDir = dirname(dirname(__FILE__));', + '$baseDir = __DIR__;', + file_get_contents(__DIR__.'/../bin/mage.php') + )); + + $phar->setStub("#!/usr/bin/env php\nstopBuffering(); + + unset($phar); + } +} diff --git a/Mage/Console.php b/Mage/Console.php index 8f2c57e..512044c 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -25,22 +25,25 @@ class Mage_Console if ($this->_args[0] == 'deploy') { $this->_action = 'deploy'; - } else if ($this->_args[0] == 'releases') { + } else if ($this->_args[0] == 'releases') { $this->_action = 'releases'; } else if ($this->_args[0] == 'update') { $this->_action = 'update'; + } else if ($this->_args[0] == 'compile') { + $this->_action = 'compile'; + } else if ($this->_args[0] == 'add') { $this->_action = 'add'; } else if ($this->_args[0] == 'install') { $this->_action = 'install'; - } else if ($this->_args[0] == 'upgrade') { + } else if ($this->_args[0] == 'upgrade') { $this->_action = 'upgrade'; - } else if ($this->_args[0] == 'version') { + } else if ($this->_args[0] == 'version') { $this->_action = 'version'; } else if ($this->_args[0] == 'init') { @@ -126,10 +129,10 @@ class Mage_Console $config->loadSCM(); // Logging - $showGrettings = true; - if (in_array($this->getAction(), array('install', 'upgrade', 'version'))) { + $showGrettings = true; + if (in_array($this->getAction(), array('install', 'upgrade', 'version'))) { self::$_logEnabled = false; - $showGrettings = false; + $showGrettings = false; } else { self::$_logEnabled = $config->general('logging', false); } @@ -145,19 +148,19 @@ class Mage_Console $task->run($config); break; - case 'releases': + case 'releases': $task = new Mage_Task_Releases; switch ($this->_args[1]) { case 'list': $task->setAction($this->_args[1]); break; - case 'rollback': + case 'rollback': $task->setAction($this->_args[1]); - $task->setRelease($this->_args[2]); + $task->setRelease($this->_args[2]); break; - } - $task->run($config); + } + $task->run($config); break; case 'update'; @@ -165,14 +168,19 @@ class Mage_Console $task->run($config); break; + case 'compile'; + $task = new Mage_Task_Compile; + $task->run($config); + break; + case 'install'; $task = new Mage_Task_Install; $task->run(); break; - case 'upgrade'; - $task = new Mage_Task_Upgrade; - $task->run(); + case 'upgrade'; + $task = new Mage_Task_Upgrade; + $task->run(); break; case 'init'; @@ -195,8 +203,8 @@ class Mage_Console } break; - case 'version'; - $this->showVersion(); + case 'version'; + $this->showVersion(); break; default: diff --git a/Mage/Task/Compile.php b/Mage/Task/Compile.php new file mode 100644 index 0000000..e1fb4a0 --- /dev/null +++ b/Mage/Task/Compile.php @@ -0,0 +1,22 @@ + + */ +class Mage_Task_Compile +{ + /** + * @see Mage_Compile::compile() + */ + public function run () + { + Mage_Console::output('Compiling Magallanes... ', 1, 0); + + $compiler = new Mage_Compiler(); + $compiler->compile(); + + Mage_Console::output('Mage compiled successfully'); + } +}