This repository has been archived by the owner on Jul 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlinkConfig.sh
executable file
·81 lines (75 loc) · 2.51 KB
/
linkConfig.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
#!/bin/bash
# Usage:
# Run portal with the app-template
# ./run.sh [portal-folder-name]
#
# Verify directory was specified
if [[ -z $1 ]]; then
echo Usage: ./run.sh [portal-folder-name] [optional-reset-flag]
exit 1
fi
# If specified, verify second argument was set correctly
if [ ! -z $2 ] && [ "$2" != "-r" ]; then
echo Usage: ./run.sh [portal-folder-name] [-r to reset last link]
exit 1
fi
# remove ending slash if directory given had a slash
folderNoSlash=${1%/}
CONFIG_FOLDER=src/config
ACTIVE_CONFIGURATION=src/configurations/$folderNoSlash
# we want to always make sure that the linking is undone after this script so we capture
# ctrl-c. This has removed various bugs when developing locally.
# See here - https://unix.stackexchange.com/a/407249
trap undoSymlink SIGINT
function undoSymlink {
# remove symlink
rm -rf $ACTIVE_CONFIGURATION/
# copy back contents
cp -r $CONFIG_FOLDER/ $ACTIVE_CONFIGURATION/
# remove config folder contents
rm -rf $CONFIG_FOLDER/
printf '\n'
exit 0
}
# Check that directory exists
if [ ! -d "$ACTIVE_CONFIGURATION" ]; then
echo Directory $ACTIVE_CONFIGURATION does not exist.
echo Available options are -
ls ./src/configurations
exit 1
fi
# Check if there's a symlink in the directory thats trying to be worked on
# This indicates there was some sort of error the last time this script was
# being run.
if [ -h "$ACTIVE_CONFIGURATION/routesConfig.ts" ]; then
if [ ! -z $2 ]; then
echo 'Removing previous symlink since -r was provided'
undoSymlink
else
echo "
Something went wrong: Detected symlink in $ACTIVE_CONFIGURATION
If you ran ./linkConfig $folderNoSlash last rerun this script like so -
$ ./linkConfig $folderNoSlash -r
Then fix the error that caused yarn start to fail (most likely need to clean install node_modules).
Otherwise to reset the configuration run
$ git checkout $ACTIVE_CONFIGURATION
"
exit 1
fi
fi
# React applications can’t resolve symlinks, so instead of symlinking the
# configuration to the react app, we copy over the configuration and symlink
# the contents back to the configuration
# clear out config
rm -rf ./$CONFIG_FOLDER/*
# copy over the contents
cp -r ./$ACTIVE_CONFIGURATION/ ./$CONFIG_FOLDER/
rm -rf ./$ACTIVE_CONFIGURATION/*
# symlink current configuration to the portal
cd ./$ACTIVE_CONFIGURATION
ln -s ../../config/* .
cd ../../../
# start the project
# Fixes node binding error when switching between packages and forgetting to run this command...
npm rebuild node-sass
yarn && yarn start