Set this for drawCallback
[dygraphs.git] / gulpfile.js
... / ...
CommitLineData
1var gulp = require('gulp');
2var plugins = require('gulp-load-plugins')();
3var karma = require('karma').server;
4var path = require('path');
5
6var dev = false;
7var src = {
8 base: "src",
9 polyfills: {
10 base: "src/polyfills",
11 files: [
12 "console.js",
13 "dashed-canvas.js"
14 ]
15 },
16 main: {
17 base: "src",
18 files: [
19 "dygraph-options.js",
20 "dygraph-layout.js",
21 "dygraph-canvas.js",
22 "dygraph.js",
23 "dygraph-utils.js",
24 "dygraph-gviz.js",
25 "dygraph-interaction-model.js",
26 "dygraph-tickers.js",
27 "dygraph-plugin-base.js"
28 ]
29 } ,
30 plugins: {
31 base: "src/plugins",
32 files: [
33 "annotations.js",
34 "axes.js",
35 "chart-labels.js",
36 "grid.js",
37 "legend.js",
38 "range-selector.js",
39 "../dygraph-plugin-install.js"
40 ]
41 },
42 // Only used by dynamic loader
43 devOptions: {
44 base: "src",
45 files: ["dygraph-options-reference.js"]
46 },
47 datahandlers: {
48 base: "src/datahandler",
49 files: [
50 "datahandler.js",
51 "default.js",
52 "default-fractions.js",
53 "bars.js",
54 "bars-error.js",
55 "bars-custom.js",
56 "bars-fractions.js"
57 ]
58 }
59};
60
61// Convenience function to merge multiple arrays into one
62var mergePaths = function() {
63 var paths = [];
64 var pathobj = null;
65 if (arguments.length > 0) {
66 for (var i = 0; i < arguments.length; i++) {
67 pathObj = arguments[i];
68 pathObj.files.map(function(filename) {
69 paths.push(path.join(pathObj.base, filename));
70 });
71 }
72
73 return paths;
74 } else {
75 return [];
76 }
77};
78
79var copyright = '/*! @license Copyright 2015 Dan Vanderkam (danvdk@gmail.com) MIT-licensed (http://opensource.org/licenses/MIT) */';
80
81/*
82// Creates the dygraph-autoloader
83gulp.task('create-loader', function() {
84 // Create string ready for javascript array
85 var files = mergePaths(src.lib, src.main, src.plugins, src.devOptions, src.datahandlers)
86 .map(function(filename) {
87 // Make the path relative to dist file and add quotes
88 return "'" + filename.replace(src.base, '../../' + src.base) + "'";
89 })
90 .join(",");
91
92 return gulp.src(src.base + '../dygraph/dygraph-autoloader.js')
93 .pipe(plugins.replace(/\/\* REPLACEME \*\//, files))
94 .pipe(gulp.dest('dist/scratch'));
95});
96*/
97
98gulp.task('create-dev', function() {
99 var dest = 'dist';
100 return gulp.src(mergePaths(src.polyfills, src.main, src.plugins, src.devOptions, src.datahandlers), {base: '.'})
101 .pipe(plugins.sourcemaps.init({debug:true}))
102 .pipe(plugins.concat('dygraph-combined-dev.js'))
103 .pipe(plugins.header(copyright))
104 .pipe(plugins.sourcemaps.write('.')) // '.' = external sourcemap
105 .pipe(gulp.dest(dest));
106});
107
108gulp.task('concat', function() {
109 var dest = 'dist';
110 return gulp.src(mergePaths(src.polyfills, src.main, src.plugins, src.datahandlers), {base: '.'})
111 .pipe(plugins.sourcemaps.init())
112 .pipe(plugins.concat('scratch'))
113 .pipe(plugins.header(copyright))
114 .pipe(gulp.dest(dest))
115 .pipe(plugins.uglify({
116 compress: {
117 global_defs: { DEBUG: false }
118 },
119 warnings: false,
120 preserveComments: "none"
121 }))
122 .pipe(plugins.header(copyright))
123 .pipe(plugins.rename('dygraph-combined.js'))
124 .pipe(plugins.sourcemaps.write('.'))
125 .pipe(gulp.dest(dest));
126
127});
128
129gulp.task('gwt-dist', ['concat'], function() {
130 // Copy package structure to dist folder
131 gulp.src('gwt/**', {'base': '.'})
132 .pipe(gulp.dest('dist'));
133
134 gulp.src('dygraph-combined.js')
135 .pipe(gulp.dest('dist/gwt/org/danvk'));
136
137 // Generate jar
138 gulp.src('')
139 .pipe(plugins.shell([
140 'bash -c "jar -cf dist/dygraph-gwt.jar -C dist/gwt org"'
141 ]))
142});
143
144gulp.task('test', ['concat', 'create-dev'], function(done) {
145 karma.start({
146 configFile: process.cwd() + '/auto_tests/karma.conf.js',
147 singleRun: true
148 }, done);
149});
150
151gulp.task('coveralls', ['test'], plugins.shell.task([
152 './scripts/transform-coverage.js ' +
153 'dist/dygraph-combined-dev.js.map ' +
154 'dist/coverage/report-lcov/lcov.info ' +
155 '| ./node_modules/.bin/coveralls'
156]));
157
158gulp.task('watch', function() {
159 gulp.watch('src/**', ['concat']);
160});
161
162gulp.task('watch-test', function() {
163 gulp.watch(['src/**', 'auto_tests/tests/**'], ['test']);
164});
165
166gulp.task('dist', ['gwt-dist', 'concat', 'create-dev']);
167gulp.task('travis', ['test', 'coveralls']);
168gulp.task('default', ['test', 'dist']);