Merge pull request #231 from paulfelix/master
[dygraphs.git] / generate-combined.sh
index a5ccfca..9e184ae 100755 (executable)
@@ -1,32 +1,65 @@
 #!/bin/bash
 # Generates a single JS file that's easier to include.
-# This packed JS includes a partial copy of MochiKit and PlotKit.
-# It winds up being 146k uncompressed and 37k gzipped.
 
-# Generate the packed version of the subset of PlotKit needed by dygraphs.
-# This saves ~30k
-cd plotkit_v091
-./scripts/pack.py Base Layout Canvas > /tmp/plotkit-packed.js
-cd ..
+GetSources () {
+  # This list needs to be kept in sync w/ the one in dygraph-dev.js
+  # and the one in jsTestDriver.conf. Order matters, except for the plugins.
+  for F in \
+    strftime/strftime-min.js \
+    rgbcolor/rgbcolor.js \
+    stacktrace.js \
+    dashed-canvas.js \
+    dygraph-options.js \
+    dygraph-layout.js \
+    dygraph-canvas.js \
+    dygraph.js \
+    dygraph-utils.js \
+    dygraph-gviz.js \
+    dygraph-interaction-model.js \
+    dygraph-tickers.js \
+    dygraph-plugin-base.js \
+    plugins/*.js \
+    dygraph-plugin-install.js
+  do
+      echo "$F"
+  done
+}
 
-# Do the same for MochiKit. This save another 77k.
-cd mochikit_v14
-./scripts/pack.py \
-Base Iter Format DOM Style Color Signal \
-> /tmp/mochikit-packed.js
-cd ..
+# Pack all the JS together.
+CatSources () {
+  GetSources \
+  | xargs cat \
+  | perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,'
+}
 
-# Pack the dygraphs JS. This saves another 22k.
-cat \
-dygraph-canvas.js \
-dygraph.js \
-> /tmp/dygraph.js
+Copyright () {
+  echo '/*! @license Copyright 2011 Dan Vanderkam (danvdk@gmail.com) MIT-licensed (http://opensource.org/licenses/MIT) */'
+}
 
-java -jar plotkit_v091/scripts/custom_rhino.jar -c /tmp/dygraph.js \
-> /tmp/dygraph-packed.js
+CatCompressed () {
+  Copyright
+  CatSources \
+  | java -jar yuicompressor-2.4.2.jar --type js
+}
 
-cat \
-/tmp/mochikit-packed.js \
-/tmp/plotkit-packed.js \
-/tmp/dygraph-packed.js \
-> dygraph-combined.js
+ACTION="${1:-update}"
+case "$ACTION" in
+ls)
+  GetSources
+  ;;
+cat)
+  Copyright
+  CatSources
+  ;;
+compress*|cat_compress*)
+  CatCompressed
+  ;;
+update)
+  CatCompressed > dygraph-combined.js
+  chmod a+r dygraph-combined.js
+  ;;
+*)
+  echo >&2 "Unknown action '$ACTION'"
+  exit 1
+  ;;
+esac