-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·115 lines (102 loc) · 3.49 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
'use strict';
var gulp = require('gulp'),
gutil = require('gulp-util'),
debug = require('gulp-debug'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
jshintfileoutput = require('gulp-jshint-html-reporter'),
browserify = require('gulp-browserify'),
sass = require('gulp-sass'),
concatCss = require('gulp-concat-css'),
cleanCSS = require('gulp-clean-css'),
uglify = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps'),
gulpif = require('gulp-if'),
webserver = require('gulp-webserver'),
path = require('path'),
swPrecache = require('sw-precache'),
csv = require('csvtojson'),
jsonfile = require('jsonfile');
var src = './src',
dest = './public',
environment = 'production1',
CONFIG = require('./src/js/config');
gulp.task('csvtojson:bus', function () {
var busJSON = [];
csv()
.fromFile(src + '/data/dublin-bus-stops.csv')
.on('json', (busStop) => {
if (busStop.position.lat >= CONFIG.MAP_CONFIG.maxBounds[0][0] &&
busStop.position.lat <= CONFIG.MAP_CONFIG.maxBounds[1][0] &&
busStop.position.lng <= CONFIG.MAP_CONFIG.maxBounds[1][1] &&
busStop.position.lng >= CONFIG.MAP_CONFIG.maxBounds[0][1]) {
busJSON.push(busStop);
console.log(busStop);
}
})
.on('done', (error) => {
jsonfile.writeFile(dest + '/data/dublin-bus-stops.json', busJSON, function (err) {
console.error(err)
})
})
});
gulp.task('generate-service-worker', function(callback) {
swPrecache.write(path.join(dest, 'service-worker.js'), {
staticFileGlobs: [
dest + '/**/*.{js,html,json,css,png,jpg,gif,svg,eot,ttf,woff}'
],
stripPrefix: dest,
runtimeCaching: [{
urlPattern: /^https:\/\/mysterious-temple-97993.herokuapp\.com\/stations/,
handler: 'networkFirst'
}]
}, callback);
});
gulp.task('js:lint', function() {
return gulp.src(src + '/js/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('gulp-jshint-html-reporter', { filename: 'jshint-output.html' }));
});
gulp.task('js:build', function() {
return gulp.src(src + '/js/app.js')
.pipe(browserify())
.pipe(gulpif(environment === 'production', uglify()))
.on('error', function (err) {
gutil.log('Error!', err.message);
})
.pipe(gulp.dest(dest + '/js'));
});
gulp.task('html', function() {
});
gulp.task('scss:build', function () {
return gulp.src(src + '/scss/**/*.scss')
.pipe(debug())
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest(dest + '/css'));
});
gulp.task('css', function() {
gulp.src( src + '/css/app.css')
//.pipe(concatCss('app.css', { rebaseUrls: false }))
.pipe(gulpif(environment === 'production', cleanCSS()))
.pipe(gulp.dest(dest + '/css'));
});
gulp.task('watch', function() {
gulp.watch([src + '/js/**/*', dest + '/data/**/*'], ['generate-service-worker','js']);
gulp.watch(src + '/scss/**/*.scss', ['generate-service-worker','scss']);
gulp.watch(dest + '/*.html', ['generate-service-worker','html']);
});
gulp.task('webserver', ['generate-service-worker','html', 'scss', 'js'], function() {
gulp.src(dest)
.pipe(webserver({
livereload: true,
open: true
})
);
});
gulp.task('default', ['watch', 'webserver']);
gulp.task('build', ['generate-service-worker','html', 'scss', 'js']);
gulp.task('js', ['js:lint', 'js:build']);
gulp.task('scss', ['scss:build']);