-
Notifications
You must be signed in to change notification settings - Fork 13
/
gulpfile.js
130 lines (115 loc) · 3.93 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
var gulp = require('gulp');
var webserver = require('gulp-webserver');
var taskListing = require('gulp-task-listing');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var gutil = require('gulp-util');
var cssmin = require('gulp-cssmin');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var clean = require('gulp-clean');
var replace = require('gulp-replace');
var ghpages = require('gulp-gh-pages');
var git = require('gulp-git');
var bump = require('gulp-bump');
var tag = require('gulp-tag-version');
var version = require('./package.json').version;
// FIXME: hook this up https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md
gulp.task('clean', function () {
return gulp.src('./dist/gh-pages/*')
.pipe(clean());
});
gulp.task('build-css', function() {
var src = [
'./src/css/leaflet.css',
'./src/css/leaflet-tooltip.css',
'./src/css/nprogress.css',
'./src/css/progress.css',
'./src/css/main.css',
'./src/css/map.css',
'./src/css/info.css',
'./src/css/locate-control.css',
'./src/css/routes-list.css',
];
return gulp.src(src)
.pipe(cssmin())
.pipe(concat('bundle.css'))
.pipe(gulp.dest('./dist/gh-pages/css'));
});
gulp.task('uglify', ['browserify-app'], function() {
return gulp.src('./dist/gh-pages/js/bundle.js')
.pipe(sourcemaps.init())
.pipe(concat('./dist/gh-pages/js/bundle.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.'));
});
gulp.task('browserify-app', function() {
var bundler = browserify({
entries: ['./src/js/main.js'],
extensions: ['.js'],
debug: true,
});
var bundle = function() {
return bundler
.bundle()
.on('error', function(e) {
gutil.log(gutil.colors.red("shit broke", e.toString()));
this.emit('end');
})
.pipe(source('./dist/gh-pages/js/bundle.js'))
.pipe(gulp.dest('.'))
.on('end', function() {
gutil.log(gutil.colors.blue("shit finished"));
});
};
return bundle();
});
gulp.task('build-html', function() {
var html = gulp.src('./src/html/index.html')
.pipe(replace(/bundle.(css|js)/g, 'bundle.$1?v=' + version))
.pipe(gulp.dest('./dist/gh-pages/'));
});
gulp.task('build-data', function() {
gulp.src('./data/**.*')
.pipe(gulp.dest('./dist/gh-pages/data'));
});
gulp.task('build-img', function() {
gulp.src('./src/img/**.*')
.pipe(gulp.dest('./dist/gh-pages/img'));
});
gulp.task('_serve', function() {
return gulp.src('./dist/gh-pages/')
.pipe(webserver({
host: '0.0.0.0',
port: 1234,
})
);
});
gulp.task('cname', function() {
gulp.src('./CNAME')
.pipe(gulp.dest('./dist/gh-pages/'));
});
gulp.task('deploy-gh-pages', ['bump'], function() {
return gulp.src('./dist/gh-pages/**/*')
.pipe(ghpages({cacheDir: '/tmp/ghettorappid'}));
});
gulp.task('bump', function() {
return gulp.src('./package.json')
.pipe(bump({type: 'patch'}))
.pipe(gulp.dest('./'))
.pipe(git.commit('Update version for release :shit:'))
// .pipe(tag())
// .pipe(git.push('origin', 'master', {args: '--tags'}))
.on('error', gutil.log);
});
gulp.task('watch', function() {
gulp.watch('./src/js/**', ['browserify-app']);
gulp.watch('./src/css/**', ['build-css']);
gulp.watch('./src/html/**', ['build-html']);
});
gulp.task('serve', ['build-data', 'build-img', 'build-css', 'build-html', 'browserify-app', '_serve', 'watch']);
gulp.task('build', ['cname', 'build-data', 'build-img', 'build-css', 'build-html', 'browserify-app', 'uglify']);
gulp.task('deploy', ['deploy-gh-pages']);
gulp.task('default', taskListing);