Artifact Content

Not logged in

Artifact aed342d2f51c138815e01fda17123fd81ab3cfc6:


#!/usr/bin/env bash

# 
# build.sh
# "Build" script for Arend. This basically just compiles the grammar and 
# (optionally) runs all the tests via Node (so you don't have to open the
# test page to view them).
#

# Copy this script's output to the build results log file
exec > >(tee "tests/build-results.txt")
exec 2>&1

# This complicated setup is the "variable" to which the Peg.js parser object
# is assigned. We need this whole mess in order to detect whether the module
# is being loaded in Node or the browser, and place the parser object in the
# appropriate location (either module.exports, or window.lib[...]).
MODULE='if(typeof window !== "undefined") {
    window.lib["syntax.peg.js"] = {};
    base = window.lib;
    loc = "syntax.peg.js";
}
else {
    base = module;
    loc = "exports";
}
base[loc]'

echo "---- Building grammar ----"

# Compile grammar
./node_modules/pegjs/bin/pegjs \
    -e "$MODULE" \
    --cache \
    --allowed-start-rules start,term,definition src/syntax.peg src/syntax.peg.js 

echo "--------------------------"

# Run tests, inside istanbul so we get code coverage info.
if [ "$1" = "test" ]; then

    echo "---- Test results ----"

    for test in tests/*.js; do
        # node node_modules/istanbul/lib/cli.js tests/$file
        node $test
    done

    echo "----------------------"
fi

# List any pending TODOs
echo "---- TODO Comments ----"

ack "//.+TODO" src/* lib/*.js plsrc/*.pl

echo "-----------------------"

echo "---- Extra files ----"
fossil extras --ignore "lib/katex/*","lib/MathJax/*","node_modules/*"
echo "-----------------------"