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