我有没有代码但有依赖项列表的作曲家项目。我想运行composer install下载所有依赖包,然后在每个包中运行一些 bash 命令。
我的作曲家.json:
{
"name": "testmain/testmain",
"description": "testmain",
"minimum-stability": "dev",
"repositories": [{
"type": "package",
"package": {
"name": "testsub/testsub1",
"description": "testsub/testsub1",
"version": "master",
"source": {
"url": "https://github.com/testsub/testsub1",
"type": "git",
"reference": "master"
},
"scripts": {
"post-install-cmd": [
"make",
"make install"
]
}
}
},
{
"type": "package",
"package": {
"name": "testsub/testsub2",
"description": "testsub/testsub2",
"version": "master",
"source": {
"url": "https://github.com/testsub/testsub2",
"type": "git",
"reference": "master"
},
"scripts": {
"post-install-cmd": [
"make",
"make install"
]
}
}
}
],
"require": {
"testsub/testsub1": "master",
"testsub/testsub2": "master"
}
}Run Code Online (Sandbox Code Playgroud)
问题在于scripts嵌套包的运行顺序,所有脚本都被 Composer 忽略。
谢谢!
正如 Tomas 所说,不可能自动调用非 ROOT 脚本。但您可以允许用户手动调用它们。这并不适用于所有情况,但在其他情况下却很好。
如果您有以下内容vendor/johndoe/mypackage/composer.json:
"scripts": {
"nameOfScript": "\\johndoe\\mypackage\\Scripts::invoke"
}
Run Code Online (Sandbox Code Playgroud)
在composer.json您的根目录中放置以下内容:
"scripts": {
"myFancyScript": [
"@putenv COMPOSER=vendor/johndoe/mypackage/composer.json",
"@composer nameOfScript"
]
}
Run Code Online (Sandbox Code Playgroud)
然后用户可以从根目录调用并执行包中的composer myFancyScript静态函数。invoke()johndoe/mypackage