From 7154d2e205a15511675e31f93fca8bc6bfcc0ad5 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 6 Aug 2014 21:32:42 -0600 Subject: [PATCH] added initial pass at install command --- .gitignore | 5 +- bin/grav | 1 + system/src/Grav/Console/CleanCommand.php | 2 +- system/src/Grav/Console/InstallCommand.php | 103 +++++++++++++++++++++ user/plugins/error | 1 - user/plugins/problems | 1 - user/themes/antimatter | 1 - 7 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 system/src/Grav/Console/InstallCommand.php delete mode 120000 user/plugins/error delete mode 120000 user/plugins/problems delete mode 120000 user/themes/antimatter diff --git a/.gitignore b/.gitignore index 38c92f5c9..306b28aa8 100755 --- a/.gitignore +++ b/.gitignore @@ -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/* diff --git a/bin/grav b/bin/grav index 05be1573e..a0e6ea705 100755 --- a/bin/grav +++ b/bin/grav @@ -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(), )); diff --git a/system/src/Grav/Console/CleanCommand.php b/system/src/Grav/Console/CleanCommand.php index 7b995562f..1eeae70f0 100644 --- a/system/src/Grav/Console/CleanCommand.php +++ b/system/src/Grav/Console/CleanCommand.php @@ -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 clean clean extraneous folders and data'); } diff --git a/system/src/Grav/Console/InstallCommand.php b/system/src/Grav/Console/InstallCommand.php new file mode 100644 index 000000000..b17960bf8 --- /dev/null +++ b/system/src/Grav/Console/InstallCommand.php @@ -0,0 +1,103 @@ +setName("install") + ->addOption( + 'symlink', + 's', + InputOption::VALUE_NONE, + 'Symlink the required bits' + ) + ->setDescription("Handles cloning and symlinking for Grav") + ->setHelp('The install 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('ERROR Missing .dependencies file'); + } + + + + + } + + // loops over the array of paths and deletes the files/folders + private function gitclone($output) + { + $output->writeln(''); + $output->writeln('Cloning Bits'); + $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('SUCCESS cloned ' . $data['url'] . ' -> ' . $data['path'] . ''); + $output->writeln(''); + } else { + $output->writeln('' . $data['path'] . ' already exists, skipping...'); + $output->writeln(''); + } + + } + } + + // loops over the array of paths and deletes the files/folders + private function symlink($output) + { + $output->writeln(''); + $output->writeln('Symlinking Bits'); + $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('SUCCESS symlinked ' . $data['src'] . ' -> ' . $data['path'] . ''); + $output->writeln(''); + } else { + $output->writeln('' . $data['path'] . ' already exists, skipping...'); + $output->writeln(''); + } + + } + } +} diff --git a/user/plugins/error b/user/plugins/error deleted file mode 120000 index 12a26ca75..000000000 --- a/user/plugins/error +++ /dev/null @@ -1 +0,0 @@ -/Users/rhuk/Projects/github/grav-plugin-error \ No newline at end of file diff --git a/user/plugins/problems b/user/plugins/problems deleted file mode 120000 index 45ce790a4..000000000 --- a/user/plugins/problems +++ /dev/null @@ -1 +0,0 @@ -/Users/rhuk/Projects/github/grav-plugin-problems \ No newline at end of file diff --git a/user/themes/antimatter b/user/themes/antimatter deleted file mode 120000 index 4360261fa..000000000 --- a/user/themes/antimatter +++ /dev/null @@ -1 +0,0 @@ -/Users/rhuk/Projects/github/grav-theme-antimatter \ No newline at end of file