build.sh 1.1 KB
Newer Older
1 2 3 4
#!/bin/bash

set -e

5 6 7 8
if [ -f "$HOME/.cargo/env" ]; then
    source $HOME/.cargo/env
fi

9
WORKING_PATH=`pwd`
10 11
SERVER_DIR="dist"
SERVER_DIR_PATH="$WORKING_PATH/$SERVER_DIR"
12 13
SERVERLESS_DIR="serverless"
SERVERLESS_DIR_PATH="$WORKING_PATH/$SERVERLESS_DIR"
14 15
OUTPUT="output"
OUTPUT_PATH="$WORKING_PATH/$OUTPUT"
16

17 18 19 20
build_server() {
    # generate dist
    rm -rf $SERVER_DIR_PATH
    mkdir -p $SERVER_DIR_PATH
21

22 23
    # next build
    yarn build:next
24

25 26
    # server build
    yarn build:server
27

28 29 30 31 32
    # move static files
    cp next.config.js $SERVER_DIR_PATH
    cp package.json $SERVER_DIR_PATH
    cp -r public $SERVER_DIR_PATH
}
33

34 35
build_serverless() {
    build_server
36

37 38 39
    # generate dist
    rm -rf $SERVERLESS_DIR_PATH
    mkdir -p $SERVERLESS_DIR_PATH
40

41 42 43
    # next export
    yarn export
}
44

45 46 47 48 49 50 51
# generate output
rm -rf $OUTPUT_PATH
mkdir -p $OUTPUT_PATH

# package serverless files
PUBLIC_PATH="/app" API_URL="/api" build_serverless
(cd $SERVERLESS_DIR_PATH && tar zcf $OUTPUT_PATH/serverless.tar.gz .)
52

53 54 55
# package server files
PUBLIC_PATH="" API_URL="/api" build_server
(cd $SERVER_DIR_PATH && tar zcf $OUTPUT_PATH/server.tar.gz .)