From 28e25898292bd8c03c8535a1d75703632bf80b07 Mon Sep 17 00:00:00 2001 From: vagrant Date: Tue, 8 Sep 2015 09:28:14 +0000 Subject: [PATCH] initial commit --- .DS_Store | Bin 0 -> 8196 bytes .editorconfig | 15 +++ changelog.md | 6 + composer.json | 29 +++++ contributing.md | 31 +++++ license.md | 20 +++ readme.md | 41 ++++++ skeleton/.DS_Store | Bin 0 -> 6148 bytes skeleton/CHANGELOG.md | 20 +++ skeleton/CONTRIBUTING.md | 33 +++++ skeleton/LICENSE.md | 21 ++++ skeleton/README.md | 74 +++++++++++ skeleton/composer.json | 44 +++++++ skeleton/config/.gitkeep | 0 skeleton/config/config.php | 8 ++ skeleton/database/migrations/.gitkeep | 0 skeleton/database/seeds/.gitkeep | 0 skeleton/resources/assets/.gitkeep | 0 skeleton/resources/lang/en/.gitkeep | 0 skeleton/resources/views/.gitkeep | 0 skeleton/src/.DS_Store | Bin 0 -> 6148 bytes skeleton/src/Contracts/.gitkeep | 0 skeleton/src/Http/.DS_Store | Bin 0 -> 6148 bytes skeleton/src/Http/Controllers/.gitkeep | 0 skeleton/src/Models/.gitkeep | 0 skeleton/src/Repositories/.gitkeep | 0 skeleton/src/ServiceProvider.php | 168 +++++++++++++++++++++++++ src/PackerHelper.php | 95 ++++++++++++++ src/PackerNewCommand.php | 113 +++++++++++++++++ src/PackerServiceProvider.php | 64 ++++++++++ 30 files changed, 782 insertions(+) create mode 100644 .DS_Store create mode 100644 .editorconfig create mode 100755 changelog.md create mode 100755 composer.json create mode 100755 contributing.md create mode 100755 license.md create mode 100755 readme.md create mode 100644 skeleton/.DS_Store create mode 100755 skeleton/CHANGELOG.md create mode 100755 skeleton/CONTRIBUTING.md create mode 100755 skeleton/LICENSE.md create mode 100755 skeleton/README.md create mode 100755 skeleton/composer.json create mode 100755 skeleton/config/.gitkeep create mode 100755 skeleton/config/config.php create mode 100755 skeleton/database/migrations/.gitkeep create mode 100755 skeleton/database/seeds/.gitkeep create mode 100755 skeleton/resources/assets/.gitkeep create mode 100755 skeleton/resources/lang/en/.gitkeep create mode 100755 skeleton/resources/views/.gitkeep create mode 100644 skeleton/src/.DS_Store create mode 100755 skeleton/src/Contracts/.gitkeep create mode 100644 skeleton/src/Http/.DS_Store create mode 100755 skeleton/src/Http/Controllers/.gitkeep create mode 100755 skeleton/src/Models/.gitkeep create mode 100755 skeleton/src/Repositories/.gitkeep create mode 100755 skeleton/src/ServiceProvider.php create mode 100755 src/PackerHelper.php create mode 100755 src/PackerNewCommand.php create mode 100755 src/PackerServiceProvider.php diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..377c78482c01b3a232d8bdfee74249b9979d8dff GIT binary patch literal 8196 zcmeHLTWl0n82hC!wzTE8%5wW@WP7^{^y+8y6w^^J{Z)QWX^xi zf15Mkd~?qH0|3}s(3=730YIUXOBSZ)8V9%Yv*M`oHPcBV#RC}Nfdh7W(9KnN2Z{iJ z0D%C30D%C30D&6;0ot?qp-iyvOKZ>u2m}cHFA?DDLzGS~i2$$N6>#AI)$Ue#{hqd*G}*4EbC&6PvDhW7s;-$dd5RL68V-l2hFRUz zJ;?!QFzIPt!EM#@yTr)UjkMqI(!7CEzuR%F(Y}`6VH$%eHml9CJ+bHP%-3t`-av}Y?#dfQ3hmNtV~6RQY11;j`;<^9q=Zsz&d^Y-DY`N?+!P&Z zUa^+?Yhvq$huH^;GXLgPE!+EZ!-tL?KXLNKmtOwxBZ&n1s|m~;hs@b)!J@kvD@`}T zeJe1t_BSUpPS*eL;mMyS<8ZayVwc3V>hTh;UzFjhPE%Xk5;NP?6q~{Cvoq(Jj_vL+ z@-E2~t91$Rtr^Gmap=uBRv~M1y3f-m$DM$2EDH{yxt* z=y6+xsc)z2t*$5{VA0};+U?TRndUn#ZB*6n14I?(`bn2JsgWK_OB)u`LozJZ ztVVi^50p5aBa2n3QIk*Uy;XC*Neu7`%SGbCR z)36p9)?oyfVk0iYW?YSHaUHJ5Hr#@D;x_ES9^8d{a4)8C0CSi}7d;%tNAOWRgpc77 zJdP*uB)*C7;Jf%9zK>_|Q@n^@%Slz0=)Sph2U6k{l9h~hi#eaIM_*YOQJ zg{K8?&)_+{fL}^(j&gRJ9G6=B>RO!5I*Ei{@G=1B+0k!=Zw0Tjj{c`UxqVRCmVmSs%aO^L#BL_@Ks~ChRFFpoXe+s>@w*`)09tgtYz%f{N+Z3UT;$^ z1L}GG-#+pG|LaW~_y-6C2>go>z?wud(Ml68eIAUTJFm5)bnc^*AKY(5N)bYhD91^P ua-5`Jjtk!?x$>B}FGr*#4ITgZkATvrU$Fnj|I)W=u>ZpqPSpR{{{K7tA+pE- literal 0 HcmV?d00001 diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cd8eb86 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/changelog.md b/changelog.md new file mode 100755 index 0000000..ea9292d --- /dev/null +++ b/changelog.md @@ -0,0 +1,6 @@ +# Changelog + +All Notable changes to Packer will be documented in this file. + +## Version 0.1 +Everything is brand new! diff --git a/composer.json b/composer.json new file mode 100755 index 0000000..9209cef --- /dev/null +++ b/composer.json @@ -0,0 +1,29 @@ +{ + "name": "laravolt/packer", + "description": "A cli tool for creating Laravel packages.", + "keywords": [ + "Packager", + "Laravel", + "package", + "skeleton" + ], + "homepage": "https://github.com/laravolt/packer", + "license": "EUPL-1.1", + "authors": [ + { + "name": "Bayu Hendra", + "email": "uyab.exe@gmail.com", + "homepage": "https://github.com/uyab" + } + ], + "require": { + "illuminate/support": "~5", + "illuminate/console": "~5", + "illuminate/filesystem": "~5", + }, + "autoload": { + "psr-4": { + "Laravolt\\Packer\\": "src" + } + } +} diff --git a/contributing.md b/contributing.md new file mode 100755 index 0000000..8c6fcd5 --- /dev/null +++ b/contributing.md @@ -0,0 +1,31 @@ +# Contributing + +Contributions are **welcome** via Pull Requests on [Github](https://github.com/laravolt/packer). + +An interesting read is [Contributing to a Github Project](http://jasonlewis.me/article/contributing-to-a-github-project). + +Also try to code in the same style as Laravel (which followes the [PSR standard](http://www.php-fig.org/) guidelines) + +**Happy coding**! + + +## Pull Requests + +- **Add tests!** - Your patch likely won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `readme.md`, `changlog.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. + +- **Create feature branches** - Don't ask us to pull from your master branch. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. + + +## Running Tests + +``` bash +$ phpunit +``` diff --git a/license.md b/license.md new file mode 100755 index 0000000..d15b592 --- /dev/null +++ b/license.md @@ -0,0 +1,20 @@ +# The EU Public License v1.1 + +Copyright (c) 2015 JeroenG + +Licensed under the EUPL, Version 1.1 or – as soon they +will be approved by the European Commission - subsequent +versions of the EUPL (the "Licence"); +You may not use this work except in compliance with the +Licence. +You may obtain a copy of the Licence at: + +https://joinup.ec.europa.eu/software/page/eupl5 + +Unless required by applicable law or agreed to in +writing, software distributed under the Licence is +distributed on an "AS IS" basis, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +express or implied. +See the Licence for the specific language governing +permissions and limitations under the Licence. \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100755 index 0000000..087bf5e --- /dev/null +++ b/readme.md @@ -0,0 +1,41 @@ +# Laravel Packager + +[![Latest Version](https://img.shields.io/github/release/jeroen-g/laravel-packager.svg?style=flat)](https://github.com/jeroen-g/laravel-packager/releases) +[![License](https://img.shields.io/badge/License-EUPL--1.1-blue.svg?style=flat)](license.md) + +This package provides you with a simple tool to set up a new Laravel package. It provides a complete boilerplate code that could actually be done by a package. Use what you need, remove the remaining. + +## Installation + +Via Composer + + $ composer require laravolt/packer + +Then add the service provider in `config/app.php`: + + 'Laravolt\Packer\PackerServiceProvider', + +## Usage + +### New package +The command will handle practically everything for you. It will create a packages directory, creates the vendor and package directory in it, pulls in a skeleton package, sets up composer.json, creates a service provider, registers the package in config/app.php and the app's composer.json. So you can start right away with only this command: + +``` bash +$ php artisan packer:new vendor_name package_name +``` + +## Contributing + +Please see [contributing.md](contributing.md) for details. + +## License + +The EU Public License. Please see [license.md](license.md) for more information. + +## Changelog + +Please see [changelog.md](changelog.md) for the changes made. + +## Credits + +This package was originally forked from [Jeroen-G/laravel-packager awesome package](https://github.com/Jeroen-G/laravel-packager). diff --git a/skeleton/.DS_Store b/skeleton/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..56d632f9f66736cda4f28c2cd43d23ade59f3ce5 GIT binary patch literal 6148 zcmeHKOHRW;4E4|o71%_qSmp}cAXMQ5U9l@oNvL*XX{YgAe%D6*BuD_~}i83PUK^eRIFbUx}Ya~1BIRrX+#uZJbljA|pW`!Mmi1~`5j{V>zQ}f3^)p|88=qfppAUTQ;Bcww zoR-iLbV1|984~3r`bgwNy+k?feq=v;bVFnG;c10c#p`-eO-J5OIi3h78ct*-T25v~ zO((JvZFkTz+TCtdUG4Tx&aerMe6+OA9v)@)o5*_`>+J4!JJNpjP(o(@AOo1$EWLw( zW{m-3z!=ytz~@5_Wh@k%fO2%e$Q1zCgsIWK^PViOP^i2V@|8q632Kgz%x D@Bxv8 literal 0 HcmV?d00001 diff --git a/skeleton/CHANGELOG.md b/skeleton/CHANGELOG.md new file mode 100755 index 0000000..881c4a1 --- /dev/null +++ b/skeleton/CHANGELOG.md @@ -0,0 +1,20 @@ +# Changelog + +All Notable changes to `:package_name` will be documented in this file + +## NEXT - YYYY-MM-DD + +### Added +- Nothing + +### Deprecated +- Nothing + +### Fixed +- Nothing + +### Removed +- Nothing + +### Security +- Nothing diff --git a/skeleton/CONTRIBUTING.md b/skeleton/CONTRIBUTING.md new file mode 100755 index 0000000..cfd8de4 --- /dev/null +++ b/skeleton/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +We accept contributions via Pull Requests on [Github](https://github.com/lara-league/:package_name). + + +## Pull Requests + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. + +- **Create feature branches** - Don't ask us to pull from your master branch. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. +- **Guidelines** - Please read the additional guidelines on [LaraLeague.com](http://laraleague.com). + + +## Running Tests + +``` bash +$ composer test +``` + + +**Happy coding**! diff --git a/skeleton/LICENSE.md b/skeleton/LICENSE.md new file mode 100755 index 0000000..9a1d265 --- /dev/null +++ b/skeleton/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License (MIT) + +Copyright (c) 2015 :author_name <:author_email> + +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. diff --git a/skeleton/README.md b/skeleton/README.md new file mode 100755 index 0000000..234dc31 --- /dev/null +++ b/skeleton/README.md @@ -0,0 +1,74 @@ +# :package_name + +[![Latest Version on Packagist][ico-version]][link-packagist] +[![Software License][ico-license]](LICENSE.md) +[![Build Status][ico-travis]][link-travis] +[![Coverage Status][ico-scrutinizer]][link-scrutinizer] +[![Quality Score][ico-code-quality]][link-code-quality] +[![Total Downloads][ico-downloads]][link-downloads] + + +**NOTE:** +- Replace ```:author_name``` ```:author_username``` ```:author_website``` ```:author_email``` ```:package_name``` ```:PackageName``` ```:package_description``` with their correct values in [README.md](README.md), [CHANGELOG.md](CHANGELOG.md), [CONTRIBUTING.md](CONTRIBUTING.md), [LICENSE.md](LICENSE.md), [PackageServiceProvider.php](src/PackageServiceProvider.php) and [composer.json](composer.json) files. +- Rename the file [PackageServiceProvider.php](src/PackageServiceProvider.php) and the Provider class to reflect the :PackageName. +- Delete the above lines up and including **NOTE:**. + +This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what +PSRs you support to avoid any confusion with users and contributors. + +## Install + +Via Composer + +``` bash +$ composer require league/:package_name +``` + +## Usage + +``` php +$skeleton = new League\Skeleton(); +echo $skeleton->echoPhrase('Hello, League!'); +``` + +## Change log + +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. + +## Testing + +``` bash +$ composer test +``` + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. + +## Security + +If you discover any security related issues, please contact [LaraLeague](https://github.com/lara-league). + +## Credits + +- [:author_name][link-author] +- [All Contributors][link-contributors] + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. + +[ico-version]: https://img.shields.io/packagist/v/league/:package_name.svg?style=flat-square +[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square +[ico-travis]: https://img.shields.io/travis/thephpleague/:package_name/master.svg?style=flat-square +[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/thephpleague/:package_name.svg?style=flat-square +[ico-code-quality]: https://img.shields.io/scrutinizer/g/thephpleague/:package_name.svg?style=flat-square +[ico-downloads]: https://img.shields.io/packagist/dt/league/:package_name.svg?style=flat-square + +[link-packagist]: https://packagist.org/packages/league/:package_name +[link-travis]: https://travis-ci.org/thephpleague/:package_name +[link-scrutinizer]: https://scrutinizer-ci.com/g/thephpleague/:package_name/code-structure +[link-code-quality]: https://scrutinizer-ci.com/g/thephpleague/:package_name +[link-downloads]: https://packagist.org/packages/league/:package_name +[link-author]: https://github.com/:author_username +[link-contributors]: ../../contributors diff --git a/skeleton/composer.json b/skeleton/composer.json new file mode 100755 index 0000000..f726987 --- /dev/null +++ b/skeleton/composer.json @@ -0,0 +1,44 @@ +{ + "name": ":vendor_name/:package_name", + "description": ":package_description", + "keywords": [ + ":vendor_name", + ":package_name" + ], + "homepage": "https://github.com/:vendor_name/:package_name", + "license": "MIT", + "authors": [ + { + "name": ":author_name", + "email": ":author_email", + "homepage": ":author_website", + "role": "Developer" + } + ], + "require": { + "php" : ">=5.5.0", + "illuminate/support": "~5.1" + }, + "require-dev": { + "phpunit/phpunit" : "4.*", + "scrutinizer/ocular": "~1.1" + }, + "autoload": { + "psr-4": { + ":VendorName\\:PackageName\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + ":VendorName\\:PackageName\\Test\\": "tests" + } + }, + "scripts": { + "test": "phpunit" + }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + } +} diff --git a/skeleton/config/.gitkeep b/skeleton/config/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/skeleton/config/config.php b/skeleton/config/config.php new file mode 100755 index 0000000..09553b3 --- /dev/null +++ b/skeleton/config/config.php @@ -0,0 +1,8 @@ + true +]; \ No newline at end of file diff --git a/skeleton/database/migrations/.gitkeep b/skeleton/database/migrations/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/skeleton/database/seeds/.gitkeep b/skeleton/database/seeds/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/skeleton/resources/assets/.gitkeep b/skeleton/resources/assets/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/skeleton/resources/lang/en/.gitkeep b/skeleton/resources/lang/en/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/skeleton/resources/views/.gitkeep b/skeleton/resources/views/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/skeleton/src/.DS_Store b/skeleton/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..355263f914ee1bb456c350ba070028d2fbe4c540 GIT binary patch literal 6148 zcmeHKJ5Izf5PgOSErKHDmcGK?AXFGEcC*qCAgpCL-LTEf;&{`(be6|K!4FBYd^&W0-m|< zgY{R5oFComU*F13Wj1jA^U z6)^*04Fzf_TZzFM4tp@aXqXi>oY;yFww1q%7cQ$Ke<<$6QPF#6z!?}aaIM3Iy#IIj z%T$Z}VTg~M0cYT!F~E~%-K=mZdt1+rCvR;)yGIidzbpy_`rsn~1Gz_T%B0Q*(cu>j Wv!Y}XdkF{nhd?33J7?ez82AK`*E*O0 literal 0 HcmV?d00001 diff --git a/skeleton/src/Http/Controllers/.gitkeep b/skeleton/src/Http/Controllers/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/skeleton/src/Models/.gitkeep b/skeleton/src/Models/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/skeleton/src/Repositories/.gitkeep b/skeleton/src/Repositories/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/skeleton/src/ServiceProvider.php b/skeleton/src/ServiceProvider.php new file mode 100755 index 0000000..c940a79 --- /dev/null +++ b/skeleton/src/ServiceProvider.php @@ -0,0 +1,168 @@ +registerViews(); + $this->registerMigrations(); + $this->registerSeeds(); + $this->registerAssets(); + $this->registerTranslations(); + $this->registerConfigurations(); + + if(! $this->app->routesAreCached() && config(':package_name.routes')) { + $this->registerRoutes(); + } + } + + /** + * Register the package views + * + * @see http://laravel.com/docs/5.1/packages#views + * @return void + */ + protected function registerViews() + { + // register views within the application with the set namespace + $this->loadViewsFrom($this->packagePath('resources/views'), ':package_name'); + // allow views to be published to the storage directory + $this->publishes([ + $this->packagePath('resources/views') => base_path('resources/views/:vendor_name/:package_name'), + ], 'views'); + } + + /** + * Register the package migrations + * + * @see http://laravel.com/docs/5.1/packages#publishing-file-groups + * @return void + */ + protected function registerMigrations() + { + $this->publishes([ + $this->packagePath('database/migrations') => database_path('/migrations') + ], 'migrations'); + } + + /** + * Register the package database seeds + * + * @return void + */ + protected function registerSeeds() + { + $this->publishes([ + $this->packagePath('database/seeds') => database_path('/seeds') + ], 'seeds'); + } + + /** + * Register the package public assets + * + * @see http://laravel.com/docs/5.1/packages#public-assets + * @return void + */ + protected function registerAssets() + { + $this->publishes([ + $this->packagePath('resources/assets') => public_path(':vendor_name/:package_name'), + ], 'public'); + } + + /** + * Register the package translations + * + * @see http://laravel.com/docs/5.1/packages#translations + * @return void + */ + protected function registerTranslations() + { + $this->loadTranslationsFrom($this->packagePath('resources/lang'), ':package_name'); + } + + /** + * Register the package configurations + * + * @see http://laravel.com/docs/5.1/packages#configuration + * @return void + */ + protected function registerConfigurations() + { + $this->mergeConfigFrom( + $this->packagePath('config/config.php'), ':package_name' + ); + $this->publishes([ + $this->packagePath('config/config.php') => config_path(':package_name.php'), + ], 'config'); + } + + /** + * Register the package routes + * + * @warn consider allowing routes to be disabled + * @see http://laravel.com/docs/5.1/routing + * @see http://laravel.com/docs/5.1/packages#routing + * @return void + */ + protected function registerRoutes() + { + $this->app['router']->group([ + 'namespace' => __NAMESPACE__ + ], function() { + // index action showing the packages + $this->app['router']->any('/:package_name', [ + 'as' => ':package_name:index', + 'uses' => 'Controllers\:PackageNameController@index' + ]); + + }); + } + + /** + * Loads a path relative to the package base directory + * + * @param string $path + * @return string + */ + protected function packagePath($path = '') + { + return sprintf("%s/../%s", __DIR__ , $path); + } +} diff --git a/src/PackerHelper.php b/src/PackerHelper.php new file mode 100755 index 0000000..2eddbae --- /dev/null +++ b/src/PackerHelper.php @@ -0,0 +1,95 @@ +files = $files; + } + + /** + * Setting custom formatting for the progress bar + * @param object $bar Symfony ProgressBar instance + * @return object $bar Symfony ProgressBar instance + */ + public function barSetup($bar) + { + // the finished part of the bar + $bar->setBarCharacter('='); + + // the unfinished part of the bar + $bar->setEmptyBarCharacter('-'); + + // the progress character + $bar->setProgressCharacter('>'); + + // the 'layout' of the bar + $bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% '); + + return $bar; + } + + /** + * Open haystack, find and replace needles, save haystack + * @param string $oldFile The haystack + * @param mixed $search String or array to look for (the needles) + * @param mixed $replace What to replace the needles for? + * @param string $newFile Where to save, defaults to $oldFile + * @return void + */ + public function replaceAndSave($oldFile, $search, $replace, $newFile = null) + { + $newFile = ($newFile == null) ? $oldFile : $newFile ; + $file = $this->files->get($oldFile); + $replacing = str_replace($search, $replace, $file); + $this->files->put($newFile, $replacing); + } + + /** + * Check if the package already exists + * @param string $path Path to the package directory + * @param string $vendor The vendor + * @param string $name Name of the package + * @return void Throws error if package exists, aborts process + */ + public function checkExistingPackage($path, $vendor, $name) + { + if(is_dir($path.$vendor.'/'.$name)){ + throw new RuntimeException('Package already exists'); + } + } + + /** + * Create a directory if it doesn't exist + * @param string $path Path of the directory to make + * @return void + */ + public function makeDir($path) + { + if(!is_dir($path)) { + return mkdir($path); + } + } +} diff --git a/src/PackerNewCommand.php b/src/PackerNewCommand.php new file mode 100755 index 0000000..c93e80c --- /dev/null +++ b/src/PackerNewCommand.php @@ -0,0 +1,113 @@ +helper = $helper; + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + // Start the progress bar + $bar = $this->helper->barSetup($this->output->createProgressBar(7)); + $bar->start(); + + // Common variables + $vendor = $this->argument('vendor'); + $name = $this->argument('name'); + $path = getcwd().'/packages/'; + $fullPath = $path.$vendor.'/'.$name; + $cVendor = ucfirst($vendor); + $cName = ucfirst($name); + $requirement = '"psr-4": { + "'.$cVendor.'\\\\'.$cName.'\\\\": "packages/'.$vendor.'/'.$name.'/src",'; + $appConfigLine = 'App\Providers\RouteServiceProvider::class, + '.$cVendor.'\\'.$cName.'\\'.'ServiceProvider::class,'; + + // Start creating the package + $this->info('Creating package '.$vendor.'\\'.$name.'...'); + $this->helper->checkExistingPackage($path, $vendor, $name); + $bar->advance(); + + // Create the package directory + $this->info('Creating packages directory...'); + $this->helper->makeDir($path); + $bar->advance(); + + // Create the vendor directory + $this->info('Creating vendor...'); + $this->helper->makeDir($path.$vendor); + $bar->advance(); + + // Copying package skeleton + $this->info('Copying package skeleton...'); + File::copyDirectory(__DIR__ . '/../skeleton', $fullPath); + + foreach(File::allFiles($fullPath) as $file) { + $search = [':vendor_name', ':VendorName', ':package_name', ':PackageName']; + $replace = [$vendor, $cVendor, $name, $cName]; + $this->helper->replaceAndSave($file, $search, $replace); + } + + $bar->advance(); + + + // Add it to composer.json + $this->info('Adding package to composer and app...'); + $this->helper->replaceAndSave(getcwd().'/composer.json', '"psr-4": {', $requirement); + //And add it to the providers array in config/app.php + $this->helper->replaceAndSave(getcwd().'/config/app.php', 'App\Providers\RouteServiceProvider::class,', $appConfigLine); + $bar->advance(); + + // Finished creating the package, end of the progress bar + $bar->finish(); + $this->info('Package created successfully!'); + $this->output->newLine(2); + $bar = null; + } +} diff --git a/src/PackerServiceProvider.php b/src/PackerServiceProvider.php new file mode 100755 index 0000000..a5fee2a --- /dev/null +++ b/src/PackerServiceProvider.php @@ -0,0 +1,64 @@ +'Laravolt\Packer\PackerServiceProvider', + * + * @package Packer + * @author uyab + * + **/ +class PackerServiceProvider extends ServiceProvider +{ + /** + * Indicates if loading of the provider is deferred. + * + * @var bool + */ + protected $defer = false; + + /** + * The console commands. + * + * @var bool + */ + protected $commands = [ + 'Laravolt\Packer\PackerNewCommand' + ]; + + /** + * Bootstrap the application events. + * + * @return void + */ + public function boot() + { + // Not really anything to boot. + } + + /** + * Register the command. + * + * @return void + */ + public function register() + { + $this->commands($this->commands); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array('laravolt.packer'); + } +}