diff --git a/build/build.py b/build/build.py new file mode 100755 index 0000000000..9ac625411d --- /dev/null +++ b/build/build.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +import sys +sys.path.append("../tools") + +import jsmin, mergejs + +sourceDirectory = "../lib" +configFilename = "library.cfg" +outputFilename = "OpenLayers.js" + +if len(sys.argv) > 1: + configFilename = sys.argv[1] + ".cfg" +if len(sys.argv) > 2: + outputFilename = sys.argv[2] + +print "Adding license file." +merged = file("license.txt").read() +print "Merging libraries." +merged += mergejs.run(sourceDirectory, None, configFilename) +print "Compressing." +minimized = jsmin.jsmin(merged) + +print "Writing to %s." % outputFilename +file(outputFilename, "w").write(minimized) + +print "Done." diff --git a/build/build.sh b/build/build.sh deleted file mode 100755 index b5435a2268..0000000000 --- a/build/build.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -# -# Script to build compressed single file version of OpenLayers library -# - -OUTPUT_FILENAME=OpenLayers.js -TMP_OUTPUT_FILENAME=tmp.${OUTPUT_FILENAME} - -TOOLS_DIR=../tools - -if [ "$1" != "" ]; then - CFG_FILENAME="$1.cfg" -else - CFG_FILENAME=library.cfg -fi - -SRC_DIR=../lib - -CMD_MERGE_JS=${TOOLS_DIR}/mergejs.py - -CMD_SHRINKSAFE=${TOOLS_DIR}/shrinksafe.py -CMD_JSMIN=${TOOLS_DIR}/jsmin.py - -LICENSE_HEADER_FILENAME=license.txt - - -## Generate "fat" single file library version -${CMD_MERGE_JS} -c ${CFG_FILENAME} ${TMP_OUTPUT_FILENAME} ${SRC_DIR} - - -## Compress ("shrink") the single file library version - -echo -echo Shrinking and post-processing... -# (We also append the license header here.) -cat ${LICENSE_HEADER_FILENAME} > ${OUTPUT_FILENAME} -${CMD_JSMIN} <${TMP_OUTPUT_FILENAME} >> ${OUTPUT_FILENAME} - -echo Cleaning up... -rm $TMP_OUTPUT_FILENAME - -echo -echo Done. diff --git a/tools/mergejs.py b/tools/mergejs.py index 7b823f93df..95a705859f 100755 --- a/tools/mergejs.py +++ b/tools/mergejs.py @@ -127,28 +127,10 @@ class Config: self.include = lines[lines.index("[include]") + 1:lines.index("[exclude]")] self.exclude = lines[lines.index("[exclude]") + 1:] -if __name__ == "__main__": - import getopt - - options, args = getopt.getopt(sys.argv[1:], "-c:") - - try: - outputFilename = args[0] - except IndexError: - usage(sys.argv[0]) - raise SystemExit - else: - sourceDirectory = args[1] - if not sourceDirectory: - usage(sys.argv[0]) - raise SystemExit - +def run (sourceDirectory, outputFilename = None, configFile = None): cfg = None - if options and options[0][0] == "-c": - filename = options[0][1] - print "Parsing configuration file: %s" % filename - - cfg = Config(filename) + if configFile: + cfg = Config(configFile) print cfg.include allFiles = [] @@ -227,6 +209,30 @@ if __name__ == "__main__": print "\nTotal files merged: %d " % len(allFiles) - print "\nGenerating: %s" % (outputFilename) + if outputFilename: + print "\nGenerating: %s" % (outputFilename) + open(outputFilename, "w").write("".join(result)) + return "".join(result) - open(outputFilename, "w").write("".join(result)) +if __name__ == "__main__": + import getopt + + options, args = getopt.getopt(sys.argv[1:], "-c:") + + try: + outputFilename = args[0] + except IndexError: + usage(sys.argv[0]) + raise SystemExit + else: + sourceDirectory = args[1] + if not sourceDirectory: + usage(sys.argv[0]) + raise SystemExit + + configFile = None + if options and options[0][0] == "-c": + configFile = options[0][1] + print "Parsing configuration file: %s" % filename + + run( sourceDirectory, outputFilename, configFile )