-
Notifications
You must be signed in to change notification settings - Fork 11
/
start.sh
executable file
·42 lines (37 loc) · 1.62 KB
/
start.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
#!/bin/sh
# * Set the default package manager to use if cannot be guessed from lock files
echo "defaultAgent=$PACKAGE_MANAGER" > ~/.nirc
# * Look for the package.json file.
# * If not found, create it in the "functions" directory.
if [ -f "./functions/package.json" ]; then
# * ./functions/package.json exists
FUNCTIONS_WORKING_DIR=./functions
FUNCTIONS_RELATIVE_PATH=.
else
# * ./functions/package.json DOES NOT exist
if [ -f "./package.json" ]; then
# * ./package.json exists
FUNCTIONS_WORKING_DIR=.
FUNCTIONS_RELATIVE_PATH=./functions
else
# * ./package.json DOES NOT exist"
mkdir -p functions
cd functions
npm init -y 1> /dev/null
cd ..
FUNCTIONS_WORKING_DIR=./functions
FUNCTIONS_RELATIVE_PATH=.
fi
fi
# if neither package-lock.json nor yarn.lock exists nor pnpm-lock.yaml, error
if [ ! -f "$FUNCTIONS_WORKING_DIR/package-lock.json" ] && [ ! -f "$FUNCTIONS_WORKING_DIR/yarn.lock" ] && [ ! -f "$FUNCTIONS_WORKING_DIR/pnpm-lock.yaml" ]; then
echo "No lock file found. Please commit your lock file for npm, yarn, or pnpm"
exit 1
fi
# * Create a default tsconfig.json file in the functions' working directory.
cp -n $SERVER_PATH/tsconfig.json $FUNCTIONS_WORKING_DIR/tsconfig.json
# * Start nodemon that listens to package.json and lock files and run npm/pnpm/yarn install,
# * Then run another nodemon that listens to the functions directory and run the server
FUNCTIONS_WORKING_DIR=$FUNCTIONS_WORKING_DIR \
FUNCTIONS_RELATIVE_PATH=$FUNCTIONS_RELATIVE_PATH \
nodemon --config $SERVER_PATH/nodemon.json $FUNCTIONS_WORKING_DIR/package.json