-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
adc7a80
Fixed package:show command, what is running in the background
thijsbouwes 7922450
Updated the docs
thijsbouwes d30c283
Added a stub template for the base package object
thijsbouwes a3c34a4
Added the option to search the packagist api
thijsbouwes af2783a
Added a new command to add new packages
thijsbouwes db9884b
Added a getter for the configurator
thijsbouwes 86f6c1e
Made a method to update the current yaml file
thijsbouwes 94d0a17
Made the package classes the same as the slug, so there are no conflicts
thijsbouwes de34741
Changed the class naming of packages
thijsbouwes faa3e0c
Changed the get all slugs to get all names
thijsbouwes be795f6
Added some tests for the packagist api
thijsbouwes 4fad679
Made some small changes in the create project command
thijsbouwes ccad7ea
Changed the example namespace
thijsbouwes 07c6df2
Removed empty method, did some psr styling and optimized regex
thijsbouwes c9cba35
Implemented the skeletor base abstract class
thijsbouwes 929b5df
Fixed the add new package
thijsbouwes 9f7aa7a
Implemented the configurable package interface
thijsbouwes File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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