I wrote a an system using laravel 5.2. This system have multiple modules/package capability. All of the modules will be located in a folder called modules.
to get started, I wrote a small package which is located in a folder called modules/Mikea/Surveys. The folder Mikea is the vendor's name and Surveys is the module/package name. Each package must have it's own composer.json file which allows the developer to configure each package with it's own composer configs.
The idea here is to have one laravel installation that supports extension to allow any developer to contribute into my main "system."
Here is how my modules folder looks like
modules
modules/Mikea
modules/Mikea/Surveys
modules/Mikea/Surveys/database
modules/Mikea/Surveys/resources
modules/Mikea/Surveys/composer.json
modules/Mikea/Surveys/routes.php
modules/Mikea/Surveys/src
modules/Mikea/Surveys/src/Controllers
modules/Mikea/Surveys/src/Jobs
modules/Mikea/Surveys/src/Models
modules/Mikea/Surveys/src/....
In my main composer.json file I am using "path" type in the repositories section like you see in the following composer.json file
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"laravelcollective/html": "5.2.x-dev",
"mikea/surveys": "*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"symfony/dom-crawler": "~3.0",
"symfony/css-selector": " ~3.0"
},
"repositories": [
{
"type": "path",
"url": "modules/mikea/Surveys"
}
],
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
In modules/Mikea/Surveys I have another composer.json file that allows me to configure each package separately like, package version, license, author....
Here is a copy of my second composer.json file "composer.json for my extension"
{
"name": "mikea/surveys",
"type": "library",
"version": "0.1.4",
"description": "Survey System",
"keywords": ["Mike A", "Surveys"],
"license": "MIT",
"authors": [
{
"name": "Mike A",
"email": "mikea@example.com"
}
],
"require": {
"php": ">=5.4.0"
},
"autoload": {
"classmap": [
"database/migrations",
"database/seeds"
],
"psr-4": {
"mikea\\Surveys\\": "src/"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
Everything works fine right now. All I have to do is execute composer update from the command line. It will simply copy the files from \modules\Mikea\Surveys into \vendor\mikea\Surveys
Then I can publish my views using the command line.
The problem that I am facing is that every time I make a change to the files in modules/Mikea/Surveys I will have to do the following 2 ugly steps to see my work in the browsers.
- In my second
composer.jsonfile, I have to increase the value of the version number of my modules "basically trick composer to think there is a new version of the package" - run
composer updateto copy the files all over again from\modules\Mikea\Surveysinto\vendor\mikea\Surveys
This is obviously too much work and no one want to do this!
How can I do to tell composer to auto load the files from modules/Mikea/Surveys while I am in development mode? So instead keep changing/updating I would keep working from the \modules\Mikea\Surveys folder until I am ready to release a new release of my package. Once ready, I would create a new version and run composer update to get the latest available version.
I am open to better ideas on how to develop such a system.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire