hgraca / composer-shell-plugin
一个用于管理shell依赖的composer插件。
v2.0.2
2023-08-20 19:28 UTC
Requires
- php: ^8.2
- composer-plugin-api: ^2.0
Requires (Dev)
- composer/composer: ^2.5.8
- ergebnis/composer-normalize: ^2.34.0
- friendsofphp/php-cs-fixer: ^v3.22.0
- malukenho/mcbumpface: ^1.2.0
- overtrue/phplint: ^9.0.4
- phpstan/phpstan: ^1.10.26
- phpunit/phpunit: ^10.2.6
- psalm/plugin-phpunit: ^0.18.4
- rector/rector: ^0.15.25
- roave/security-advisories: dev-master
- vimeo/psalm: ^5.13.1
README
一个用于管理shell依赖的composer插件。
工作原理
该插件为shell包中的shell脚本生成自动加载器,然后在我们要使用依赖项的shell脚本的入口点中需要将其源(包含)。
这正是PHP包所发生的情况。
要生成shell自动加载器,它会遍历所有包,并为每个shell包搜索所有shell脚本,并将它们添加到shell自动加载器中。
如何使用
除了以下内容外,所有操作都与PHP项目相同。
在依赖于shell包的项目中
安装并允许插件
composer require "hgraca/composer-shell-plugin"
{
"name": "hgraca/some-project",
"type": "project",
"require": {
"hgraca/composer-shell-plugin": "dev-main"
},
"config": {
"allow-plugins": {
"hgraca/composer-shell-plugin": true
}
}
}
在脚本入口点中包含自动加载器
#!/usr/bin/env bash
# The "VENDOR_PATH" variable MUST be defined, as the autoloader depends on it,
# because there is no posix compliant way to infer this.
VENDOR_PATH="..."
. "${VENDOR_PATH}/autoload.sh"
# call the functions in the installed projects
在shell包中
标记项目为shell项目/库
在shell包的composer.json
中,将包类型设置为shell-project
或shell-library
。
例如
{
"name": "hgraca/dummy-shell-project-2",
"type": "shell-library",
"description": "A project to manually test the composer-shell-plugin plugin by being installed in another project."
}
一个工作示例
要查看工作示例,请检查tests/PluginTestPlayground
。
请随意运行
composer -d tests/PluginTestPlayground/TestProject install
tests/PluginTestPlayground/TestProject/bin/run.sh
定义包含shell脚本的文件夹(可选)
在shell包的composer.json
中,在extra.hgraca/composer-shell-plugin.source-folders
中设置应添加到自动加载器的文件夹列表。
这是可选的,默认情况下将使用src
文件夹。
例如
{
"name": "hgraca/dummy-shell-project-1",
"type": "shell-library",
"description": "A project to manually test the composer-shell-plugin plugin by being installed in another project.",
"extra": {
"hgraca/composer-shell-plugin": {
"source-folders": [
"src",
"lib"
]
}
}
}
如何运行
使用本地PHP(8.2)
- 使用
composer install
安装依赖项; - 可以使用
composer run-app
运行食谱; - 可以使用
composer test
运行测试; - 要列出所有自定义脚本,请运行
composer run-script --list
。
使用Docker
- 在
./build
中更改PHP和xdebug配置; - 使用
docker compose -f ./build/docker-compose.yaml run app composer install
安装依赖项; - 可以使用
docker compose -f ./build/docker-compose.yaml run app composer run-app
运行食谱; - 可以使用
composer docker-test
运行测试; - 要列出所有自定义脚本,请运行
docker compose -f ./build/docker-compose.yaml run app composer run-script --list
。
其他命令
composer git-bundle
:创建一个git bundlegit clone -b main composer-shell-plugin.gitbundle composer-shell-plugin
:从git bundle重新创建存储库