-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathactivate_js_env.fish
46 lines (44 loc) · 1.95 KB
/
activate_js_env.fish
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
function load_js_env -a path
set abspath (greadlink -f -- "$path")
if begin; test -n "$path"; and greadlink -f -- "$PWD" | grep -q "^$abspath"; end
debug "Loading '$path' js env..." $green
set -gx ACTIVE_JS_ENV "$abspath"
and set -gx ACTIVE_JS_PACKAGE (node -pe "require('$path/package.json').name")
and set -gx ACTIVE_NODE_BIN (which node)
and set -gx ACTIVE_NODE_VERSION (node --version | perl -pe 's/^v(\d+\.\d+)(\..+)?/$1/gm')
and set -gx ACTIVE_NPM_BIN (which npm)
and set -gx ACTIVE_NPM_VERSION (jq -r '.version' "$ACTIVE_JS_ENV/package.json")
and set -gx ACTIVE_YARN_BIN (which yarn)
and set -gx ACTIVE_YARN_VERSION (eval "$ACTIVE_YARN_BIN --version")
return $status
else
debug "Deactivating previous ACTIVE_JS_ENV." $yellow
set -gx ACTIVE_JS_ENV ""
set -gx ACTIVE_JS_PACKAGE ""
set -gx ACTIVE_NODE_BIN ""
set -gx ACTIVE_NODE_VERSION ""
set -gx ACTIVE_NPM_BIN ""
set -gx ACTIVE_NPM_VERSION ""
set -gx ACTIVE_YARN_BIN ""
set -gx ACTIVE_YARN_VERSION ""
return 0
end
end
function print_js_env
debug "=============================================" $white
debug "ACTIVE_JS_ENV=$ACTIVE_JS_ENV" $white
debug "ACTIVE_JS_PACKAGE=$ACTIVE_JS_PACKAGE" $white
debug "ACTIVE_NODE_BIN=$ACTIVE_NODE_BIN" $white
debug "ACTIVE_NODE_VERSION=$ACTIVE_NODE_VERSION" $white
debug "ACTIVE_NPM_BIN=$ACTIVE_NPM_BIN" $white
debug "ACTIVE_NPM_VERSION=$ACTIVE_NPM_VERSION" $white
debug "ACTIVE_YARN_BIN=$ACTIVE_YARN_BIN" $white
debug "ACTIVE_YARN_VERSION=$ACTIVE_YARN_VERSION" $white
debug "============================================" $white
end
function activate_js_env -a path --description 'Load a python virtual environment'
print_js_env
test -n "$path"; or set path (findabove "package.json" "$PWD" "$MAXHOPS" | perl -pe 's/\/package.json//gm')
load_js_env "$path"
print_js_env
end