#!/bin/bash # # buildjs.sh # # Copyright (c) 2013-2015 Simon Fraser University Library # Copyright (c) 2010-2015 John Willinsky # Distributed under the GNU GPL v2. For full terms see the file docs/COPYING. # # Script to check and minimize JavaScript for distribution. # # Requirements: # - Requires Python/Closure Linter and Java/Closure Compiler, see # . Please download the compiler.jar # from there. Expects Closure's compiler.jar file in '~/bin'. If you want to put it # into a different directory then please change the TOOL_PATH variable below. # Please see the Closure Linter documentation for installation instructions # of that tool. # # - Requires jslint4java, see . Expects the # jslint4java.jar (must be renamed!) in the same path as the Closure compiler, # i.e. in TOOL_PATH as configured below. # # - This tool expects to be run from the application's main directory. # # Usage: lib/pkp/tools/buildjs.sh [-n] # ...where -n can be optionally specified to prevent caching. # ### OS specific configuration ### # Define a tab to be used inside of sed commands (sed on OSX does not recognize \t) TAB=$'\t' # Determine what flag to use for extended regular expressions if [ `uname` == 'Darwin' ]; then EXTENDED_REGEX_FLAG='E' else EXTENDED_REGEX_FLAG='r' fi ### Configuration ### TOOL_PATH=~/bin JS_OUTPUT='js/pkp.min.js' CLOSURE_EXTERNS=' --externs lib/pkp/tools/closure-externs.js --externs lib/pkp/tools/closure-externs-check-only.js --externs lib/pkp/tools/jquery-externs.js' ### Command Line Options ### OPTIND=1 DO_CACHE=1 while getopts "n" opt; do case "$opt" in n) DO_CACHE=0 # No caching ;; esac done shift $((OPTIND-1)) ### Start Processing ### echo >&2 echo "Starting PKP JavaScript builder." >&2 echo "Copyright (c) 2010-2015 John Willinsky" >&2 ### Checking Requirements ### MISSING_REQUIREMENT='' if [ -z `which gjslint` ]; then echo >&2 echo "Google Closure Linter not found in PATH. Please go" >&2 echo "to " >&2 echo "and make sure that you correctly install the tool before you run" >&2 echo "buildjs.sh." >&2 MISSING_REQUIREMENT='gjslint' fi if [ ! -e "$TOOL_PATH/jslint4java.jar" ]; then echo >&2 echo "JSLint4Java must be installed in the '$TOOL_PATH'" >&2 echo "directory. Please download the tool from" >&2 echo "," >&2 echo "rename it to jslint4java.jar and try again." >&2 MISSING_REQUIREMENT='jslint4java' fi if [ ! -e "$TOOL_PATH/compiler.jar" ]; then echo >&2 echo "Google Closure Compiler not found in '$TOOL_PATH'" >&2 echo "Please go to " >&2 echo "and download the tool. Then try again." >&2 MISSING_REQUIREMENT='closure' fi if [ -n "$MISSING_REQUIREMENT" ]; then echo >&2 echo "Exiting!" >&2 exit 1 fi echo >&2 # A list with all files to be compiled and minified. Expects # a complete list of script files in minifiedScripts.tpl. COMPILE_FILES=$(sed -n -$EXTENDED_REGEX_FLAG '/