我正在尝试编写一个将连续运行多个命令行命令的composer.json文件,所以就像这样的示例:
"scripts": {
"test": [
"@createDir"
],
"createDir": "mkdir testing"
}
当我使用composer.phar update
在终端中运行composer文件时,不会创建目录。任何人都可以指出我正确的方向如何做到这一点或我做错了什么?
答案 0 :(得分:1)
默认情况下,在install
或update
结束时,Composer不会运行所有脚本。要实现这一点,您的脚本需要位于Command Event个密钥之一,例如post-update-cmd
。
您仍然可以引用这些块中的其他脚本,例如
"scripts": {
"post-install-cmd": [
"@test"
],
"test": [
"touch foo"
]
}
要运行单个脚本,请使用run-script
命令:
composer run-script test
答案 1 :(得分:0)
也许结构错了,让我给你举个例子:
{
"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"
}
}
编辑:也许你可以试试composer dump-autoload
答案 2 :(得分:0)
如果你想运行一个应该永远运行的命令,这对你有帮助
在 composer.json 中
"scripts": {
"start-lumen" : [
"php -S localhost:8000 -t public"
]
}
添加 --timeout=0 以永久运行
composer run-script start-lumen --timeout=0