Skip to content

Instantly share code, notes, and snippets.

@ngs
Created November 27, 2010 20:59
Show Gist options
  • Select an option

  • Save ngs/718263 to your computer and use it in GitHub Desktop.

Select an option

Save ngs/718263 to your computer and use it in GitHub Desktop.
Compile JavaScript files with Closure Compiler

structure

  • compile
  • lib
    • jquery.js
  • src
    • code-prefix.js
    • intro.js
    • module1.js
    • module2.js
    • ...
    • outro.js
    • code-suffix.js

compile

$ /path/to/my/jsproject/compile
#!/bin/sh
BASEDIR=${0%/*}
source "$BASEDIR/manifest"
RAW="$BASEDIR/raw.js"
TMP="$BASEDIR/tmp.js"
LIB="$BASEDIR/lib.js"
LIBDIR="$BASEDIR/lib"
SRCDIR="$BASEDIR/src"
OUTPUTFILE="$BASEDIR/$OUTPUT"
echo "" > $RAW
echo "" > $LIB
echo "start concat libraries to $LIB"
for SRC in ${LIBS[@]};do
echo " $LIBDIR/$SRC"
cat "$LIBDIR/$SRC" >> $LIB
done
echo "start concat sources to $RAW"
for SRC in ${SOURCES[@]};do
echo " $SRCDIR/$SRC"
cat "$SRCDIR/$SRC" >> $RAW;
done
echo "start compiling"
java com.google.javascript.jscomp.CommandLineRunner --js_output_file $TMP --js $RAW
echo "concat output to $OUTPUTFILE"
rm $OUTPUTFILE
if [ -f "$BASEDIR/$PREFIX" ]; then
cat "$BASEDIR/$PREFIX" > $OUTPUTFILE
fi
cat $LIB >> $OUTPUTFILE
cat $TMP >> $OUTPUTFILE
if [ -f "$BASEDIR/$SUFFIX" ]; then
cat "$BASEDIR/$SUFFIX" >> $OUTPUTFILE
fi
echo "cleaning up removing $RAW $TMP $LIB"
rm -f $RAW $TMP $LIB
echo "finished"
PREFIX="src/code-prefix.js"
SUFFIX="src/code-suffix.js"
OUTPUT="dist/compiled.js"
LIBS=(
'jquery.js'
)
SOURCES=(
'intro.js'
'Template.js'
'RandomString.js'
'console.js'
'main.js'
'module1.js'
'module2.js'
'outro.js'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment