added initial pass at install command

This commit is contained in:
Andy Miller
2014-08-06 21:32:42 -06:00
parent da2f5dc817
commit 7154d2e205
7 changed files with 108 additions and 6 deletions

5
.gitignore vendored
View File

@@ -17,8 +17,9 @@ Thumbs.db
/images/*
/user/data/*
!/user/data/index.html
user/plugins/**/
user/themes/**/
user/plugins/error
user/plugins/problems
user/themes/antimatter
# phpstorm
.idea/*

View File

@@ -15,6 +15,7 @@ if (!file_exists(ROOT_DIR . 'index.php')) {
$app = new Application('Grav CLI Application', '0.1.0');
$app->addCommands(array(
new Grav\Console\InstallCommand(),
new Grav\Console\SetupCommand(),
new Grav\Console\CleanCommand(),
));

View File

@@ -88,7 +88,7 @@ class CleanCommand extends Command {
protected function configure() {
$this
->setName("clean")
->setDescription("Handles cl chores for Grav")
->setDescription("Handles cleaning chores for Grav")
->setHelp('The <info>clean</info> clean extraneous folders and data');
}

View File

@@ -0,0 +1,103 @@
<?php
namespace Grav\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use \Symfony\Component\Yaml\Yaml;
class InstallCommand extends Command {
protected $configuration;
protected function configure() {
$this
->setName("install")
->addOption(
'symlink',
's',
InputOption::VALUE_NONE,
'Symlink the required bits'
)
->setDescription("Handles cloning and symlinking for Grav")
->setHelp('The <info>install</info> provides clone and symlink installation chores');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$dependencies_file = ROOT_DIR . '/.dependencies';
// Create a red output option
$output->getFormatter()->setStyle('red', new OutputFormatterStyle('red'));
$output->getFormatter()->setStyle('cyan', new OutputFormatterStyle('cyan'));
$output->getFormatter()->setStyle('green', new OutputFormatterStyle('green'));
$output->getFormatter()->setStyle('magenta', new OutputFormatterStyle('magenta'));
if (is_file($dependencies_file)) {
$this->configuration = Yaml::parse($dependencies_file);
if (!$input->getOption('symlink')) {
$this->gitclone($output);
} else {
$this->symlink($output);
}
} else {
$output->writeln('<red>ERROR</red> Missing .dependencies file');
}
}
// loops over the array of paths and deletes the files/folders
private function gitclone($output)
{
$output->writeln('');
$output->writeln('<green>Cloning Bits</green>');
$output->writeln('============');
$output->writeln('');
exec('cd ' . ROOT_DIR);
foreach($this->configuration['git'] as $repo => $data) {
if (!file_exists($data['path'])) {
exec('git clone ' . $data['url'] . ' ' . $data['path']);
$output->writeln('<green>SUCCESS</green> cloned <magenta>' . $data['url'] . '</magenta> -> <cyan>' . $data['path'] . '</cyan>');
$output->writeln('');
} else {
$output->writeln('<red>' . $data['path'] . ' already exists, skipping...</red>');
$output->writeln('');
}
}
}
// loops over the array of paths and deletes the files/folders
private function symlink($output)
{
$output->writeln('');
$output->writeln('<green>Symlinking Bits</green>');
$output->writeln('===============');
$output->writeln('');
exec('cd ' . ROOT_DIR);
foreach($this->configuration['links'] as $repo => $data) {
if (!file_exists($data['path'])) {
$from = ROOT_DIR . $data['src'];
$to = ROOT_DIR . $data['path'];
symlink ($from, $to);
$output->writeln('<green>SUCCESS</green> symlinked <magenta>' . $data['src'] . '</magenta> -> <cyan>' . $data['path'] . '</cyan>');
$output->writeln('');
} else {
$output->writeln('<red>' . $data['path'] . ' already exists, skipping...</red>');
$output->writeln('');
}
}
}
}

View File

@@ -1 +0,0 @@
/Users/rhuk/Projects/github/grav-plugin-error

View File

@@ -1 +0,0 @@
/Users/rhuk/Projects/github/grav-plugin-problems

View File

@@ -1 +0,0 @@
/Users/rhuk/Projects/github/grav-theme-antimatter