-
Notifications
You must be signed in to change notification settings - Fork 1
/
fontawesome-npmrc.sh
executable file
·92 lines (85 loc) · 2.13 KB
/
fontawesome-npmrc.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
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
#!/bin/bash
FORCE=false
CI=false
for arg in "$@"; do
if [ "$arg" == "--force" ]; then
FORCE=true
fi
if [ "$arg" == "--ci" ]; then
CI=true
fi
done
create_npmrc() {
if [ ! -f .npmrc ]; then
touch .npmrc
fi
if grep -q "@fortawesome:registry" .npmrc && [ "$FORCE" = false ]; then
echo "FONTAWESOME_KEY already exists in .npmrc";
return 0;
else
echo "@fortawesome:registry=https://npm.fontawesome.com/
@awesome.me:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=$FONTAWESOME_KEY" > .npmrc
echo ".npmrc created";
return 0;
fi
}
update_yarnrc() {
if [ ! -f .yarnrc.yml ]; then
YARN_VERSION=$(yarn --version 2>/dev/null || echo "${DEFAULT_YARN_VERSION}")
cat <<EOL >.yarnrc.yml
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.5.3.cjs
npmScopes:
fortawesome:
npmAlwaysAuth: true
npmRegistryServer: "https://npm.fontawesome.com/"
npmAuthToken: "${FONTAWESOME_KEY}"
awesome.me:
npmAlwaysAuth: true
npmRegistryServer: "https://npm.fontawesome.com/"
npmAuthToken: "${FONTAWESOME_KEY}"
EOL
echo ".yarnrc.yml created";
return 0;
fi
if grep -q "npmAuthToken:" .yarnrc.yml && [ "$FORCE" = false ]; then
echo "FONTAWESOME_KEY already exists in .yarnrc.yml";
return 0;
else
if grep -q "npmAuthToken:" .yarnrc.yml; then
sed -i "s/npmAuthToken: .*/npmAuthToken: \"${FONTAWESOME_KEY}\"/" .yarnrc.yml
echo ".yarnrc.yml updated with new token";
else
cat <<EOL >>.yarnrc.yml
npmScopes:
fortawesome:
npmAlwaysAuth: true
npmRegistryServer: "https://npm.fontawesome.com/"
npmAuthToken: "${FONTAWESOME_KEY}"
awesome.me:
npmAlwaysAuth: true
npmRegistryServer: "https://npm.fontawesome.com/"
npmAuthToken: "${FONTAWESOME_KEY}"
EOL
echo ".yarnrc.yml updated";
fi
return 0;
fi
}
if [ -z "${FONTAWESOME_KEY}" ]; then
echo "FONTAWESOME_KEY not set";
exit 1;
fi
create_npmrc
CREATE_NPMRC=$?
update_yarnrc
UPDATE_YARNRC=$?
if [ $CREATE_NPMRC -eq 0 -a $UPDATE_YARNRC -eq 0 ]; then
exit 0;
fi
if [ "$CI" = true ]; then
echo "CI mode enabled, exiting without error";
exit 0;
fi
exit 1;