问题
I'm trying to write a composer.json file that will run several command line commands in a row so just as an example something like this:
"scripts": {
"test": [
"@createDir"
],
"createDir": "mkdir testing"
}
When I run the composer file in terminal using composer.phar update
the directory isn't created though. Can anybody point me in the right direction how to do this or what I'm doing wrong?
回答1:
Composer doesn't run all scripts by default at the end of an install
or update
. For that to happen, your script needs to be under one of the Command Event keys, e.g. post-update-cmd
.
You can still reference other scripts within these blocks, e.g.
"scripts": {
"post-install-cmd": [
"@test"
],
"test": [
"touch foo"
]
}
To run an individual script, you use the run-script
command:
composer run-script test
回答2:
Maybe the structure is wrong, let me show you an example:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.3.*",
"acacha/admin-lte-template-laravel": "dev-master",
"yajra/laravel-datatables-oracle": "^6.21",
"barryvdh/laravel-dompdf": "^0.7.0",
"spatie/laravel-backup": "^3.0.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.0",
"symfony/css-selector": "3.1.*",
"symfony/dom-crawler": "3.1.*"
},
"autoload": {
"classmap": [
"database",
"App/Helpers/MyCustomHelper"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
EDIT: Maybe you can try with composer dump-autoload
来源:https://stackoverflow.com/questions/48682416/run-command-line-command-in-composer-json