jonpugh / composer-project-bins
Include bin scripts in top level composer projects.
Installs: 183
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:composer-plugin
Requires
- composer-plugin-api: ^2.0
This package is auto-updated.
Last update: 2024-11-11 16:43:35 UTC
README
Your scripts in the Composer bin-dir.
This plugin allows you to add your own scripts as composer bins to projects.
It works just like dependent packages "bin" scripts work: a link is created from your vendor bin directory to the script.
Advantages:
- All commands for your project can be run from the same directory, the vendor bin dir.
- The composer bin dir and autoloader path are available via bash or PHP variables.
- Scripts can use ensure they are calling exact versions of scripts such as
drush
ornpm
by including this path.
See Composer "Vendor Binaries" Documentation for more information.
Usage
-
Install the plugin.
$ composer require operations/project-bin-scripts
-
Create a script file.
#!/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
-
Add to
composer.json
:{ "bin": [ "scripts/hello-world" ] }
-
Run composer install:
$ composer install
-
Run your script from the composer bin path:
./vendor/bin/hello-world
Or, if you set PATH, just use the command.
PATH=$PATH:./vendor/bin hello-world
NOTE about composer schema for "bin"
This is the same configuration used by composer.json
schema for dependencies.
Using this same config here might cause some confusion.
The main reason this was used is so the plugin could use the exact same code to install project binaries as it does dependency binaries.
If you think this is confusing and should change, please submit a pull request.
About
- Created by: Jon Pugh