Move code into src/
[dygraphs.git] / generate-combined.sh
1 #!/bin/bash
2 # Generates a single JS file that's easier to include.
3
4 GetSources () {
5 # Include dyraph-options-reference only if DEBUG environment variable is set.
6 if [ ! -z "$DEBUG" ]; then
7 maybe_options_reference=dygraph-options-reference.js
8 else
9 maybe_options_reference=''
10 fi
11
12 # This list needs to be kept in sync w/ the one in dygraph-dev.js
13 # and the one in jsTestDriver.conf. Order matters, except for the plugins.
14 for F in \
15 polyfills/console.js \
16 dashed-canvas.js \
17 dygraph-options.js \
18 dygraph-layout.js \
19 dygraph-canvas.js \
20 dygraph.js \
21 dygraph-utils.js \
22 dygraph-gviz.js \
23 dygraph-interaction-model.js \
24 dygraph-tickers.js \
25 dygraph-plugin-base.js \
26 plugins/*.js \
27 dygraph-plugin-install.js \
28 $maybe_options_reference \
29 datahandler/datahandler.js \
30 datahandler/default.js \
31 datahandler/default-fractions.js \
32 datahandler/bars.js \
33 datahandler/bars-custom.js \
34 datahandler/bars-error.js \
35 datahandler/bars-fractions.js
36 do
37 echo "$F"
38 done
39 }
40
41 # Pack all the JS together.
42 CatSources () {
43 GetSources \
44 | xargs cat
45 }
46
47 Copyright () {
48 echo '/*! @license Copyright 2014 Dan Vanderkam (danvdk@gmail.com) MIT-licensed (http://opensource.org/licenses/MIT) */'
49 }
50
51 CatCompressed () {
52 node_modules/uglify-js/bin/uglifyjs \
53 $(GetSources | xargs) \
54 --compress warnings=false \
55 --mangle \
56 --define DEBUG=false \
57 --preamble "$(Copyright)" \
58 $*
59 }
60
61 ACTION="${1:-update}"
62 case "$ACTION" in
63 ls)
64 GetSources
65 ;;
66 cat)
67 Copyright
68 CatSources
69 ;;
70 cat-dev)
71 DEBUG=true
72 Copyright
73 CatSources
74 ;;
75 compress*|cat_compress*)
76 CatCompressed
77 ;;
78 update)
79 CatCompressed --source-map dygraph-combined.js.map \
80 > dygraph-combined.js
81 chmod a+r dygraph-combined.js dygraph-combined.js.map
82 ;;
83 *)
84 echo >&2 "Unknown action '$ACTION'"
85 exit 1
86 ;;
87 esac