Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·130 lines (107 loc) · 3.25 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·130 lines (107 loc) · 3.25 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
set -e
# colours
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NOCOLOUR='\033[0m'
CONFIG_DIR=/etc/gu
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR=${DIR}/..
printf "\n\rSetting up Fronts Tool dependencies... \n\r\n\r"
fileExists() {
test -e "$1"
}
check_yarn_installed() {
if ! [ -x "$(command -v yarn)" ]; then
echo -e "\r\n\r\n${red}yarn not found: please install yarn from https://yarnpkg.com/${plain}\r\n"
echo -e "Yarn is required in the fronts-client directory to ensure developers use consistent JS dependencies"
exit 1
fi
}
set_node_version() {
## Check which Node version manager is available and use it
if command -v mise >/dev/null 2>&1; then
echo "Using mise"
eval "$(mise activate bash)"
elif command -v nvm >/dev/null 2>&1; then
echo "Using nvm"
nvm use
elif command -v fnm >/dev/null 2>&1; then
echo "Using fnm"
fnm use
else
echo -e "${RED}No Node version manager (mise, nvm, fnm) found.${NOCOLOUR}"
exit 1
fi
runningNodeVersion=$(node -v)
requiredNodeVersion=$(cat .nvmrc)
echo "Running ${runningNodeVersion}"
echo "Required ${requiredNodeVersion}"
if [ "$runningNodeVersion" != "$requiredNodeVersion" ]; then
echo -e "${red}Using wrong version of Node. Required ${requiredNodeVersion}. Running ${runningNodeVersion}.${plain}."
exit 1
fi
}
install_v2_deps_and_build() {
cd fronts-client
set_node_version
yarn install
printf "\nCompiling Javascript... \n\r\n\r"
yarn build
cd ..
}
printf "\n\rSetting up Breaking News tool (Fronts Tool V1) dependencies... \n\r\n\r"
install_v1_deps() {
set_node_version
printf "\n\rInstalling NPM modules \n\r\n\r"
npm install
printf "\n\rInstalling JSPM modules \n\r\n\r"
npm run jspm install
}
setup_nginx() {
brew install guardian/devtools/dev-nginx
dev-nginx setup-app nginx/nginx-mapping.yml
}
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
download_config() {
aws s3 cp s3://facia-private/facia-tool.application.secrets.local.conf ${CONFIG_DIR}/facia-tool.application.secrets.conf --profile cmsFronts
aws s3 cp s3://facia-private/facia-tool.local.properties ${CONFIG_DIR}/facia-tool.properties --profile cmsFronts
}
fetch_config(){
if [[ -w ${CONFIG_DIR} ]]; then
download_config
echo -e "${GREEN}Done ${NOCOLOUR}"
else
echo "Cannot write to ${CONFIG_DIR}. It either doesn't exist or is not owned by $(whoami)."
if [[ $1 = "--allow-creation" ]]; then
echo "Creating ${CONFIG_DIR} and making user $(whoami) the owner"
sudo mkdir -p ${CONFIG_DIR}
sudo chown -R $(whoami) ${CONFIG_DIR}
download_config
echo -e "${GREEN}Done ${NOCOLOUR}"
else
echo -e "${RED}Error. Re-run this script with flag --allow-creation ${NOCOLOUR}"
exit 1
fi
fi
}
configure_git() {
echo "Configuring git…"
git config --local blame.ignoreRevsFile .git-blame-ignore-revs
git config --local core.hooksPath scripts/git-hooks
}
main() {
fetch_config "$@"
check_yarn_installed
install_v1_deps
install_v2_deps_and_build
if [ "$USER" = "vscode" ]; then
echo "Running in VS Code dev container, skipping nginx setup"
else
setup_nginx
fi
configure_git
printf "\n\rDone.\n\r\n\r"
}
main "$@"