operations / composer-project-bins
2.1.0
2024-01-25 15:15 UTC
Requires
- composer-plugin-api: ^2.0
This package is auto-updated.
Last update: 2024-09-11 16:19:39 UTC
README
您的脚本位于Composer的bin目录中。
此插件允许您将自定义脚本添加到项目的Composer bins中。
它的工作方式与依赖包的"bin"脚本一样:从您的供应商bin目录创建到脚本的链接。
优势
- 您项目中的所有命令都可以从同一个目录,供应商bin目录中运行。
- Composer bin目录和自动加载路径可以通过bash或PHP变量访问。
- 脚本可以使用此路径确保调用确切的脚本版本,例如
drush
或npm
。
有关更多信息,请参阅Composer "Vendor Binaries" 文档。
用法
-
安装插件。
$ composer require operations/project-bin-scripts
-
创建一个脚本文件。
#!/usr/bin/env bash # File: scripts/hello-world # If your script wants to rely on the other scripts in bin-dir, check for $COMPOSER_RUNTIME_BIN_DIR if [[ -z $COMPOSER_RUNTIME_BIN_DIR ]]; then echo "ERROR: The COMPOSER_RUNTIME_BIN_DIR environment variable is missing. Run this script from the composer vendor bin directory." exit 1 fi # Set the PATH variable to include COMPOSER_RUNTIME_BIN_DIR to allow calling # other bin scripts directly. PATH=$PATH:$COMPOSER_RUNTIME_BIN_DIR echo "Hello World!" echo "You are here:" pwd # To confirm this works, try using "which" echo "You are using this drush: " which drush drush --version
-
添加到
composer.json
{ "bin": [ "scripts/hello-world" ] }
-
运行composer install
$ composer install
-
从Composer bin路径运行您的脚本
./vendor/bin/hello-world
或者,如果设置了PATH,只需使用命令即可。
PATH=$PATH:./vendor/bin hello-world
关于composer schema的"bin"说明
这是与composer.json
依赖项模式相同的配置。在这里使用此配置可能会引起一些混淆。
使用此配置的主要原因是为了使插件能够使用与安装依赖项二进制文件相同的代码安装项目二进制文件。
如果您认为这很令人困惑并且应该更改,请提交一个pull request。
关于
- 创建者:Jon Pugh