From b73a0250a9ade973102c6242345f0c5e7baf0501 Mon Sep 17 00:00:00 2001 From: Henry Paradiz Date: Fri, 18 May 2018 18:54:45 -0400 Subject: [PATCH] Initial commit --- .gitignore | 2 + bin/divergence | 5 + composer.json | 33 ++++ readme.md | 40 +++++ src/Command.php | 236 +++++++++++++++++++++++++ src/Controllers/CommandLineHandler.php | 48 +++++ 6 files changed, 364 insertions(+) create mode 100644 .gitignore create mode 100755 bin/divergence create mode 100644 composer.json create mode 100644 readme.md create mode 100644 src/Command.php create mode 100644 src/Controllers/CommandLineHandler.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88e99d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor +composer.lock \ No newline at end of file diff --git a/bin/divergence b/bin/divergence new file mode 100755 index 0000000..a39bf6c --- /dev/null +++ b/bin/divergence @@ -0,0 +1,5 @@ +#!/usr/bin/env php +backgroundYellow()->black()->out("No composer.json detected."); + static::$climate->backgroundYellow()->black()->out('Run composer init first!'); + return; + } + + if(static::$isRequired) { + static::$climate->info('divergence/divergence is already in your composer.json require.'); + static::$climate->info('Run composer install && composer update if you have not already.'); + } else { + static::$climate->info('divergence/divergence is not in your composer.json require.'); + $input = static::$climate->input('Do you want to run composer require divergence/divergence for this project? [y,n]'); + $input->accept(['y', 'yes','no','n']); + + $response = $input->prompt(); + if(in_array($response,['y','yes'])) { + shell_exec("composer require divergence/divergence --ansi"); + static::getEnvironment(); // force recheck + } + } + + static::checkDirectories(); + + static::checkAutoloader(); + } + + public static function checkAutoloader() + { + if(!static::$package['autoload']) { + static::$climate->info('No local autoloaded directory found!'); + static::$namespace = null; + } + + $autoloaders = []; + + if(!static::$namespace) { + if(static::$package['autoload']['psr-4']) { + $autoloaders = array_merge($autoloaders,static::$package['autoload']['psr-4']); + } + if(static::$package['autoload']['psr-0']) { + $autoloaders = array_merge($autoloaders,static::$package['autoload']['psr-4']); + } + } + + dump($autoloaders); + + if(count($autoloaders) === 1) { + // prompt: found 1 autoloader config. Is this your namespace? + } + elseif(count($autoloaders) > 1) { + // prompt: found count($autoloaders) autoloader configs. Which one is your namespace? + } + + if(!count($autoloaders)) { + // prompt: do you want to create a new namespace? default: name of this package from composer.json + } + + } + + public static function checkDirectories() + { + $freshInstall = true; + + $requiredFiles = [ + 'bootstrap/app.php', + 'bootstrap/autoload.php', + 'bootstrap/router.php', + 'config/app.php', + 'config/db.php', + 'public/index.php', + 'public/.htaccess', + 'views/dwoo/design.tpl', + ]; + + foreach($requiredFiles as $file) { + if(!file_exists(getcwd().'/'.$file)) { + static::$climate->error($file.' missing.'); + } else { + $freshInstall = false; + } + } + + if($freshInstall) { + static::$climate->info('Looks like this is a fresh install'); + $input = static::$climate->input('Do you want to bootstrap this project with framework defaults? [y,n]'); + $input->accept(['y', 'yes','no','n']); + + $response = $input->prompt(); + if(in_array($response,['y','yes'])) { + foreach($requiredFiles as $file) { + $source = 'vendor/divergence/divergence/'.$file; + $dest = getcwd().'/'.$file; + if(!file_exists(dirname($dest))) { + mkdir(dirname($dest),0777,true); + } + copy($source,$dest); + } + $freshInstall = false; + } + } else { + static::$climate->info('Looks like this project has been bootstrapped.'); + } + } + + public static function status() + { + if(!static::$hasComposer) { + static::$climate->backgroundYellow()->black()->out("No composer.json detected."); + return; + } + + static::$climate->info(sprintf('Found %s',static::$package['name'])); + + if(!static::$isRequired && !static::$isRequireDev) { + static::$climate->backgroundYellow()->black()->out('Did not find divergence/divergence in composer.json require'); + static::$climate->backgroundYellow()->black()->out('Run divergence init to bootstrap your project'); + return; + } + + if(static::$isRequired) { + static::$climate->info('Found divergence/divergence in composer.json require'); + } + + if(static::$isRequireDev) { + static::$climate->info('Found divergence/divergence in composer.json require-dev'); + } + + + } + + public static function version() + { + static::$climate->out('Divergence Command Line Tool'); + } + + public static function usage() + { + static::version(); + static::$climate->out(''); + static::$climate->out(" divergence [command] [arguments]"); + static::$climate->out(''); + static::$climate->out(''); + static::$climate->bold("\tAvailable Arguments"); + static::$climate->out("\t--version, -v\t\tVersion information"); + static::$climate->out(''); + static::$climate->out("\thelp, --help, -h\tThis help information"); + static::$climate->out(''); + static::$climate->bold("\tAvailable Commands"); + static::$climate->out(''); + static::$climate->out("\tinit\t\tBootstraps a new Divergence project."); + static::$climate->out("\tstatus\t\tShows information on the current project."); + static::$climate->out("\tbuild\t\tA suite of commands for automatically building project components."); + } +} \ No newline at end of file diff --git a/src/Controllers/CommandLineHandler.php b/src/Controllers/CommandLineHandler.php new file mode 100644 index 0000000..52b61c8 --- /dev/null +++ b/src/Controllers/CommandLineHandler.php @@ -0,0 +1,48 @@ +