aboutsummaryrefslogtreecommitdiffstats
path: root/build.sh
blob: 28c48fb64ca6d715d7d24afcf98038d782538843 (plain)
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
#!/usr/bin/env bash

# Exit with error when any error occurs
set -e

function print_help {
    echo "This is a build script for FMark"
    echo ""
    echo "USAGE:"
    echo "  ./build.sh [OPTIONS]"
    echo ""
    echo "OPTIONS:"
    echo "  -b/--build    Build a specific project, can be set to"
    echo "                fsharp, js, all, testall"
    echo "  -h/--help     Print this help menu."
}

POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
    -b|--build)
    BUILD="$2"
    shift # past argument
    shift # past value
    ;;
    -h|--help)
    print_help
    exit 0
    ;;
    *)
    print_help
    exit 1
    ;;
esac
done

if [[ -z $BUILD ]]; then
    BUILD=all
fi

if [[ $BUILD != "fsharp" ]] && [[ $BUILD != "js" ]] && [[ $BUILD != "all" ]] && [[ $BUILD != "testall" ]]; then
    print_help
    exit 1
fi

echo "build set to: $BUILD"
echo ""

# get the current directory of the script, which is at the base of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [[ -z $TRAVIS_BUILD_DIR ]]; then
    BASE_DIR=$DIR
else
    echo "Running on travis-ci"
    BASE_DIR=$TRAVIS_BUILD_DIR
fi

function cd_run_module() {
    echo "########## Running $1 module tests ###########"
    cd $BASE_DIR/FMark/src/Common/$1
    dotnet build
    dotnet run --no-build -- --sequenced
    if [[ "$?" != "0" ]]; then
        exit 1
    fi
}

if [[ $BUILD = "testall" ]]; then
    modules=("Lexer" "TOCite" "Markalc" "Parser" "HTMLGen" "MarkdownGen" "Logger")
    for i in "${modules[@]}"; do
        cd_run_module $i
    done
fi

if [[ $BUILD = "testall" ]] || [[ $BUILD = "all" ]] || [[ $BUILD = "fsharp" ]]; then
    echo "Running F# tests"
    cd $BASE_DIR/FMark/src/FMarkCLI
    dotnet build
    dotnet run --no-build -- --test true -l info
    if [[ "$?" != "0" ]]; then
        exit 1
    fi
fi

if [[ $BUILD = "all" ]] || [[ $BUILD = "js" ]]; then
    echo "Running javascript build"
    cd $BASE_DIR/FMark
    yarn install
    cd $BASE_DIR/FMark/src/FMarkFable
    dotnet restore
    dotnet fable yarn-dev
    if [[ "$?" != "0" ]]; then
        exit 1
    fi
fi