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