forked from yaph/d3-geomap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
101 lines (87 loc) · 2.57 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
var gulp = require('gulp'),
babel = require('gulp-babel'),
concat = require('gulp-concat'),
connect = require('gulp-connect'),
sass = require('gulp-ruby-sass'),
uglify = require('gulp-uglify'),
zip = require('gulp-zip'),
del = require('del'),
pkg = require('./package.json');
var paths = {
scripts: [
'src/js/utils.js',
'src/js/colorbrewer.js',
'src/js/geomap.js',
'src/js/choropleth.js'
],
styles: ['src/**/*.sass'],
data: ['src/**/*.json'],
vendor: [
'node_modules/d3/d3.min.js',
'node_modules/d3-geo-projection/d3.geo.projection.min.js',
'node_modules/topojson/build/topojson.min.js'
]
};
// Bundle resources in dist so they can be downloaded.
gulp.task('bundle', function() {
gulp.src('LICENSE')
.pipe(gulp.dest('dist'));
gulp.src('node_modules/d3/LICENSE')
.pipe(gulp.dest('dist/vendor'));
var target = 'd3-geomap-' + pkg.version + '.zip';
gulp.src('dist/**/*', {base: 'dist'})
.pipe(zip(target))
.pipe(gulp.dest('bundle'));
});
gulp.task('clean', function() {
del(['dist']);
});
// Run dev server.
gulp.task('connect', function() {
connect.server({
root: __dirname,
port: 8000,
livereload: true
});
});
// Copy geo data.
gulp.task('data', function() {
gulp.src(paths.data)
.pipe(gulp.dest('dist'));
});
// Minify scripts and styles.
gulp.task('minify', ['babel'], function() {
gulp.src('dist/js/d3.geomap.js')
.pipe(uglify())
.pipe(concat('d3.geomap.min.js'))
.pipe(gulp.dest('dist/js'));
});
// Compile and concat scripts.
gulp.task('babel', function() {
return gulp.src(paths.scripts)
.pipe(babel())
.pipe(concat('d3.geomap.js'))
.pipe(gulp.dest('dist/js'));
});
// Compile and copy sass.
gulp.task('styles', function () {
return gulp.src(paths.styles)
.pipe(sass())
.pipe(concat('d3.geomap.css'))
.pipe(gulp.dest('dist/css'));
});
// Concatenate and copy vendor scripts.
gulp.task('vendor', function() {
return gulp.src(paths.vendor)
.pipe(concat('d3.geomap.dependencies.min.js'))
.pipe(gulp.dest('dist/vendor'));
});
// Rerun task when a file changes.
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['babel']);
gulp.watch(paths.styles, ['styles']);
});
// Build files needed for distribution.
gulp.task('dist', ['data', 'babel', 'styles', 'minify', 'vendor']);
// The default task (called when you run `gulp` from cli).
gulp.task('default', ['dist', 'connect', 'watch']);