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
|
// Gulp and plugins
var
gulp = require('gulp'),
umd = require('gulp-umd'),
rimraf = require('gulp-rimraf'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
//sass = require('gulp-sass'), // for building css from scss
//minifycss = require('gulp-minify-css'), // for minifiing css
jshint = require('gulp-jshint'),
testem = require('gulp-testem'),
connect = require('gulp-connect'),
babel = require('gulp-babel');
// paths
var
src = './src/js/',
dist = './dist/',
jsFiles = [
'MG.js',
'misc/utility.js',
'common/register.js',
'common/hooks.js',
'common/data_graphic.js',
'common/bootstrap_tooltip_popover.js',
'common/chart_title.js',
'common/scales.js',
'common/y_axis.js',
'common/x_axis.js',
'common/scales.js',
'common/init.js',
'common/markers.js',
'common/rollover.js',
'common/zoom.js',
'common/brush.js',
'common/window_listeners.js',
'layout/bootstrap_dropdown.js',
'layout/button.js',
'charts/line.js',
'charts/histogram.js',
'charts/point.js',
'charts/bar.js',
'charts/table.js',
'charts/missing.js',
'misc/process.js',
'misc/smoothers.js',
'misc/formatters.js',
'misc/transitions.js',
'misc/markup.js',
'misc/error.js'
];
gulp.task('default', ['jshint', 'test', 'build:js']);
gulp.task('clean', function () {
return gulp.src([dist + 'metricsgraphics.js', dist + 'metricsgraphics.min.js'], {read: false})
.pipe(rimraf());
});
// build css files from scss
//gulp.task('build:css', ['clean'], function () {
// return gulp.src(scssFiles)
// .pipe(sass({includePaths: scssDependencies}))
// .pipe(minifycss())
// .pipe(gulp.dest(dist));
//});
// create 'metricsgraphics.js' and 'metricsgraphics.min.js' from source js
gulp.task('build:js', ['clean'], function () {
return gulp.src(jsFiles.map(path => src + path))
.pipe(concat({path: 'metricsgraphics.js'}))
.pipe(babel({
presets: ['env']
}))
.pipe(umd(
{
dependencies:function() {
return [{
name: 'd3',
amd: 'd3',
cjs: 'd3',
global: 'd3',
param: 'd3'
}];
},
exports: function() {
return "MG";
},
namespace: function() {
return "MG";
}
}
))
.pipe(gulp.dest(dist))
.pipe(rename('metricsgraphics.min.js'))
.pipe(uglify())
.pipe(gulp.dest(dist));
});
// Check source js files with jshint
gulp.task('jshint', function () {
return gulp.src(jsFiles.map(fname => `src/js/${fname}`))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
});
// Run test suite server (testem')
gulp.task('test', function() {
return gulp.src([''])
.pipe(testem({
configFile: 'testem.json'
}));
});
// Development server tasks
// NOTE: these paths will need changing when the SCSS source is ready
var roots = ['dist', 'examples', 'src', 'bower_components'],
watchables = roots.map(function(root) {
return root + '/**/*';
});
gulp.task('dev:watch', function() { return gulp.watch(watchables, ['jshint', 'dev:reload']); });
gulp.task('dev:reload', function() { return gulp.src(watchables).pipe(connect.reload()); });
gulp.task('serve', ['jshint', 'dev:serve', 'dev:watch']);
gulp.task('dev:serve', function() {
connect.server({
root: roots,
port: 4300,
livereload: true
});
});
|