Merge pull request #464 from danvk/sourcemap
authorRobert Konigsberg <konigsberg@gmail.com>
Sun, 16 Nov 2014 00:07:28 +0000 (19:07 -0500)
committerRobert Konigsberg <konigsberg@gmail.com>
Sun, 16 Nov 2014 00:07:28 +0000 (19:07 -0500)
Generate a source map!

dygraph.js
file-size-stats.sh [deleted file]
generate-combined.sh

index 7b80e32..a9b1cf9 100644 (file)
@@ -43,6 +43,9 @@
 
  */
 
+// For "production" code, this gets set to false by uglifyjs.
+if (typeof(DEBUG) === 'undefined') DEBUG=true;
+
 /*jshint globalstrict: true */
 /*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false,ActiveXObject:false */
 "use strict";
@@ -665,16 +668,16 @@ Dygraph.prototype.toString = function() {
  * @return { ... } The value of the option.
  */
 Dygraph.prototype.attr_ = function(name, seriesName) {
-// <REMOVE_FOR_COMBINED>
-  if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
-    console.error('Must include options reference JS for testing');
-  } else if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(name)) {
-    console.error('Dygraphs is using property ' + name + ', which has no ' +
-                  'entry in the Dygraphs.OPTIONS_REFERENCE listing.');
-    // Only log this error once.
-    Dygraph.OPTIONS_REFERENCE[name] = true;
-  }
-// </REMOVE_FOR_COMBINED>
+  if (DEBUG) {
+    if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
+      console.error('Must include options reference JS for testing');
+    } else if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(name)) {
+      console.error('Dygraphs is using property ' + name + ', which has no ' +
+                    'entry in the Dygraphs.OPTIONS_REFERENCE listing.');
+      // Only log this error once.
+      Dygraph.OPTIONS_REFERENCE[name] = true;
+    }
+  }
   return seriesName ? this.attributes_.getForSeries(name, seriesName) : this.attributes_.get(name);
 };
 
diff --git a/file-size-stats.sh b/file-size-stats.sh
deleted file mode 100755 (executable)
index fb81519..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash
-
-# Reports compressed file sizes for each JS file in dygraphs.
-
-# This list needs to be kept in sync w/ the one in dygraph-dev.js
-# and the one in jsTestDriver.conf.
-for file in \
-dygraph-layout.js \
-dygraph-canvas.js \
-dygraph.js \
-dygraph-utils.js \
-dygraph-gviz.js \
-dygraph-interaction-model.js \
-dygraph-tickers.js \
-dashed-canvas.js \
-dygraph-plugin-base.js \
-plugins/annotations.js \
-plugins/axes.js \
-plugins/range-selector.js \
-plugins/chart-labels.js \
-plugins/grid.js \
-plugins/legend.js \
-dygraph-plugin-install.js \
-; do
-  base_size=$(cat $file | wc -c)
-  cat $file \
-    | perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,' \
-    > /tmp/dygraph.js
-  min_size=$(java -jar yuicompressor-2.4.2.jar /tmp/dygraph.js | gzip -c | wc -c)
-
-  echo "$min_size ($base_size) $file"
-done
index 30c0a7e..a224156 100755 (executable)
@@ -33,8 +33,7 @@ GetSources () {
 # Pack all the JS together.
 CatSources () {
   GetSources \
-  | xargs cat \
-  | perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,'
+  | xargs cat 
 }
 
 Copyright () {
@@ -42,10 +41,13 @@ Copyright () {
 }
 
 CatCompressed () {
-  Copyright
-  CatSources \
-  | grep -v '"use strict";' \
-  | node_modules/uglify-js/bin/uglifyjs -c warnings=false -m
+  node_modules/uglify-js/bin/uglifyjs \
+    $(GetSources | xargs) \
+    --compress warnings=false \
+    --mangle \
+    --define DEBUG=false \
+    --preamble "$(Copyright)" \
+    $*
 }
 
 ACTION="${1:-update}"
@@ -61,8 +63,9 @@ compress*|cat_compress*)
   CatCompressed
   ;;
 update)
-  CatCompressed > dygraph-combined.js
-  chmod a+r dygraph-combined.js
+  CatCompressed --source-map dygraph-combined.js.map \
+    > dygraph-combined.js
+  chmod a+r dygraph-combined.js dygraph-combined.js.map
   ;;
 *)
   echo >&2 "Unknown action '$ACTION'"