From 1beeb31035c4028e84cde14b804c08d33bffbd02 Mon Sep 17 00:00:00 2001 From: Klaus Weidner Date: Thu, 24 Jan 2013 16:53:13 -0800 Subject: [PATCH] refactor generate-combined.sh Update the generate-combined.sh script to support printing an ordered source file list, cat'ing the compressed or uncompressed output, or updating the dygraph-combined.js file (the default). This is intended to make it easier to integrate dygraphs code into other builds. Move the plugins/{base,install}.js files to dygraph-plugin-{base,install}.js, this simplifies the file list by permitting use of plugins/*.js with no order dependency. --- closure-todo.txt | 4 +-- dygraph-dev.js | 4 +-- dygraph-plugin-base.js | 4 +++ dygraph-plugin-install.js | 19 ++++++++++ file-size-stats.sh | 4 +-- generate-combined.sh | 90 ++++++++++++++++++++++++++++++----------------- jsTestDriver.conf | 12 ++----- plugins/base.js | 6 ---- plugins/install.js | 20 ----------- 9 files changed, 90 insertions(+), 73 deletions(-) create mode 100644 dygraph-plugin-base.js create mode 100644 dygraph-plugin-install.js delete mode 100644 plugins/base.js delete mode 100644 plugins/install.js diff --git a/closure-todo.txt b/closure-todo.txt index 081b9ed..c9d42b7 100644 --- a/closure-todo.txt +++ b/closure-todo.txt @@ -20,14 +20,14 @@ x dygraph-tickers.js x dygraph-options-reference.js x dygraph-utils.js x dashed-canvas.js +- dygraph-plugin-base.js +- dygraph-plugin-install.js Plugins: - plugins/annotations.js - plugins/axes.js -- plugins/base.js - plugins/chart-labels.js - plugins/grid.js -- plugins/install.js - plugins/legend.js Here's a command that can be used to build dygraphs using the closure diff --git a/dygraph-dev.js b/dygraph-dev.js index 923bebb..c06d23d 100644 --- a/dygraph-dev.js +++ b/dygraph-dev.js @@ -28,14 +28,14 @@ "dygraph-gviz.js", "dygraph-interaction-model.js", "dygraph-tickers.js", - "plugins/base.js", + "dygraph-plugin-base.js", "plugins/annotations.js", "plugins/axes.js", "plugins/chart-labels.js", "plugins/grid.js", "plugins/legend.js", "plugins/range-selector.js", - "plugins/install.js", + "dygraph-plugin-install.js", "dygraph-options-reference.js" // Shouldn't be included in generate-combined.sh ]; diff --git a/dygraph-plugin-base.js b/dygraph-plugin-base.js new file mode 100644 index 0000000..7f758a9 --- /dev/null +++ b/dygraph-plugin-base.js @@ -0,0 +1,4 @@ +/*global Dygraph:false */ + +// Namespace for plugins. Load this before plugins/*.js files. +Dygraph.Plugins = {}; diff --git a/dygraph-plugin-install.js b/dygraph-plugin-install.js new file mode 100644 index 0000000..806a927 --- /dev/null +++ b/dygraph-plugin-install.js @@ -0,0 +1,19 @@ +/*global Dygraph:false */ + +// This file defines the ordering of the plugins. +// +// The ordering is from most-general to most-specific. +// This means that, in an event cascade, plugins which have registered for that +// event will be called in reverse order. +// +// This is most relevant for plugins which register a layout event, e.g. +// Axes, Legend and ChartLabels. + +Dygraph.PLUGINS.push( + Dygraph.Plugins.Legend, + Dygraph.Plugins.Axes, + Dygraph.Plugins.RangeSelector, // Has to be before ChartLabels so that its callbacks are called after ChartLabels' callbacks. + Dygraph.Plugins.ChartLabels, + Dygraph.Plugins.Annotations, + Dygraph.Plugins.Grid +); diff --git a/file-size-stats.sh b/file-size-stats.sh index 0657d1e..24f1bac 100755 --- a/file-size-stats.sh +++ b/file-size-stats.sh @@ -15,14 +15,14 @@ dygraph-tickers.js \ rgbcolor/rgbcolor.js \ strftime/strftime-min.js \ dashed-canvas.js \ -plugins/base.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 \ -plugins/install.js \ +dygraph-plugin-install.js \ ; do base_size=$(cat $file | wc -c) cat $file \ diff --git a/generate-combined.sh b/generate-combined.sh index a79c1d0..9e184ae 100755 --- a/generate-combined.sh +++ b/generate-combined.sh @@ -1,39 +1,65 @@ #!/bin/bash # Generates a single JS file that's easier to include. +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 +} + # Pack all the JS together. +CatSources () { + GetSources \ + | xargs cat \ + | perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,' +} -# This list needs to be kept in sync w/ the one in dygraph-dev.js -# and the one in jsTestDriver.conf. -cat \ -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 \ -plugins/base.js \ -plugins/annotations.js \ -plugins/axes.js \ -plugins/chart-labels.js \ -plugins/grid.js \ -plugins/legend.js \ -plugins/range-selector.js \ -plugins/install.js \ -| perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,' \ -> /tmp/dygraph.js +Copyright () { + echo '/*! @license Copyright 2011 Dan Vanderkam (danvdk@gmail.com) MIT-licensed (http://opensource.org/licenses/MIT) */' +} -java -jar yuicompressor-2.4.2.jar /tmp/dygraph.js \ -> /tmp/dygraph-packed.js +CatCompressed () { + Copyright + CatSources \ + | java -jar yuicompressor-2.4.2.jar --type js +} -( - echo '/*! @license Copyright 2011 Dan Vanderkam (danvdk@gmail.com) MIT-licensed (http://opensource.org/licenses/MIT) */' - cat /tmp/dygraph-packed.js -) > dygraph-combined.js -chmod a+r 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 diff --git a/jsTestDriver.conf b/jsTestDriver.conf index 2b411e2..ffbc369 100644 --- a/jsTestDriver.conf +++ b/jsTestDriver.conf @@ -17,13 +17,7 @@ load: - dygraph-tickers.js - dygraph-dev.js - excanvas.js - # NOTE: we can't do plugins/*.js because the order is important. - - plugins/base.js - - plugins/annotations.js - - plugins/axes.js - - plugins/range-selector.js - - plugins/chart-labels.js - - plugins/grid.js - - plugins/legend.js - - plugins/install.js + - dygraph-plugin-base.js + - plugins/*.js + - dygraph-plugin-install.js - auto_tests/tests/*.js diff --git a/plugins/base.js b/plugins/base.js deleted file mode 100644 index f5e6216..0000000 --- a/plugins/base.js +++ /dev/null @@ -1,6 +0,0 @@ -/*global Dygraph:false */ - -// Namespace for plugins. -Dygraph.Plugins = {}; - -// TODO(danvk): move this into the top-level directory. Only plugins here. diff --git a/plugins/install.js b/plugins/install.js deleted file mode 100644 index 656d426..0000000 --- a/plugins/install.js +++ /dev/null @@ -1,20 +0,0 @@ -/*global Dygraph:false */ - -// This file defines the ordering of the plugins. -// -// The ordering is from most-general to most-specific. -// This means that, in an event cascade, plugins which have registered for that -// event will be called in reverse order. -// -// This is most relevant for plugins which register a layout event, e.g. -// Axes, Legend and ChartLabels. - -// TODO(danvk): move this into the top-level directory. Only plugins here. -Dygraph.PLUGINS.push( - Dygraph.Plugins.Legend, - Dygraph.Plugins.Axes, - Dygraph.Plugins.RangeSelector, // Has to be before ChartLabels so that its callbacks are called after ChartLabels' callbacks. - Dygraph.Plugins.ChartLabels, - Dygraph.Plugins.Annotations, - Dygraph.Plugins.Grid -); -- 2.7.4