Skip to content

Commit b1648b0

Browse files
committed
Ditch fully-qualified paths.
Makes scripts more portable when they work relative to "where you are" (which should always be the project root folder.) This allows scripts to work both inside and outside of a Vagrant VM better, and to be more compatible with wrapping in `vagrant-exec`.
1 parent 530e0b9 commit b1648b0

File tree

11 files changed

+29
-72
lines changed

11 files changed

+29
-72
lines changed

cache-clear

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ if [ "$1" = '-h' ]; then
2626
fi
2727

2828

29-
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
30-
3129
echo "## Clearing cache folders.";
3230

3331
cat <<-'EOPHP' | bin/cake console

codesniffer-run

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ EOT
2727
# Set up local variables.
2828
umask a+rw
2929

30-
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
31-
TMP_DIR="${DIR}/tmp"
30+
TMP_DIR="tmp"
3231
REPORT_DIR="${TMP_DIR}/code-sniffs"
3332
FULL_REPORT_FILE="${REPORT_DIR}/report-full.txt"
3433
SUMMARY_REPORT_FILE="${REPORT_DIR}/report-summary.txt"

composer-install

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ fi
3434

3535

3636
# Set up working vars.
37-
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
38-
BIN_DIR="${DIR}/bin"
39-
COMPOSER_CONFIG_FILE="$DIR/composer.json"
40-
GUESSES=( "$( which composer )" "$BIN_DIR/composer" "$( which composer.phar )" "$BIN_DIR/composer.phar" )
37+
COMPOSER_CONFIG_FILE="composer.json"
38+
GUESSES=( "$( which composer )" "bin/composer" "$( which composer.phar )" "bin/composer.phar" )
4139

4240

4341
# Bail out if there's no config file present.

coverage-report

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@ if [ "$1" = '-h' ]; then
2424
fi
2525

2626

27-
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
28-
COVERAGE_PATH="tmp/coverage/html/"
27+
COVERAGE_PATH="tmp/coverage/html"
2928

3029

3130
# Launch the coverage in a browser if requested and we're on the host.
3231
if command -v 'open' >/dev/null 2>&1; then
33-
bin/vagrant-exec "vendor/bin/phpunit --coverage-html="$COVERAGE_PATH""
34-
open "${COVERAGE_PATH}index.html"
32+
bin/vagrant-exec "bin/phpunit --coverage-html="$COVERAGE_PATH""
33+
open "${COVERAGE_PATH}/index.html"
3534
else
36-
cd "$DIR"
3735
bin/phpunit --coverage-html="$COVERAGE_PATH"
3836
echo ""
39-
echo "## Run 'open ${COVERAGE_PATH}index.html'"
37+
echo "## Run 'open ${COVERAGE_PATH}/index.html'"
4038
echo "## from your host to view coverage reports in a browser."
4139
echo ""
4240
fi

db-backup

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ EOD;
4242
* @return string The converted value with the "closest" unit used.
4343
*/
4444
function human_filesize($bytes, $decimals = 2) {
45-
$sz = 'BKMGTP';
45+
$sz = 'BKMGTPEZY';
4646
$factor = floor((strlen(intval($bytes)) - 1) / 3);
4747
return (sprintf("%.{$decimals}f", intval($bytes) / pow(1024, $factor)) + 0) . @$sz[$factor];
4848
}
@@ -56,16 +56,15 @@ if (isset($argv[1]) && $argv[1] == '-h') {
5656
}
5757

