Last active
August 29, 2015 14:07
-
-
Save MarijnKoesen/bc5008845fd65f586bca to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# | |
# A wrapper arround composer to make it possible to annotate your composer.json file | |
# | |
# ## Installation | |
# | |
# 1) Install composer globally: | |
# - composer global require composer/composer @dev | |
# 2) Create a /usr/bin/composer file with the content of this file | |
# | |
# | |
# ## Usage | |
# | |
# Create a 'composer.annotated.json' file like your normal composer.json. | |
# | |
# In this file you can add comments like you want in the '//' format. | |
# | |
# When your run composer the 'composer.annotated.json' will be copied to 'composer.json' and composer is run. | |
# After the composer command is completed the composer.json file is removed to prevent having two composer files. | |
# | |
# Just always edit the composer.annotated.json file and use this wrapper. | |
# | |
# If the script does not find a 'composer.annotated.json' file, the script just calls composer directly without | |
# copying or removing anything, it just functions like composer does. | |
# | |
COMPOSER=~/.composer/vendor/bin/composer | |
cleanUp() | |
{ | |
rm composer.json | |
} | |
control_c() | |
{ | |
# run if user hits control-c | |
cleanUp | |
exit $? | |
} | |
if [ -e "composer.annotated.json" ]; then | |
# Trap keyboard interrupt (control-c) and execute control_c() when it happens | |
trap control_c SIGINT | |
# Copy our annotated json to the normal json file so we can run composer | |
cp composer.annotated.json composer.json | |
# This can be improved by using JSMin or something like that | |
sed -i '' 's/\/\/.*//' composer.json | |
# Run composer passing the same arguments as this wrapper was run with | |
${COMPOSER} "$@" | |
# Remove the composer.json file as we only want 1 composer json (either annotated or not) | |
# to prevent synchronization errors | |
cleanUp | |
else | |
${COMPOSER} "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment