Skip to content

Instantly share code, notes, and snippets.

@vaclavbohac
Created August 6, 2010 13:26
Show Gist options
  • Save vaclavbohac/511320 to your computer and use it in GitHub Desktop.
Save vaclavbohac/511320 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Author: Vaclav Bohac <bohac.v@gmail.com>
#
# Run easily Google Closure compiler in your project directory.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Usage:
# you@linux:www$ gglcc.sh -i inputfile.js -o outputfile.js -e externsfile.js
GGLCC_DIR="$HOME/google-closure-compiler/"
GGLCC_NAME="compiler.jar"
FILE_IN=""
FILE_OUT=""
EXTERNS=""
FORMATING_FLAG=""
if [ ! -f "$GGLCC_DIR$GGLCC_NAME" ]; then
echo "Path to Google Closure Compiler is wrong. Please, fix it."
exit 1
fi
while getopts :i:o:e:t optname
do
case "$optname" in
"i")
if [ ! -f "$OPTARG" ]; then
echo "Input file '$OPTARG' does not exist."
exit 1
fi
FILE_IN=$OPTARG
;;
"o")
FILE_OUT=$OPTARG
;;
"e")
if [ ! -f "$OPTARG" ]; then
echo "Externs file '$OPTARG' does not exist."
exit 1
fi
EXTERNS=$OPTARG
;;
"t")
FORMATING_FLAG="--formatting PRETTY_PRINT"
;;
"?")
echo "Unknown options '$OPTARG'"
;;
":")
echo "No argument value for '$OPTARG'"
;;
*)
echo "Unknown error while processing arguments.";
;;
esac
done
java -jar "$GGLCC_DIR$GGLCC_NAME" --compilation_level ADVANCED_OPTIMIZATIONS \
--js "$FILE_IN" --js_output_file "$FILE_OUT" \
--externs "$EXTERNS" $FORMATING_FLAG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment