Merge pull request #457 from danvk/fix-log
[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 | perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,'
38 }
39
40 Copyright () {
41 echo '/*! @license Copyright 2014 Dan Vanderkam (danvdk@gmail.com) MIT-licensed (http://opensource.org/licenses/MIT) */'
42 }
43
44 CatCompressed () {
45 Copyright
46 CatSources \
47 | grep -v '"use strict";' \
48 | node_modules/uglify-js/bin/uglifyjs -c warnings=false -m
49 }
50
51 ACTION="${1:-update}"
52 case "$ACTION" in
53 ls)
54 GetSources
55 ;;
56 cat)
57 Copyright
58 CatSources
59 ;;
60 compress*|cat_compress*)
61 CatCompressed
62 ;;
63 update)
64 CatCompressed > dygraph-combined.js
65 chmod a+r dygraph-combined.js
66 ;;
67 *)
68 echo >&2 "Unknown action '$ACTION'"
69 exit 1
70 ;;
71 esac