Annotation of loncom/build/compressjs.sh, revision 1.1

1.1     ! damieng     1: #!/bin/bash
        !             2: 
        !             3: # Constants
        !             4: SERVICE_URL=http://closure-compiler.appspot.com/compile
        !             5: NEWFILE="c`date +"%d%m%y"`.js"
        !             6: OPTIONS=""
        !             7: 
        !             8: if [ "$1" = "-strict" ]
        !             9: then
        !            10:         OPTIONS="--data language=ECMASCRIPT5_STRICT"
        !            11:         shift
        !            12: fi
        !            13: 
        !            14: # Check if files to compile are provided
        !            15: if [ $# -eq 0 ]
        !            16: then
        !            17: 	echo 'Nothing to compile. Specify input files as command arguments. E.g.'
        !            18: 	echo './compressjs file1.js file2.js file3.js'
        !            19: 	exit
        !            20: fi
        !            21: 
        !            22: # Itearate through all files
        !            23: for f in $*
        !            24: do
        !            25: 	if [ -r "${f}" ]
        !            26: 	then
        !            27: 		code="${code} --data-urlencode js_code@${f}"
        !            28: 	else
        !            29: 		echo "File ${f} does not exist or is not readable. Skipped."
        !            30: 	fi
        !            31: done
        !            32: 
        !            33: # Send request
        !            34: curl \
        !            35: --url ${SERVICE_URL} \
        !            36: --header 'Content-type: application/x-www-form-urlencoded' \
        !            37: ${code} \
        !            38: --data output_format=json \
        !            39: --data output_info=compiled_code \
        !            40: --data output_info=statistics \
        !            41: --data output_info=errors \
        !            42: --data compilation_level=SIMPLE_OPTIMIZATIONS \
        !            43: ${OPTIONS} |
        !            44: 
        !            45: python -c '
        !            46: import json, sys
        !            47: data = json.load(sys.stdin)
        !            48: 
        !            49: if "errors" in data:
        !            50: 	print "### COMPILATION FAILED WITH ERRORS"
        !            51: 	for err in data["errors"]:
        !            52: 		file = sys.argv[int(err["file"].replace("Input_", "")) + 1]
        !            53: 		print "File: %s, %d:%d" % (file, err["lineno"], err["charno"])
        !            54: 		print "Error: %s" % err["error"]
        !            55: 		print "Line: %s" % err["line"]
        !            56: 		
        !            57: 	print "\nBuild failed.\n"
        !            58: 	
        !            59: else:
        !            60: 	print "### COMPILATION COMPLETED"
        !            61: 	print "Original size: %db, gziped: %db" % (data["statistics"]["originalSize"], data["statistics"]["originalGzipSize"])
        !            62: 	print "Compressed size: %db, gziped: %db" % (data["statistics"]["compressedSize"], data["statistics"]["compressedGzipSize"])
        !            63: 	print "Compression rate: %.2f" % (float(data["statistics"]["compressedSize"]) / int(data["statistics"]["originalSize"]))
        !            64: 
        !            65: 	filename = "'${NEWFILE}'"
        !            66: 	f = open(filename, "w")
        !            67: 	f.write(data["compiledCode"])
        !            68: 
        !            69: 	print "\nBuild file %s created.\n" % filename
        !            70: ' $@

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>