-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.sh
executable file
·55 lines (47 loc) · 1.24 KB
/
publish.sh
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
#!/usr/bin/env bash
function showUsage() {
read -r -d '' usage <<-EOF
Usage: publish OPTIONS
Publish this node package to the configured environment <.npmrc>.
Options:
-f, --file=FILE read environmental variables for <.npmrc> from FILE
EOF
echo "$usage"
}
function showLocalNpmrcVars() {
grep -oP '(?<=\${).*?(?=})' ./npm/.npmrc |
sed s/^/'$'/ |
xargs -L 1 -I {} echo "echo '\{}'=`echo {}`" |
xargs -L 1 -I {} sh -c "{}"
}
function exportLocalNpmrcVars() {
set -a
source $1
set +a
}
function doPublishPackage() {
echo "> following values are applied for <.npmrc>"
showLocalNpmrcVars
npm config set registry $REGISTRY_URL
echo -e "\ncheck npm configuration entries:"
npm config list
npm publish
}
if [ -z "$1" ]; then
echo -e "ERROR: no option supplied!\n"
showUsage
exit 1
elif [ "$1" == "-f" ] || [ "$1" == "--file" ]; then
if [ -z "$2" ]; then
echo -e "ERROR: no environment FILE supplied!\n"
showUsage
exit 1
fi
echo -e "environmental variables in file <$2> are exported\n"
exportLocalNpmrcVars "$2"
doPublishPackage
else
echo -e "ERROR: invalid args\n"
showUsage
exit 1
fi