Skip to content

Commit 91431c8

Browse files
committed
Merge pull request #68 from loadsys/f/composer-reinstall
Add a new composer-reinstall script.
2 parents c0f38e8 + bf2aec7 commit 91431c8

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

composer-reinstall

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
3+
#---------------------------------------------------------------------
4+
usage ()
5+
{
6+
cat <<EOT
7+
8+
${0##*/}
9+
Purges composer's configured \`vendor-dir\` and any symlinks
10+
from the \`bin-dir\`, then runs \`composer install\`. Designed
11+
to help in development when composer dependencies "get weird"
12+
and need to be forcibly reset.
13+
14+
Usage:
15+
bin/${0##*/}
16+
17+
18+
EOT
19+
20+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
21+
}
22+
if [ "$1" = '-h' ]; then
23+
usage
24+
fi
25+
26+
27+
# Set up working vars.
28+
COMPOSER_CONFIG_FILE="composer.json"
29+
GUESSES=( "$(which composer)" "bin/composer" "$(which composer.phar)" "bin/composer.phar" )
30+
31+
32+
# Bail out if there's no config file present.
33+
if [ ! -e "$COMPOSER_CONFIG_FILE" ]; then
34+
echo "!! No composer config file at '$COMPOSER_CONFIG_FILE'."
35+
exit 2
36+
fi
37+
echo "## Found composer config at: ${COMPOSER_CONFIG_FILE}"
38+
39+
40+
# Bail out if composer isn't available to us.
41+
for GUESS in "$GUESSES"; do
42+
if [ -x "$GUESS" ]; then
43+
COMPOSER="$GUESS"
44+
break
45+
fi
46+
done
47+
if [ -z "$COMPOSER" ]; then
48+
echo "!! The 'composer' command was not found on this system."
49+
echo ""
50+
exit 1
51+
fi
52+
echo "## Found composer at: ${COMPOSER}"
53+
54+
COMPOSER_VENDOR_DIR="$($COMPOSER config --absolute vendor-dir)"
55+
COMPOSER_BIN_DIR="$($COMPOSER config --absolute bin-dir)"
56+
57+
# Purge the vendor folder entirely and just symlinks from the bin folder.
58+
echo "## Deleting vendor-dir: ${COMPOSER_VENDOR_DIR}"
59+
rm -rf "$COMPOSER_VENDOR_DIR"
60+
echo "## Removing bin-dir symlinks from: ${COMPOSER_BIN_DIR}"
61+
find "$COMPOSER_BIN_DIR" -type l -delete;
62+
63+
# Execute `composer install`
64+
echo "## Running install."
65+
"$COMPOSER" install --quiet --no-interaction --ignore-platform-reqs --optimize-autoloader "$@"

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"cache-clear",
2222
"codesniffer-run",
2323
"composer-install",
24+
"composer-reinstall",
2425
"coverage-ensure",
2526
"coverage-report",
2627
"db-backup",

0 commit comments

Comments
 (0)