Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 122 lines (95 sloc) 3.363 kB
#!/usr/bin/env bash
###
# Copyright © 2011, 2012 MLstate
#
# This file is part of Opa.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
###
CC_DIR="$OPALANG/tools/jschecker"
CC="$CC_DIR/compiler.jar"
CC_OPT='--formatting PRETTY_PRINT'
COMPILATION_LEVEL='WHITESPACE_ONLY'
SIMPLE_OPTIMIZATIONS='SIMPLE_OPTIMIZATIONS'
ADVANCED_OPTIMIZATIONS='ADVANCED_OPTIMIZATIONS'
FILES=''
EXTERNALS="$CC_DIR/externs.js"
WITH_EXTERNALS=false
TARGET='/dev/stdout'
help() {
cat <<EOF
$0: normalize and beautify js files.
This script is meant to be runned from anywhere on js files.
It is just a wrapper to the Google Closure Compiler:
Google Closure Compiler
http://code.google.com/closure/compiler/
Use:
$0 [options] js-files*
Options:
--help|-help|help print this help message
-e include standard externals distributed with the checker
-c turn on simple optimizations
-cc turn on advanced optimizations
-o * produce resulting js in a file rather than stdout
-- * give all remaining options to the Google Closure Compiler
EOF
}
if [ "$#" -lt 1 ]; then
help
exit 0
fi
while [ "$#" -gt 0 ]; do
case "$1" in
-h|--help|-help|help)
help
exit 0
;;
-e)
WITH_EXTERNALS=true
;;
-c)
COMPILATION_LEVEL=$SIMPLE_OPTIMIZATIONS
;;
-cc)
COMPILATION_LEVEL=$ADVANCED_OPTIMIZATIONS
;;
-o)
if [ -z "$2" ]; then echo "Error: option $1 requires an argument"; exit 1; fi
shift
TARGET="$1"
;;
--)
shift
CC_OPT="$CC_OPT $@"
break
;;
*)
FILES="$FILES $1"
;;
esac
shift
done
CC_OPT="$CC_OPT --compilation_level $COMPILATION_LEVEL --js_output_file $TARGET"
if [ "$WITH_EXTERNALS" = true ] ; then
CC_OPT="$CC_OPT --externs $EXTERNALS"
fi
if [ ! -f "$CC" ] ; then
cat <<EOF
Cannot find the Closure Compiler.
OPALANG is set to : '$OPALANG'
searched at:
OPALANG/tools/jschecker/compiler.jar
EOF
exit 1
fi
JS_FILES=''
for file in $FILES ; do
JS_FILES="$JS_FILES --js $file"
done
command="java -jar $CC $CC_OPT $JS_FILES"
echo "$command"
$command
Jump to Line
Something went wrong with that request. Please try again.