5858
// Set up variables.
59-
$dir = getcwd();
60-
$backupDir = $dir . '/backups';
59+
$backupDir = 'backups';
6160
$date = date('Ymd-His');
6261
try {
63-
$credentialsScript = "{$dir}/bin/db-credentials";
62+
$credentialsScript = 'bin/db-credentials';
6463
if (!is_readable($credentialsScript)) {
6564
echo "!! DB credentials are not available. Aborting.";
6665
exit(3);
6766
}
68-
67+
6968
ob_start(); // Capture the shebang line from db-credentials.
7069
$db = include($credentialsScript);
7170
ob_get_clean(); // Flush it.

db-credentials

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ class DbConfig {
8282
* @return void
8383
*/
8484
public function __construct() {
85-
$dir = getcwd();
86-
$injectedCode = 'use Cake\Datasource\ConnectionManager; echo serialize(ConnectionManager::config("default")) . PHP_EOL; exit;'; // This must be on a single line to work with the REPL.
85+
$injectedCode = 'echo serialize(\Cake\Datasource\ConnectionManager::config("default")) . PHP_EOL; exit;'; // This must be on a single line to work with the REPL.
8786
$cmd = "echo '{$injectedCode}' | "
88-
. escapeshellcmd("{$dir}/bin/cake Console -q");
87+
. escapeshellcmd("bin/cake Console -q");
8988
$response = [];
9089
$code = 0;
9190
exec($cmd, $response, $code);

db-login

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ if [ "$1" = '--help' ]; then
3232
fi
3333

3434

35-
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
36-
BIN_DIR="$DIR/bin"
37-
3835
# Holy yuck, but nothing else works!
39-
eval $( ${BIN_DIR}/db-credentials )
36+
eval $( bin/db-credentials )
4037

4138
# Set a custom port, if provided to us.
4239
if [ -n "${DB_PORT}" ]; then

db-sample-data

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ ${0##*/}
1616
Usage:
1717
bin/${0##*/} [table] [table2] [table3]
1818
19+
Environment:
20+
DB_SAMPLE_DATA_URL - If this environment variable is set, it will
21+
be used when displaying the download URL for
22+
the temporary zip file.
1923
2024
EOT
2125

@@ -30,21 +34,18 @@ if [ -z "$1" ]; then
3034
else
3135
TABLES="--tables "$*""
3236
fi
33-
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
34-
APP_DIR="$DIR"
35-
BIN_DIR="${DIR}/bin"
3637

3738

3839
# Configuration vars. Set these appropriately for your app and environment.
39-
PUBLIC_URL=""
40-
WEBROOT_PATH="$APP_DIR/webroot/"
40+
PUBLIC_URL=${DB_SAMPLE_DATA_URL:-}
41+
WEBROOT_PATH="webroot/"
4142

4243

4344
# Internal var setup.
44-
eval $( ${BIN_DIR}/db-credentials ) # Yuck, but nothing else works!
45+
eval $( bin/db-credentials ) # Yuck, but nothing else works!
4546
DATE=$(date +%Y-%m-%d)
4647
OPTIONS="--skip-add-drop-table --no-create-info"
47-
TMP_PATH="$APP_DIR/tmp/"
48+
TMP_PATH="tmp/"
4849
DESTINATION_NAME="${DB_NAME}_sample_data_${DATE}"
4950

5051
# Generate the dump, compress it and move it into place.

logs-clear

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,5 @@ if [ "$1" = '-h' ]; then
2626
fi
2727

2828

29-
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
30-
3129
echo "## Clearing logs.";
32-
rm -f $DIR/logs/*
30+
rm -f logs/*

migrations

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ usage ()
66
cat <<EOT
77
88
${0##*/}
9-
Convenience wrapper to run any pending Migrations. Takes an optional
10-
Migrations COMMAND (defaults to "run all") and an optional plugin
11-
for which to execute migrations. Should be run from the project
12-
root folder.
9+
Convenience wrapper to run any pending Migrations. Should be
10+
run from the project root folder.
1311
1412
Usage:
15-
bin/${0##*/} [command] [plugin]
13+
bin/${0##*/}
1614
1715
1816
EOT
@@ -23,29 +21,6 @@ if [ "$1" = '-h' ]; then
2321
usage
2422
fi
2523

26-
27-
28-
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
29-
30-
if [ "$1" ]; then
31-
OPTION=$1;
32-
else
33-
OPTION="run all";
34-
fi
35-
36-
if [ "$2" ]; then
37-
PLUGIN=$2;
38-
else
39-
PLUGIN="app"
40-
fi
41-
42-
43-
if [ $PLUGIN == "app" ]; then
44-
PLUGIN=""
45-
else
46-
PLUGIN="-p $PLUGIN"
47-
fi
48-
49-
$DIR/bin/cache-clear
50-
$DIR/bin/cake Migrations.migration $OPTION $PLUGIN
51-
$DIR/bin/cache-clear
24+
bin/cache-clear
25+
bin/cake Migrations.migration migrate
26+
bin/cache-clear

0 commit comments

Comments
 (0)