]> git.wincent.com - wincent.git/commitdiff
refactor: leverage PATH in scripts
authorGreg Hurrell <greg@hurrell.net>
Thu, 19 Mar 2020 23:55:25 +0000 (00:55 +0100)
committerGreg Hurrell <greg@hurrell.net>
Thu, 19 Mar 2020 23:55:25 +0000 (00:55 +0100)
bin/common
bin/n
bin/node
bin/yarn
install-next

index 5316eb5a82203001a43d4724bc2e104f8a827ca5..8efe6aec8bdf970ef54373e04757c120a2f937bf 100755 (executable)
@@ -6,6 +6,14 @@ if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then
   exit 1
 fi
 
+# https://stackoverflow.com/a/12694189/2103996
+REPO_ROOT="${BASH_SOURCE%/*}/.."
+
+# https://stackoverflow.com/a/4045350/2103996
+BIN_DIR=$(cd "$REPO_ROOT/bin" && pwd)
+
+export PATH="$BIN_DIR":$PATH
+
 log_debug() {
   if [[ -n $DEBUG ]]; then
     echo "[debug] $*" > /dev/stderr
diff --git a/bin/n b/bin/n
index 590c8145a1e80684c248c9facd5748d5667a5e05..84c192efa2572bc1b0ef65f86974afb38e04a455 100755 (executable)
--- a/bin/n
+++ b/bin/n
@@ -3,15 +3,15 @@
 set -e
 
 REPO_ROOT="${BASH_SOURCE%/*}/.."
-BIN_DIR="$REPO_ROOT/bin"
+
+source "$REPO_ROOT/bin/common"
+
 VENDOR_ROOT="$REPO_ROOT/vendor"
 N_EXE="$VENDOR_ROOT/n/bin/n"
 N_PREFIX="$VENDOR_ROOT/node"
 
 export N_PREFIX
 
-source "$BIN_DIR/common"
-
 if [[ ! -x $N_EXE ]]; then
   log_error "No executable at $N_EXE; did you forget to \`git submodule update\`?"
   exit 1
index 44010ab074d946f37df8713c53343aefee02c29e..712c83a797d6d6b122f69150efa8816501d9bd53 100755 (executable)
--- a/bin/node
+++ b/bin/node
@@ -3,6 +3,7 @@
 set -e
 
 REPO_ROOT="${BASH_SOURCE%/*}/.."
-N_EXE="$REPO_ROOT/bin/n"
 
-"$N_EXE" run lts "$@"
+source "$REPO_ROOT/bin/common"
+
+n run lts "$@"
index 1c35f2f02f1e21dae983bc85f86634393b8cee97..65bfe2858148916f6d3ff15b47ad3407f4c3109a 100755 (executable)
--- a/bin/yarn
+++ b/bin/yarn
@@ -3,7 +3,9 @@
 set -e
 
 REPO_ROOT="${BASH_SOURCE%/*}/.."
-N_EXE="$REPO_ROOT/bin/n"
+
+source "$REPO_ROOT/bin/common"
+
 YARN_EXE="$REPO_ROOT/vendor/yarn-v1.22.4/bin/yarn"
 
-"$N_EXE" exec lts "$YARN_EXE" "$@"
+n exec lts "$YARN_EXE" "$@"
index e43640cd06cb7f9d5e87cfa887c667ec4010b41c..28674f0555fa30987ef754f7b7fdbafdae4afa67 100755 (executable)
@@ -3,22 +3,18 @@
 set -e
 
 REPO_ROOT="${BASH_SOURCE%/*}"
-BIN_DIR="$REPO_ROOT/bin"
-NODE_EXE="$BIN_DIR/node"
-YARN_EXE="$BIN_DIR/yarn"
-MAIN_EXE="$REPO_ROOT/lib/main.js"
 
-source "$BIN_DIR/common"
+source "$REPO_ROOT/bin/common"
 
 log_info "Installing TypeScript"
 
-"$YARN_EXE" --frozen-lockfile --no-default-rc --no-progress --silent
+yarn --frozen-lockfile --no-default-rc --no-progress --silent
 
 log_info "Building"
 
 # TODO: make bin/tsc
-"$YARN_EXE" run --silent tsc
+yarn run --silent tsc
 
 log_info "Running main"
 
-"$NODE_EXE" "$MAIN_EXE" "$@"
+node "$REPO_ROOT/lib/main.js" "$@"