-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbranchout-yarn
executable file
·106 lines (83 loc) · 3.2 KB
/
branchout-yarn
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
test -n "${DEBUG}" && set -x
set -e
function runYarn() {
if test -f "${PROJECTION_DIRECTORY}/.branchout/cacerts"; then
if [ "$(command -v cygpath)" ]; then
NODE_EXTRA_CA_CERTS="$(cygpath --windows "${PROJECTION_DIRECTORY}/.branchout/cacerts")"
else
NODE_EXTRA_CA_CERTS="${PROJECTION_DIRECTORY}/.branchout/cacerts"
fi
echo "NODE_EXTRA_CA_CERTS: ${NODE_EXTRA_CA_CERTS}"
export NODE_EXTRA_CA_CERTS
fi
HOME=${BRANCHOUT_STATE}/node
YARN_CACHE_FOLDER=${BRANCHOUT_STATE}/node/cache yarn --use-yarnrc "${BRANCHOUT_STATE}/node/yarnrc" "${@}"
}
function yarnSettings() {
ensureValue "your npm registry" "NPM_REGISTRY"
if [[ ${BRANCHOUT_NPM_REGISTRY} =~ ^http:// ]]; then
export BRANCHOUT_NPM_REGISTRY="https:${BRANCHOUT_NPM_REGISTRY#*:}"
setValue "NPM_REGISTRY" "https${BRANCHOUT_NPM_REGISTRY}"
fi
ensureConfigValue "npm registry username" "NPM_USER"
readSecret "npm registry secret" "NPM_PASS"
ensureConfigValue "npm registry email (git commit author)" "GIT_EMAIL"
if test ! -d "${BRANCHOUT_STATE}/node/"; then
echo "create the branchout directory for node ${BRANCHOUT_STATE}/node/"
mkdir -p "${BRANCHOUT_STATE}/node/"
fi
echo "writing yarn config to ${BRANCHOUT_STATE}/node/yarnrc"
if test -f "${PROJECTION_DIRECTORY}/branchout-templates/yarnrc"; then
echo "using yarnrc template ${PROJECTION_DIRECTORY}/branchout-templates/yarnrc"
echo <(cat "${PROJECTION_DIRECTORY}/branchout-templates/yarnrc") > "${BRANCHOUT_STATE}/node/yarnrc"
else
echo "registry \"${BRANCHOUT_NPM_REGISTRY}\"
user \"${BRANCHOUT_CONFIG_NPM_USER}\"
email \"${BRANCHOUT_CONFIG_GIT_EMAIL}\"
always-auth true
disable-self-update-check true
" > "${BRANCHOUT_STATE}/node/yarnrc"
fi
echo "writing npm config to ${BRANCHOUT_STATE}/node/.npmrc"
BASE_64_AUTH=$(echo -n "${BRANCHOUT_CONFIG_NPM_USER}:${NPM_PASS}" | base64)
if test -f "${PROJECTION_DIRECTORY}/branchout-templates/.npmrc"; then
echo "using npmrc template ${PROJECTION_DIRECTORY}/branchout-templates/npmrc"
echo <(cat "${PROJECTION_DIRECTORY}/branchout-templates/.npmrc") > "${BRANCHOUT_STATE}/node/.npmrc"
else
echo "_auth=${BASE_64_AUTH}
always-auth=true" > "${BRANCHOUT_STATE}/node/.npmrc"
fi
}
function usage() {
echo "branchout-yarn settings|show|install|<package.json command>
settings
Generate .npmrc and yarnc for private repository access
install
Install the node modules declared in the package.json
<package.json scripts>
Run a script defined in the package.json e.g. clean, test, serve
"
exit 1
}
function main() {
test $# -gt 0 || usage
BRANCHOUT_PATH="$(dirname "$0")"
# shellcheck source=branchout-configuration
. "${BRANCHOUT_PATH}/branchout-configuration"
# shellcheck source=branchout-environment
. "${BRANCHOUT_PATH}/branchout-environment"
case "${1}" in
settings)
yarnSettings "${*}"
;;
show)
grep -v '^auth ' "${BRANCHOUT_STATE}/node/yarnrc"
;;
*)
test -f "${BRANCHOUT_STATE}/node/.npmrc" || yarnSettings
test -f "${BRANCHOUT_STATE}/node/yarnrc" || yarnSettings
runYarn "${@}"
esac
}
main "${@}"