-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/additional enhancements #7
Changes from 13 commits
adc7a80
7922450
d30c283
a3c34a4
af2783a
db9884b
86f6c1e
94d0a17
de34741
faa3e0c
be795f6
4fad679
ccad7ea
07c6df2
c9cba35
929b5df
9f7aa7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ | |
class SkeletorConfigurator | ||
{ | ||
protected $options; | ||
protected $optionFile; | ||
|
||
/** | ||
* SkeletorConfigurator constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->options = Yaml::parse(file_get_contents(__DIR__.'/skeletor.yml')); | ||
$this->optionFile = __DIR__.'/skeletor.yml'; | ||
$this->options = Yaml::parse(file_get_contents($this->optionFile)); | ||
} | ||
|
||
/** | ||
|
@@ -62,4 +64,13 @@ public function getConfig() | |
{ | ||
return $this->options; | ||
} | ||
|
||
/** | ||
* @param array $options | ||
*/ | ||
public function setConfig(array $options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we rename this method, we are saving/storing the config, setConfig implies you would be doing something like $this->config = $options |
||
{ | ||
$yaml = Yaml::dump($options); | ||
file_put_contents($this->optionFile, $yaml); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
config: | ||
name: Skeletor CLI | ||
name: 'Skeletor CLI' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for quotes since there is no special characters in the string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, i already couldn't remember changing this. But what happens, if you add a package and the |
||
version: 1.0.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there is a nice way to get the version number from the git tag automatically? |
||
frameworks: | ||
- Laravel54Framework | ||
- LaravelLumen54Framework | ||
packages: | ||
- BehatPackage | ||
- JsonBehatExtensionPackage | ||
- BehatBehatPackage | ||
- KielabokkieJsonapiBehatExtensionPackage | ||
defaultPackages: | ||
- GitHooksPackage | ||
- PixelfusionGitHooksPackage |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
namespace Skeletor\Console; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class AddNewPackage extends Command | ||
{ | ||
protected $cli; | ||
protected $packagistApi; | ||
protected $configurator; | ||
protected $packageManager; | ||
protected $skeletorFilesystem; | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('package:add') | ||
->setDescription('Add new package') | ||
->addArgument('name', InputArgument::REQUIRED, 'Package name'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->getApplication()->registerServices(); | ||
$this->setupCommand(); | ||
$package = $input->getArgument('name'); | ||
$this->cli->br()->yellow(sprintf('Skeletor - add new package, searching for %s', $package))->br(); | ||
|
||
$packageOptions = $this->packagistApi->searchPackage($package); | ||
if (empty($packageOptions)) { | ||
$this->cli->br()->red('package not found'); | ||
return; | ||
} | ||
|
||
$packageInfo['slug'] = $this->packageManager->specifyPackage($packageOptions); | ||
$packageInfo = $this->buildPackageInfo($packageInfo); | ||
if (in_array($packageInfo['name'], $this->packageManager->getAllPackageNames())) { | ||
$this->cli->br()->red('package already installed'); | ||
return; | ||
} | ||
|
||
$this->addPackageToConfig($packageInfo); | ||
$this->makePackageClass($packageInfo); | ||
} | ||
|
||
protected function setupCommand() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that this method is very similar to the one implemented in the other commands, should we maybe create an abstract SkeletorCommand and put in the there shared methods and make the actual commands extend from it instead of the Symfony Command |
||
{ | ||
$this->cli = $this->getApplication()->getCli(); | ||
$this->packagistApi = $this->getApplication()->getPackagistApi(); | ||
$this->configurator = $this->getApplication()->getConfigurator(); | ||
$this->packageManager = $this->getApplication()->getPackageManager(); | ||
|
||
$this->skeletorFilesystem = $this->getApplication()->getSkeletorFilesystem(); | ||
$this->packageManager->setPackages($this->getApplication()->getPackages()); | ||
$this->packageManager->setDefaultPackages($this->getApplication()->getDefaultPackages()); | ||
} | ||
|
||
/** | ||
* @param array $packageInfo | ||
* @return array | ||
*/ | ||
protected function buildPackageInfo(array $packageInfo) | ||
{ | ||
$packageName = preg_replace('/\//', ' ', $packageInfo['slug']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can group these two regular expressions, something like preg_replace('//|-/', ' ', $packageInfo['slug']); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, still learning regex 😃 |
||
$packageName = preg_replace('/\-/', ' ', $packageName); | ||
$packageName = ucwords($packageName); | ||
$packageInfo['name'] = $packageName; | ||
|
||
$packageName = preg_replace('/\s+/', '', $packageName); | ||
$packageInfo['class'] = $packageName.'Package'; | ||
|
||
return $packageInfo; | ||
} | ||
|
||
/** | ||
* @param array $packageInfo | ||
*/ | ||
protected function addPackageToConfig(array $packageInfo) | ||
{ | ||
$config = $this->configurator->getConfig(); | ||
$config['packages'][] = $packageInfo['class']; | ||
$this->configurator->setConfig($config); | ||
} | ||
|
||
/** | ||
* @param array $packageInfo | ||
*/ | ||
protected function makePackageClass(array $packageInfo) | ||
{ | ||
//Read stub | ||
$stub = $this->skeletorFilesystem->read('Templates/stubs/package.stub'); | ||
|
||
//Replace stub dummy data | ||
foreach ($packageInfo as $key => $info) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. following our standard, { on the same line as foreach |
||
$stub = str_replace($key.'Dummy', $info, $stub); | ||
} | ||
|
||
//Put final class in Skeletor | ||
$this->skeletorFilesystem->put( | ||
'Packages/'.$packageInfo['class'].'.php', | ||
$stub | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,14 @@ | |
namespace Skeletor\Console; | ||
|
||
use Skeletor\Frameworks\Framework; | ||
use Symfony\Component\Process\Process; | ||
use Skeletor\Exceptions\FailedFilesystem; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Process\Exception\ProcessFailedException; | ||
use Symfony\Component\Process\Process; | ||
|
||
|
||
class CreateProjectCommand extends Command | ||
{ | ||
|
@@ -42,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
$this->setupCommand(); | ||
|
||
//Start process in the background | ||
$process = new Process('php skeletor package:show --no-ansi'); | ||
$process = new Process('skeletor package:show --no-ansi'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it right that this is being changed back? This was a bugfix you did last time to sort the issue with the packagist API, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is a separate/new bug. So on composer global, the packages aren't fetched because it cant find the command. When removing the |
||
$process->setTimeout(7200); | ||
$process->start(); | ||
|
||
|
@@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
return false; | ||
} | ||
|
||
$activePackages = $this->packageManager->mergeSelectedAndDefaultPackages($activePackages); | ||
$activePackages = $this->packageManager->mergePackagesWithDefault($activePackages); | ||
$this->buildProject($activeFramework, $activePackages); | ||
$this->cli->br()->green('Yhea, success')->br(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,16 @@ public function getInstallablePackageNames() | |
}, $this->packages); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getAllPackageNames() | ||
{ | ||
return array_map(function(Package $package) { | ||
return $package->getName(); | ||
}, $this->mergePackagesWithDefault($this->packages)); | ||
} | ||
|
||
/** | ||
* @param array $names | ||
* @return array | ||
|
@@ -71,12 +81,12 @@ public function showPackagesTable(array $packages) | |
} | ||
|
||
/** | ||
* @param array $selectedPacakges | ||
* @param array $packages | ||
* @return array | ||
*/ | ||
public function mergeSelectedAndDefaultPackages(array $selectedPacakges) | ||
public function mergePackagesWithDefault(array $packages) | ||
{ | ||
return array_merge($selectedPacakges, $this->defaultPackages); | ||
return array_merge($packages, $this->defaultPackages); | ||
} | ||
|
||
/** | ||
|
@@ -122,6 +132,16 @@ public function specifyPackagesVersions(array $packages) | |
} | ||
} | ||
|
||
/** | ||
* @param array $packages | ||
* @return string with package slug | ||
*/ | ||
public function specifyPackage($packages) | ||
{ | ||
$packageQuestion = $this->cli->radio('Choose your packages:', $packages); | ||
return $packageQuestion->prompt(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line before a return |
||
} | ||
|
||
/** | ||
* @param Package $package | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace Skeletor\Packages; | ||
|
||
use Skeletor\Frameworks\Framework; | ||
|
||
class BehatBehatPackage extends Package | ||
{ | ||
public function setup() | ||
{ | ||
$this->setInstallSlug("behat/behat"); | ||
$this->setName("Behat Behat"); | ||
} | ||
|
||
public function configure(Framework $activeFramework) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty method, should we delete it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, what is the best practice. Because we define Should i remove it from the interface? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It case the best practise would be to have to interfaces, PackageInterface and ConfigurablePackageInterface that extends from PackageInterface. So you can pick the one you need for each case. |
||
{ | ||
//$this->projectFilesystem->put('PixelFusion.txt', '©PIXELFUSION'); | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we check $data is valid? something like json_last_error() === JSON_ERROR_NONE ? array_map(...) : []
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, implement this and for the
getVersionsPackage
as well