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