Set DEBUG using envify; options reference checks restored
authorDan Vanderkam <danvdk@gmail.com>
Fri, 23 Oct 2015 15:22:44 +0000 (11:22 -0400)
committerDan Vanderkam <danvdk@gmail.com>
Sun, 25 Oct 2015 02:44:14 +0000 (22:44 -0400)
auto_tests/tests/dygraph-options-tests.js
make-prod-combined.sh [new file with mode: 0755]
package.json
src/dygraph-options-reference.js
src/dygraph-options.js
src/dygraph.js
watch-combined.js [new file with mode: 0755]
watch-tests.sh

index aa9db33..ded9ee3 100644 (file)
@@ -4,6 +4,7 @@
 
 import Dygraph from '../../src/dygraph';
 import DygraphOptions from '../../src/dygraph-options';
 
 import Dygraph from '../../src/dygraph';
 import DygraphOptions from '../../src/dygraph-options';
+import OPTIONS_REFERENCE from '../../src/dygraph-options-reference';
 
 describe("dygraph-options-tests", function() {
 
 
 describe("dygraph-options-tests", function() {
 
@@ -76,7 +77,7 @@ var getWarnings = function(div, data, opts) {
 };
 
 it('testLogWarningForNonexistentOption', function() {
 };
 
 it('testLogWarningForNonexistentOption', function() {
-  if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
+  if (!OPTIONS_REFERENCE) {
     return;  // this test won't pass in non-debug mode.
   }
 
     return;  // this test won't pass in non-debug mode.
   }
 
@@ -105,7 +106,7 @@ it('testLogWarningForNonexistentOption', function() {
 });
 
 it('testOnlyLogsEachWarningOnce', function() {
 });
 
 it('testOnlyLogsEachWarningOnce', function() {
-  if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
+  if (!OPTIONS_REFERENCE) {
     return;  // this test won't pass in non-debug mode.
   }
 
     return;  // this test won't pass in non-debug mode.
   }
 
diff --git a/make-prod-combined.sh b/make-prod-combined.sh
new file mode 100755 (executable)
index 0000000..a95c612
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+browserify \
+  -v \
+  -t babelify \
+  -t [ envify --NODE_ENV production ] \
+  --debug \
+  --standalone Dygraph \
+  src/dygraph.js \
+  | uglifyjs -c -m \
+  > dist/dygraph.js
index 4d1f576..7d136cc 100644 (file)
@@ -31,6 +31,8 @@
     "chai": "^3.3.0",
     "closure-compiler": "^0.2.6",
     "coveralls": "^2.11.2",
     "chai": "^3.3.0",
     "closure-compiler": "^0.2.6",
     "coveralls": "^2.11.2",
+    "envify": "^3.4.0",
+    "exorcist": "^0.4.0",
     "gulp": "^3.8.10",
     "gulp-concat": "^2.4.3",
     "gulp-eslint": "^0.2.0",
     "gulp": "^3.8.10",
     "gulp-concat": "^2.4.3",
     "gulp-eslint": "^0.2.0",
@@ -58,7 +60,7 @@
     "phantomjs": "^1.9.7-8",
     "pre-commit": "^1.0.6",
     "source-map": "^0.4.2",
     "phantomjs": "^1.9.7-8",
     "pre-commit": "^1.0.6",
     "source-map": "^0.4.2",
-    "uglify-js": "^2",
+    "uglify-js": "^2.5.0",
     "watchify": "^3.4.0"
   },
   "scripts": {
     "watchify": "^3.4.0"
   },
   "scripts": {
index 933bdab..3f9a640 100644 (file)
@@ -4,11 +4,18 @@
  * MIT-licensed (http://opensource.org/licenses/MIT)
  */
 
  * MIT-licensed (http://opensource.org/licenses/MIT)
  */
 
+"use strict";
+
+var OPTIONS_REFERENCE = null;
+
+// For "production" code, this gets removed by uglifyjs.
+if (process.env.NODE_ENV != 'production') {
+
 // NOTE: in addition to parsing as JS, this snippet is expected to be valid
 // JSON. This assumption cannot be checked in JS, but it will be checked when
 // documentation is generated by the generate-documentation.py script. For the
 // most part, this just means that you should always use double quotes.
 // NOTE: in addition to parsing as JS, this snippet is expected to be valid
 // JSON. This assumption cannot be checked in JS, but it will be checked when
 // documentation is generated by the generate-documentation.py script. For the
 // most part, this just means that you should always use double quotes.
-Dygraph.OPTIONS_REFERENCE =  // <JSON>
+OPTIONS_REFERENCE =  // <JSON>
 {
   "xValueParser": {
     "default": "parseFloat() or Date.parse()*",
 {
   "xValueParser": {
     "default": "parseFloat() or Date.parse()*",
@@ -831,57 +838,58 @@ Dygraph.OPTIONS_REFERENCE =  // <JSON>
 // most part, this just means that you should always use double quotes.
 
 // Do a quick sanity check on the options reference.
 // most part, this just means that you should always use double quotes.
 
 // Do a quick sanity check on the options reference.
-(function() {
-  "use strict";
-  var warn = function(msg) { if (window.console) window.console.warn(msg); };
-  var flds = ['type', 'default', 'description'];
-  var valid_cats = [
-   'Annotations',
-   'Axis display',
-   'Chart labels',
-   'CSV parsing',
-   'Callbacks',
-   'Data',
-   'Data Line display',
-   'Data Series Colors',
-   'Error Bars',
-   'Grid',
-   'Interactive Elements',
-   'Range Selector',
-   'Legend',
-   'Overall display',
-   'Rolling Averages',
-   'Series',
-   'Value display/formatting',
-   'Zooming',
-   'Debugging',
-   'Configuration',
-   'Deprecated'
-  ];
-  var i;
-  var cats = {};
-  for (i = 0; i < valid_cats.length; i++) cats[valid_cats[i]] = true;
+var warn = function(msg) { if (window.console) window.console.warn(msg); };
+var flds = ['type', 'default', 'description'];
+var valid_cats = [
+ 'Annotations',
+ 'Axis display',
+ 'Chart labels',
+ 'CSV parsing',
+ 'Callbacks',
+ 'Data',
+ 'Data Line display',
+ 'Data Series Colors',
+ 'Error Bars',
+ 'Grid',
+ 'Interactive Elements',
+ 'Range Selector',
+ 'Legend',
+ 'Overall display',
+ 'Rolling Averages',
+ 'Series',
+ 'Value display/formatting',
+ 'Zooming',
+ 'Debugging',
+ 'Configuration',
+ 'Deprecated'
+];
+var i;
+var cats = {};
+for (i = 0; i < valid_cats.length; i++) cats[valid_cats[i]] = true;
 
 
-  for (var k in Dygraph.OPTIONS_REFERENCE) {
-    if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(k)) continue;
-    var op = Dygraph.OPTIONS_REFERENCE[k];
-    for (i = 0; i < flds.length; i++) {
-      if (!op.hasOwnProperty(flds[i])) {
-        warn('Option ' + k + ' missing "' + flds[i] + '" property');
-      } else if (typeof(op[flds[i]]) != 'string') {
-        warn(k + '.' + flds[i] + ' must be of type string');
-      }
+for (var k in OPTIONS_REFERENCE) {
+  if (!OPTIONS_REFERENCE.hasOwnProperty(k)) continue;
+  var op = OPTIONS_REFERENCE[k];
+  for (i = 0; i < flds.length; i++) {
+    if (!op.hasOwnProperty(flds[i])) {
+      warn('Option ' + k + ' missing "' + flds[i] + '" property');
+    } else if (typeof(op[flds[i]]) != 'string') {
+      warn(k + '.' + flds[i] + ' must be of type string');
     }
     }
-    var labels = op.labels;
-    if (typeof(labels) !== 'object') {
-      warn('Option "' + k + '" is missing a "labels": [...] option');
-    } else {
-      for (i = 0; i < labels.length; i++) {
-        if (!cats.hasOwnProperty(labels[i])) {
-          warn('Option "' + k + '" has label "' + labels[i] +
-               '", which is invalid.');
-        }
+  }
+  var labels = op.labels;
+  if (typeof(labels) !== 'object') {
+    warn('Option "' + k + '" is missing a "labels": [...] option');
+  } else {
+    for (i = 0; i < labels.length; i++) {
+      if (!cats.hasOwnProperty(labels[i])) {
+        warn('Option "' + k + '" has label "' + labels[i] +
+             '", which is invalid.');
       }
     }
   }
       }
     }
   }
-})();
+}
+
+}
+
+export default OPTIONS_REFERENCE;
index 8affcdf..d7ec5fb 100644 (file)
 
 // TODO: remove this jshint directive & fix the warnings.
 /*jshint sub:true */
 
 // TODO: remove this jshint directive & fix the warnings.
 /*jshint sub:true */
-/*global Dygraph:false */
 "use strict";
 
 import * as utils from './dygraph-utils';
 import DEFAULT_ATTRS from './dygraph-default-attrs';
 "use strict";
 
 import * as utils from './dygraph-utils';
 import DEFAULT_ATTRS from './dygraph-default-attrs';
+import OPTIONS_REFERENCE from './dygraph-options-reference';
 
 /*
  * Interesting member variables: (REMOVING THIS LIST AS I CLOSURIZE)
 
 /*
  * Interesting member variables: (REMOVING THIS LIST AS I CLOSURIZE)
@@ -166,7 +166,10 @@ DygraphOptions.prototype.reparseSeries = function() {
   }
   utils.update(this.xAxis_.options, axis_opts["x"] || {});
 
   }
   utils.update(this.xAxis_.options, axis_opts["x"] || {});
 
-  // if (DEBUG) this.validateOptions_();
+  // For "production" code, this gets removed by uglifyjs.
+  if (process.env.NODE_ENV != 'production') {
+    this.validateOptions_();
+  }
 };
 
 /**
 };
 
 /**
@@ -322,23 +325,22 @@ DygraphOptions.prototype.seriesNames = function() {
   return this.labels_;
 };
 
   return this.labels_;
 };
 
-// TODO: fix this
-// if (DEBUG) {
-if (false) {
+// For "production" code, this gets removed by uglifyjs.
+if (process.env.NODE_ENV != 'production') {
 
 /**
  * Validate all options.
 
 /**
  * Validate all options.
- * This requires Dygraph.OPTIONS_REFERENCE, which is only available in debug builds.
+ * This requires OPTIONS_REFERENCE, which is only available in debug builds.
  * @private
  */
 DygraphOptions.prototype.validateOptions_ = function() {
  * @private
  */
 DygraphOptions.prototype.validateOptions_ = function() {
-  if (typeof Dygraph.OPTIONS_REFERENCE === 'undefined') {
+  if (typeof OPTIONS_REFERENCE === 'undefined') {
     throw 'Called validateOptions_ in prod build.';
   }
 
   var that = this;
   var validateOption = function(optionName) {
     throw 'Called validateOptions_ in prod build.';
   }
 
   var that = this;
   var validateOption = function(optionName) {
-    if (!Dygraph.OPTIONS_REFERENCE[optionName]) {
+    if (!OPTIONS_REFERENCE[optionName]) {
       that.warnInvalidOption_(optionName);
     }
   };
       that.warnInvalidOption_(optionName);
     }
   };
index 321b8fa..1060aab 100644 (file)
 
  */
 
 
  */
 
-// For "production" code, this gets set to false by uglifyjs.
-// if (typeof(DEBUG) === 'undefined') DEBUG=true;
-var DEBUG = true;
-
 import DygraphLayout from './dygraph-layout';
 import DygraphCanvasRenderer from './dygraph-canvas';
 import DygraphOptions from './dygraph-options';
 import DygraphLayout from './dygraph-layout';
 import DygraphCanvasRenderer from './dygraph-canvas';
 import DygraphOptions from './dygraph-options';
@@ -54,6 +50,7 @@ import DygraphInteraction from './dygraph-interaction-model';
 import * as DygraphTickers from './dygraph-tickers';
 import * as utils from './dygraph-utils';
 import DEFAULT_ATTRS from './dygraph-default-attrs';
 import * as DygraphTickers from './dygraph-tickers';
 import * as utils from './dygraph-utils';
 import DEFAULT_ATTRS from './dygraph-default-attrs';
+import OPTIONS_REFERENCE from './dygraph-options-reference';
 
 import DefaultHandler from './datahandler/default';
 import ErrorBarsHandler from './datahandler/bars-error';
 
 import DefaultHandler from './datahandler/default';
 import ErrorBarsHandler from './datahandler/bars-error';
@@ -70,7 +67,6 @@ import RangeSelectorPlugin from './plugins/range-selector';
 
 import GVizChart from './dygraph-gviz';
 
 
 import GVizChart from './dygraph-gviz';
 
-/*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false,ActiveXObject:false */
 "use strict";
 
 /**
 "use strict";
 
 /**
@@ -368,16 +364,17 @@ Dygraph.prototype.toString = function() {
  * @return { ... } The value of the option.
  */
 Dygraph.prototype.attr_ = function(name, seriesName) {
  * @return { ... } The value of the option.
  */
 Dygraph.prototype.attr_ = function(name, seriesName) {
-  // 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;
-  //   }
-  // }
+  // For "production" code, this gets removed by uglifyjs.
+  if (process.env.NODE_ENV != 'production') {
+    if (typeof(OPTIONS_REFERENCE) === 'undefined') {
+      console.error('Must include options reference JS for testing');
+    } else if (!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.
+      OPTIONS_REFERENCE[name] = true;
+    }
+  }
   return seriesName ? this.attributes_.getForSeries(name, seriesName) : this.attributes_.get(name);
 };
 
   return seriesName ? this.attributes_.getForSeries(name, seriesName) : this.attributes_.get(name);
 };
 
diff --git a/watch-combined.js b/watch-combined.js
new file mode 100755 (executable)
index 0000000..4ef91ce
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+watchify \
+  -v \
+  -t babelify \
+  -t [ envify --NODE_ENV development ] \
+  --debug \
+  --standalone Dygraph \
+  -o dist/dygraph.js \
+  src/dygraph.js
index 002f879..9b2b648 100755 (executable)
@@ -1,63 +1,8 @@
+#!/bin/bash
 watchify \
 watchify \
-  -v -t babelify \
+  -v \
+  -t babelify \
+  -t [ envify --NODE_ENV development ] \
   --debug \
   -o dist/tests.js \
   --debug \
   -o dist/tests.js \
-  auto_tests/tests/sanity.js \
-  auto_tests/tests/pathological_cases.js \
-  auto_tests/tests/axis_labels.js \
-  auto_tests/tests/annotations.js \
-  auto_tests/tests/callback.js \
-  auto_tests/tests/connect_separated_points.js \
-  auto_tests/tests/fill_step_plot.js \
-  auto_tests/tests/custom_bars.js \
-  auto_tests/tests/css.js \
-  auto_tests/tests/data_api.js \
-  auto_tests/tests/date_formats.js \
-  auto_tests/tests/date_ticker.js \
-  auto_tests/tests/error_bars.js \
-  auto_tests/tests/dygraph-options-tests.js \
-  auto_tests/tests/fast_canvas_proxy.js \
-  auto_tests/tests/formats.js \
-  auto_tests/tests/hidpi.js \
-  auto_tests/tests/interaction_model.js \
-  auto_tests/tests/missing_points.js \
-  auto_tests/tests/multi_csv.js \
-
-
-cat <<END
-auto_tests/tests/multiple_axes.js \
-auto_tests/tests/no_hours.js \
-auto_tests/tests/numeric_ticker.js \
-auto_tests/tests/parser.js \
-auto_tests/tests/per_axis.js \
-auto_tests/tests/per_series.js \
-auto_tests/tests/plugins.js \
-auto_tests/tests/plugins_legend.js \
-auto_tests/tests/range_selector.js \
-auto_tests/tests/range_tests.js \
-auto_tests/tests/resize.js \
-auto_tests/tests/rolling_average.js \
-auto_tests/tests/scientific_notation.js \
-auto_tests/tests/scrolling_div.js \
-auto_tests/tests/selection.js \
-auto_tests/tests/simple_drawing.js \
-auto_tests/tests/smooth_plotter.js \
-auto_tests/tests/stacked.js \
-auto_tests/tests/step_plot_per_series.js \
-auto_tests/tests/synchronize.js \
-auto_tests/tests/to_dom_coords.js \
-auto_tests/tests/two_digit_years.js \
-auto_tests/tests/update_options.js \
-auto_tests/tests/update_while_panning.js \
-auto_tests/tests/utils_test.js \
-auto_tests/tests/axis_labels-deprecated.js \
-auto_tests/tests/visibility.js
-auto_tests/tests/gviz.js \
-END > /dev/null
-
-
-# These ones are going to be hard
-cat <<END
-# There are differences between how installPattern and setLineDash work:
-auto_tests/tests/grid_per_axis.js
-END > /dev/null
+  auto_tests/tests/*.js