rollandrock / composer-interaction
Requires
- php: ^7.4
- composer-plugin-api: ^1.1
- ext-json: *
- symfony/console: ^4.4
- symfony/dotenv: ^4.4
Requires (Dev)
- composer/composer: ^1.9
- phpspec/phpspec: ^6.1
This package is auto-updated.
Last update: 2024-09-17 23:32:35 UTC
README
此composer插件允许您的composer create-project
命令询问一些必要的信息,用于安装可选的新包或在安装后替换一些占位符。
通过在应用程序骨架的composer.json
中设置一些配置,composer将询问任何类型的问题,并相应地执行操作。
此外,插件在项目创建后将自动销毁,使您的最终composer.json
保持清洁。
用法
在骨架的composer.json
中添加以下行
{ "require": { "rollandrock/composer": "^1.0" }, "extra": { "rollandrock-interaction": { "questions": [ { "type": "add-package", "question": "Would you like to do stuff?" }, { "type": "replace", "question": "What is the name of your dog?" } ] } } }
问题配置
目前有两个动作将跟随您的问题:"add-package"和"replace"。
add-package
此操作将在用户对问题回答“是”时安装所有必需的包。它还可以添加项目所需的环境变量(可选)。以下此类问题的配置示例
{ "action": "add-package", "question": "Would you like to add a bundle to help you configure RabbitMQ vhosts?", "packages": { "olaurendeau/rabbit-mq-admin-toolkit-bundle": "^2.0" }, "env": { "RABBITMQ_USER": "rollandrock" } }
如果用户回答“是”,composer将安装olaurendeau/rabbit-mq-admin-toolkit-bundle
并将RABBITMQ_USER
添加到.env
文件中。
add-package
问题的配置还可以有一个reference
属性,这将允许询问条件问题。参见条件问题部分。
replace
此操作将搜索给定的占位符,并将其替换为用户的答案。问题可以有“free”或“choice”两种类型。如果选择“choice”,您需要添加一个额外的键“choices”。示例
{ "action": "replace", "question": "What is the application's name?", "type": "free", "placeholders": [ { "file": "config/parameters.yaml", "placeholder": "{APP_NAME}" } ] }, { "action": "replace", "question": "What is the application's type?", "type": "choice", "choices": ["api", "worker", "service"], "placeholders": [ { "file": "config/parameters.yaml", "placeholder": "{APP_TYPE}" } ] }
条件问题
每个问题都可以有一个if
属性。在这种情况下,如果引用的布尔问题(add-package
问题)已收到“是”的答案,则会提出该问题。
示例
[ { "reference": "rmq", "action": "add-package", "question": "Would you like to install RabbitMQ?", "packages": { "swarrot/swarrot-bundle": "*" } }, { "if": "rmq", "reference": "rmq-config", "action": "add-package", "question": "Would you like to add a bundle to help you configure RabbitMQ vhosts?", "packages": { "olaurendeau/rabbit-mq-admin-toolkit-bundle": "^2.0" } }, { "if": "rmq-config", "action": "replace", "question": "What is the application's name?", "type": "free", "placeholders": [ { "file": "config/parameters.yaml", "placeholder": "{APP_NAME}" } ] } ]
在这里,第二个问题只有在用户对第一个问题的回答为“是”时才会提出。同样,第三个问题只有在用户对其他问题的回答为“是”时才会提出。
自动删除
此插件在项目创建后自动删除。这意味着插件的需求和额外配置不会出现在最终的composer.json
中。