-
-
Save SebastiaanKloos/f4910e8fe6ea95631c70fe735667d4d2 to your computer and use it in GitHub Desktop.
Bash script to simply require a local composer package by providing it's repository path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if a path argument is provided | |
if [ $# -eq 0 ]; then | |
echo "Please provide the path to the local repository." | |
exit 1 | |
fi | |
# Get the absolute path of the provided directory | |
repo_path=$(cd "$1" && pwd) | |
# Check if the directory exists | |
if [ ! -d "$repo_path" ]; then | |
echo "The provided path is not a valid directory." | |
exit 1 | |
fi | |
# Get the name of the directory (to be used as the repository name) | |
repo_name=$(basename "$repo_path") | |
# Add the repository to composer.json | |
composer config repositories.$repo_name '{"type": "path", "url": "'$repo_path'", "options": {"symlink": true}}' | |
echo "Repository $repo_name added successfully." | |
# Read the package name from composer.json | |
if [ -f "$repo_path/composer.json" ]; then | |
package_name=$(awk -F'"' '/"name": ".+"/ {print $4; exit}' "$repo_path/composer.json") | |
if [ -n "$package_name" ]; then | |
# Optionally, you can also require the package | |
read -p "Do you want to require the package $package_name? (y/n) " answer | |
if [[ $answer =~ ^[Yy]$ ]]; then | |
composer require "$package_name:@dev" | |
echo "Package $package_name has been required." | |
fi | |
else | |
echo "Could not find package name in composer.json." | |
fi | |
else | |
echo "composer.json not found in the repository." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment