From: Dan Vanderkam Date: Fri, 23 Oct 2015 15:22:44 +0000 (-0400) Subject: Set DEBUG using envify; options reference checks restored X-Git-Tag: v2.0.0~38^2~11 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=7fea22bef3dd932a4d3d706d102565ee28b26f91;p=dygraphs.git Set DEBUG using envify; options reference checks restored --- diff --git a/auto_tests/tests/dygraph-options-tests.js b/auto_tests/tests/dygraph-options-tests.js index aa9db33..ded9ee3 100644 --- a/auto_tests/tests/dygraph-options-tests.js +++ b/auto_tests/tests/dygraph-options-tests.js @@ -4,6 +4,7 @@ import Dygraph from '../../src/dygraph'; import DygraphOptions from '../../src/dygraph-options'; +import OPTIONS_REFERENCE from '../../src/dygraph-options-reference'; describe("dygraph-options-tests", function() { @@ -76,7 +77,7 @@ var getWarnings = function(div, data, opts) { }; it('testLogWarningForNonexistentOption', function() { - if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') { + if (!OPTIONS_REFERENCE) { return; // this test won't pass in non-debug mode. } @@ -105,7 +106,7 @@ it('testLogWarningForNonexistentOption', function() { }); it('testOnlyLogsEachWarningOnce', function() { - if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') { + if (!OPTIONS_REFERENCE) { 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 index 0000000..a95c612 --- /dev/null +++ b/make-prod-combined.sh @@ -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 diff --git a/package.json b/package.json index 4d1f576..7d136cc 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,8 @@ "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", @@ -58,7 +60,7 @@ "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": { diff --git a/src/dygraph-options-reference.js b/src/dygraph-options-reference.js index 933bdab..3f9a640 100644 --- a/src/dygraph-options-reference.js +++ b/src/dygraph-options-reference.js @@ -4,11 +4,18 @@ * 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. -Dygraph.OPTIONS_REFERENCE = // +OPTIONS_REFERENCE = // { "xValueParser": { "default": "parseFloat() or Date.parse()*", @@ -831,57 +838,58 @@ Dygraph.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; diff --git a/src/dygraph-options.js b/src/dygraph-options.js index 8affcdf..d7ec5fb 100644 --- a/src/dygraph-options.js +++ b/src/dygraph-options.js @@ -11,11 +11,11 @@ // 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'; +import OPTIONS_REFERENCE from './dygraph-options-reference'; /* * 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"] || {}); - // 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_; }; -// TODO: fix this -// if (DEBUG) { -if (false) { +// For "production" code, this gets removed by uglifyjs. +if (process.env.NODE_ENV != 'production') { /** * 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() { - if (typeof Dygraph.OPTIONS_REFERENCE === 'undefined') { + if (typeof OPTIONS_REFERENCE === 'undefined') { 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); } }; diff --git a/src/dygraph.js b/src/dygraph.js index 321b8fa..1060aab 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -43,10 +43,6 @@ */ -// 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'; @@ -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 OPTIONS_REFERENCE from './dygraph-options-reference'; 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'; -/*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false,ActiveXObject:false */ "use strict"; /** @@ -368,16 +364,17 @@ Dygraph.prototype.toString = function() { * @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); }; diff --git a/watch-combined.js b/watch-combined.js new file mode 100755 index 0000000..4ef91ce --- /dev/null +++ b/watch-combined.js @@ -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 diff --git a/watch-tests.sh b/watch-tests.sh index 002f879..9b2b648 100755 --- a/watch-tests.sh +++ b/watch-tests.sh @@ -1,63 +1,8 @@ +#!/bin/bash watchify \ - -v -t babelify \ + -v \ + -t babelify \ + -t [ envify --NODE_ENV development ] \ --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 < /dev/null - - -# These ones are going to be hard -cat < /dev/null + auto_tests/tests/*.js