UNPKG

6.7 kBapplication/x-shView Raw
1#!/usr/bin/env bash
2
3# NOTE TO READER - if you wish to modify this file please move it outside the ~/.suman dir, because suman
4# may periodically update this file's contents which would overwrite your changes
5# if you do so, just change your .bashrc or .zshrc, or whatever, to source your file instead of this one
6
7# we use this to cache this value in subshells
8# we should not cache, because switching between nvm versions
9
10# do not use `set -e;` since this will cause user's terminals to close
11# if they source this file
12
13export suman_global_npm_modules_path="$(npm root -g)";
14
15
16function handle_global_suman {
17
18 WHICH_SUMAN=$(which suman);
19 GLOBAL_MODULES="$(npm root -g)";
20 NEW_NODE_PATH="${NODE_PATH}":"$HOME/.suman/global/node_modules":"${GLOBAL_MODULES}"
21
22 NEW_PATH="${PATH}":"$HOME/.suman/global/node_modules/.bin";
23
24 if [ -z "${WHICH_SUMAN}" ]; then
25 echo " [suman] => No global suman installation could be found with '\$ which suman', exiting..."
26 return 1;
27 else
28
29 DIRN="$(dirname "$WHICH_SUMAN")";
30 RL="$(readlink "$WHICH_SUMAN")";
31 EXECDIR="$(dirname $(dirname "$RL"))";
32 MYPATH="$DIRN/$EXECDIR";
33 X="$(cd $(dirname ${MYPATH}) && pwd)/$(basename ${MYPATH})"
34
35 # $1 is the node exec args (inspect/debug etc), $2 is the original user args
36 # we work with the first argument passed to this function
37 local ref1="$1[@]";
38 shift
39 NODE_PATH="${NEW_NODE_PATH}" PATH="${NEW_PATH}" node "${!ref1}" "${X}/cli.js" "$@";
40 fi
41}
42
43
44function suman {
45
46 if test ${#} -eq 0; then
47 echo " [suman] using suman-shell instead of suman executable.";
48 suman-shell "$@"; # note we should have no arguments so passing "$@" to suman-shell should be pointless
49 else
50
51 suman_inspect="no";
52
53 for item in $@; do
54 if [[ "--inspect" == "$item" || "--inspect-brk" == "$item" ]]; then
55 suman_inspect="yes";
56 fi
57 done
58
59 if [[ "${suman_inspect}" == "yes" ]]; then
60 "$(dirname "$0")/suman-inspect" "$@";
61 exit $?;
62 fi
63
64 echo " [suman] => Using 'suman' alias in suman-clis.sh...";
65 LOCAL_SUMAN="$(node "$HOME/.suman/find-local-suman-executable.js")";
66 NEW_NODE_PATH="${NODE_PATH}":"$HOME/.suman/global/node_modules";
67 NEW_PATH="${PATH}":"$HOME/.suman/global/node_modules/.bin";
68
69 if [[ "${SUMAN_FORCE_GLOBAL}" == "yes" || -z "$LOCAL_SUMAN" ]]; then
70 echo " [suman] => No local Suman executable could be found, given the present working directory => $PWD";
71 echo " [suman] => Warning...attempting to run a globally installed version of Suman...";
72 local -a node_exec_args=( );
73 handle_global_suman node_exec_args "$@";
74 else
75 NODE_PATH="${NEW_NODE_PATH}" PATH="${NEW_PATH}" node "$LOCAL_SUMAN" "$@";
76 fi
77 fi
78}
79
80
81function suman-shell {
82
83 echo " [suman] => Using 'suman' alias in suman-clis.sh..."
84
85 if [[ "${SUMAN_WATCH_TEST_RUN}" == "yes" ]]; then
86 echo " [suman] Cannot run suman-shell from a watch process.";
87 echo " [suman] Cannot run suman-shell from a watch process." >&2 ;
88 exit 1;
89 fi
90
91 LOCAL_SUMAN="$(node "$HOME/.suman/find-local-suman-executable.js")";
92 NEW_NODE_PATH="${NODE_PATH}":"$HOME/.suman/global/node_modules"
93 NEW_PATH="${PATH}":"$HOME/.suman/global/node_modules/.bin";
94
95 local -a args=("$@")
96 args+=("--suman-shell")
97
98 if [[ "${SUMAN_FORCE_GLOBAL}" == "yes" || -z "$LOCAL_SUMAN" ]]; then
99 echo " [suman] => No local Suman executable could be found, given the present working directory => $PWD"
100 echo " [suman] => Warning...attempting to run a globally installed version of Suman..."
101 local -a node_exec_args=( )
102 handle_global_suman node_exec_args "${args[@]}"
103 else
104 NODE_PATH="${NEW_NODE_PATH}" PATH="${NEW_PATH}" node "$LOCAL_SUMAN" "${args[@]}";
105 fi
106}
107
108
109function suman-inspect {
110
111 echo " [suman] => Using 'suman-inspect' alias in suman-clis.sh...";
112 LOCAL_SUMAN="$(node "$HOME/.suman/find-local-suman-executable.js")";
113 NEW_NODE_PATH="${NODE_PATH}":"$HOME/.suman/global/node_modules";
114 NEW_PATH="${PATH}":"$HOME/.suman/global/node_modules/.bin";
115
116 if [[ "${SUMAN_FORCE_GLOBAL}" == "yes" || -z "$LOCAL_SUMAN" ]]; then
117 echo " [suman] => No local Suman executable could be found, given the present working directory => $PWD"
118 echo " [suman] You can use '$ which suman-debug' to find a globally installed version."
119 echo " [suman] => Warning...attempting to run a globally installed version of Suman..."
120 local -a node_exec_args=( --inspect --debug-brk )
121 handle_global_suman node_exec_args "$@"
122 else
123 echo " [suman] running node against local suman"
124 NODE_PATH="${NEW_NODE_PATH}" PATH="${NEW_PATH}" node --inspect --debug-brk "$LOCAL_SUMAN" "$@";
125 fi
126}
127
128function suman-debug {
129
130 echo " [suman] => Using 'suman-debug' alias in suman-clis.sh..."
131 LOCAL_SUMAN="$(node "$HOME/.suman/find-local-suman-executable.js")";
132 NEW_NODE_PATH="${NODE_PATH}":"$HOME/.suman/global/node_modules";
133 NEW_PATH="${PATH}":"$HOME/.suman/global/node_modules/.bin";
134
135 if [[ "${SUMAN_FORCE_GLOBAL}" == "yes" || -z "$LOCAL_SUMAN" ]]; then
136 echo " [suman] No local Suman executable could be found, given the current directory => $PWD"
137 echo " [suman] You can use '$ which suman-debug' to find a globally installed version."
138 echo " [suman] => Warning...attempting to run a globally installed version of Suman..."
139 local -a node_exec_args=( debug )
140 handle_global_suman node_exec_args "$@"
141 else
142 NODE_PATH="${NEW_NODE_PATH}" PATH="${NEW_PATH}" node debug "$LOCAL_SUMAN" "$@";
143 fi
144}
145
146function suman--debug {
147
148 echo " [suman] => Using 'suman--debug' alias in suman-clis.sh..."
149 LOCAL_SUMAN="$(node "$HOME/.suman/find-local-suman-executable.js")";
150 NEW_NODE_PATH="${NODE_PATH}":"$HOME/.suman/global/node_modules";
151 NEW_PATH="${PATH}":"$HOME/.suman/global/node_modules/.bin";
152
153 if [[ "${SUMAN_FORCE_GLOBAL}" == "yes" || -z "$LOCAL_SUMAN" ]]; then
154 echo " [suman] No local Suman executable could be found, given the current directory => $PWD"
155 echo " [suman] Use '$ which suman--debug' to find a globally installed version."
156 echo " [suman] => Warning...attempting to run a globally installed version of Suman..."
157 local -a node_exec_args=( --debug-brk=5858 --debug=5858 )
158 handle_global_suman node_exec_args "$@"
159 else
160 NODE_PATH="${NEW_NODE_PATH}" PATH="${NEW_PATH}" node --debug-brk=5858 --debug=5858 "$LOCAL_SUMAN" "$@";
161 fi
162}