-
Notifications
You must be signed in to change notification settings - Fork 25
/
staging-build.sh
80 lines (68 loc) · 3.1 KB
/
staging-build.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
#!/usr/bin/env bash
# Clean up previous build artifacts
echo "Cleaning up previous build artifacts ..."
rm -rf openmrs-config-kenyaemr
rm -rf frontend
# Prompt user for KDOD asset generation
read -p "Is this for KDOD asset generation? (y/n): " is_kdod
# Build assets
echo "Building Kenya EMR 3.x assets ..."
CWD=$(pwd)
npx --legacy-peer-deps [email protected] build \
--build-config ./frontend-config/staging/build-config.json \
--target ./frontend \
--page-title "KenyaEMR" \
--support-offline false
# Assemble assets
echo "Assembling assets ..."
npx --legacy-peer-deps [email protected] assemble \
--manifest \
--mode config \
--config ./frontend-config/staging/build-config.json \
--target ./frontend
# Copy required files
echo "Copying required files ..."
cp "${CWD}/assets/kenyaemr-login-logo.png" "${CWD}/frontend"
cp "${CWD}/assets/kenyaemr-primary-logo.svg" "${CWD}/frontend"
cp "${CWD}/assets/favicon.ico" "${CWD}/frontend"
cp "${CWD}/frontend-config/staging/kenyaemr.config.json" "${CWD}/frontend"
cp "${CWD}/frontend-config/staging/openmrs.config.json" "${CWD}/frontend"
# Copy KDOD config or registration config based on user input and update index.html
if [ "$is_kdod" = "y" ] || [ "$is_kdod" = "Y" ]; then
echo "Copying KDOD configuration..."
cp "${CWD}/frontend-config/registration/kdod.config.json" "${CWD}/frontend"
# Update the configUrls in index.html
sed -i.bak 's/configUrls: \[/configUrls: \["${openmrsSpaBase}\/kdod.config.json", /' "${CWD}/frontend/index.html" && rm "${CWD}/frontend/index.html.bak"
else
echo "Copying registration configuration..."
cp "${CWD}/frontend-config/registration/registration.config.json" "${CWD}/frontend"
# Update the configUrls in index.html
sed -i.bak 's/configUrls: \[/configUrls: \["${openmrsSpaBase}\/registration.config.json", /' "${CWD}/frontend/index.html" && rm "${CWD}/frontend/index.html.bak"
fi
# Function to handle the renaming process
rename_dist_folder() {
local pattern=$1
local dist_folder_name=$2
local folder_name=$(find frontend -name "$pattern" -type d | head -n 1 | sed 's|frontend/||')
# Check if the folder_name is not empty
if [ -n "$folder_name" ]; then
# Check if the specific 'dist' directory exists
if [ -d "$dist_folder_name" ]; then
# Rename the specific 'dist' directory to the found folder name
mv "$dist_folder_name" "$folder_name"
echo "The '$dist_folder_name' directory has been renamed to '$folder_name'"
# Now copy the renamed folder back into the 'frontend' directory
cp -r "$folder_name" frontend/
echo "The renamed folder has been copied back into the 'frontend' directory."
mv "$folder_name" "$dist_folder_name"
else
echo "The '$dist_folder_name' directory does not exist in the expected location."
fi
else
echo "No directory matching the pattern '$pattern' was found within the 'frontend' directory."
fi
}
# Handle renaming for openmrs-esm-form-entry-app-*
rename_dist_folder "openmrs-esm-form-entry-app-*" "dist-form-entry"
# Exit with success status
exit 0