forked from arbylee/Chicago-Crash-Browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
100 lines (84 loc) · 2.81 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
'use strict';
let gulp = require('gulp'),
del = require('del'),
sourcemaps = require('gulp-sourcemaps'),
concatCss = require('gulp-concat-css'),
webpack = require('webpack-stream'),
rsync = require('rsync-slim'),
secrets = require('./secrets.json'),
connect = require('gulp-connect'),
replace = require('gulp-replace');
const outputFolder = 'dist';
gulp.task('css', () => {
return gulp.src([
'node_modules/leaflet/dist/leaflet.css',
'node_modules/leaflet.markercluster/dist/MarkerCluster.css',
'node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css',
'node_modules/leaflet-draw/dist/leaflet.draw.css',
'node_modules/select2/dist/css/select2.min.css',
'stylesheets/index.css']
)
.pipe(concatCss('bundle.css', {
rebaseUrls: false
}))
.pipe(gulp.dest(outputFolder));
});
gulp.task('images', ['clean'], function () {
return gulp.src(['node_modules/leaflet-draw/dist/images/*', 'images/**/*'])
.pipe(gulp.dest(outputFolder + '/images'));
});
gulp.task('default', ['clean', 'css', 'images'], () => {
gulp.src('api/**/*')
.pipe(gulp.dest(outputFolder + '/api'));
gulp.src(['node_modules/leaflet-draw/dist/images/spritesheet-2x.png'])
.pipe(gulp.dest(outputFolder))
gulp.src(['index.html',
'api.php',
'staticmap.php',
'favicon.ico',
'config.php',
'functions.php',
'map.php'
])
.pipe(gulp.dest(outputFolder));
return gulp.src('js/crashbrowser.js')
.pipe(webpack( require('./webpack.config.js') ))
.pipe(gulp.dest(outputFolder));
});
gulp.task('clean', () => {
return del([outputFolder]).then(paths => {
console.log('Deleted files and folders:\n', paths.join('\n'));
});
});
gulp.task('watch', () => {
gulp.watch(['js/**/*.js', 'stylesheets/index.css', 'index.html'], ['default'])
});
gulp.task('serve', ['clean', 'default', 'watch'], () => {
gulp.src([outputFolder + '/bundle.js'])
.pipe(replace('@@API_HOST', 'http://www.chicagocrashes.org'))
.pipe(gulp.dest(outputFolder, {overwrite: true}));
connect.server({root: 'dist'});
});
gulp.task('replaceProd', ['default'], () => {
return gulp.src([outputFolder + '/bundle.js'])
.pipe(replace('@@API_HOST', ''))
.pipe(gulp.dest(outputFolder, {overwrite: true}));
})
gulp.task('deploy', ['default', 'replaceProd'], () => {
rsync({
src: outputFolder + '/',
dest: secrets.username + '@' + secrets.hostname + ':/var/www/chicagocrashes/htdocs',
options: '-rvhcz --delete --progress'
}, function (err) {
console.error(err);
});
});
gulp.task('deploy-beta', ['default', 'replaceProd'], () => {
rsync({
src: outputFolder + '/',
dest: secrets.username + '@' + secrets.hostname + ':/var/www/chicagocrashes/htdocs/beta',
options: '-rvhcz --delete --progress'
}, err => {
console.error(err);
});
});