-
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 16 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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
namespace Skeletor\Console; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class AddNewPackage extends SkeletorCommand | ||
{ | ||
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->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->makePackageClass($packageInfo); | ||
$this->addPackageToConfig($packageInfo); | ||
} | ||
|
||
/** | ||
* @param array $packageInfo | ||
* @return array | ||
*/ | ||
protected function buildPackageInfo(array $packageInfo) | ||
{ | ||
$packageName = preg_replace('/\/|-/', ' ', $packageInfo['slug']); | ||
$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->storeConfig($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) { | ||
$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,21 +2,16 @@ | |
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 | ||
{ | ||
protected $frameworkManager; | ||
protected $packageManager; | ||
protected $cli; | ||
|
||
class CreateProjectCommand extends SkeletorCommand | ||
{ | ||
protected function configure() | ||
{ | ||
$this->setName('project:create') | ||
|
@@ -38,11 +33,10 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
$this->setupFolder($name); | ||
} | ||
|
||
$this->getApplication()->registerServices($dryRun); | ||
$this->setupCommand(); | ||
$this->setupCommand($dryRun); | ||
|
||
//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,22 +60,11 @@ 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(); | ||
} | ||
|
||
private function setupCommand() | ||
{ | ||
$this->frameworkManager = $this->getApplication()->getFrameworkManager(); | ||
$this->packageManager = $this->getApplication()->getPackageManager(); | ||
$this->cli = $this->getApplication()->getCli(); | ||
|
||
$this->frameworkManager->setFrameworks($this->getApplication()->getFrameworks()); | ||
$this->packageManager->setPackages($this->getApplication()->getPackages()); | ||
$this->packageManager->setDefaultPackages($this->getApplication()->getDefaultPackages()); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
namespace Skeletor\Console; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
|
||
abstract class SkeletorCommand extends Command | ||
{ | ||
protected $cli; | ||
protected $packagistApi; | ||
protected $configurator; | ||
protected $packageManager; | ||
protected $frameworkManager; | ||
protected $skeletorFilesystem; | ||
|
||
protected function setupCommand($dryRun = false) | ||
{ | ||
$this->getApplication()->registerServices($dryRun); | ||
|
||
$this->cli = $this->getApplication()->getCli(); | ||
$this->packagistApi = $this->getApplication()->getPackagistApi(); | ||
$this->configurator = $this->getApplication()->getConfigurator(); | ||
$this->skeletorFilesystem = $this->getApplication()->getSkeletorFilesystem(); | ||
|
||
$this->frameworkManager = $this->getApplication()->getFrameworkManager(); | ||
$this->packageManager = $this->getApplication()->getPackageManager(); | ||
|
||
$this->frameworkManager->setFrameworks($this->getApplication()->getFrameworks()); | ||
$this->packageManager->setPackages($this->getApplication()->getPackages()); | ||
$this->packageManager->setDefaultPackages($this->getApplication()->getDefaultPackages()); | ||
} | ||
} |
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