forked from RandomAPI/Randomuser.me-Node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
86 lines (72 loc) · 2.58 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
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const terser = require('gulp-terser');
const concat = require('gulp-concat');
const minifyCss = require('gulp-cssnano');
const ejsmin = require('gulp-ejsmin');
const through = require('through2')
gulp.task('testEnv', (done) => {
process.env.spec = true;
done();
});
gulp.task('default', gulp.series('testEnv', test = (done) => {
gulp.src('spec/index.js', {read: false})
.pipe(mocha({require: ['mocha-clean'], reporter: 'nyan', exit: true}))
done();
}));
gulp.task('spec', gulp.series('testEnv', test = (done) => {
gulp.src('spec/index.js', {read: false})
.pipe(mocha({require: ['mocha-clean'], reporter: 'spec', exit: true}))
done();
}));
gulp.task('compress', () => {
return gulp.src(['public/js/ready.min.js', 'public/js/pegasus.min.js', '!public/js/highcharts.js', 'public/js/*.js'])
.pipe(concat('all.js'))
.pipe(terser())
.pipe(gulp.dest('public/dist/'));
});
gulp.task('css', () => {
return gulp.src('public/css/*.css')
.pipe(concat('style.css'))
.pipe(minifyCss({compatibility: 'ie8'}))
.pipe(gulp.dest('public/dist/'));
});
gulp.task('minify-ejs-pages', () => {
// Save the pre tag contents
let preLocs = [];
return gulp.src('views/pages/*.ejs')
.pipe(through.obj((chunk, enc, cb) => {
let contents = chunk.contents.toString('utf8');
let preMatches = contents.match(/<pre>((?:.|\n)*?)<\/pre>/g);
if (preMatches) {
preMatches.forEach(match => {
preLocs.push(match);
contents = contents.replace(match, 'PRE_MATCH_' + (preLocs.length-1));
});
chunk.contents = Buffer.from(contents, 'utf8');
}
cb(null, chunk)
}))
.pipe(ejsmin())
.pipe(through.obj((chunk, enc, cb) => {
let contents = chunk.contents.toString('utf8');
let search = new RegExp(/PRE_MATCH_(\d+)/g);
let match = search.exec(contents);
while (match != null) {
contents = contents.replace('PRE_MATCH_' + match[1], preLocs[match[1]]);
match = search.exec(contents);
}
chunk.contents = Buffer.from(contents, 'utf8');
cb(null, chunk)
}))
.pipe(gulp.dest('.viewsMin/pages'))
});
gulp.task('minify-ejs-snippets', () => {
return gulp.src('views/snippets/*.ejs')
.pipe(ejsmin())
.pipe(gulp.dest('.viewsMin/snippets'))
});
gulp.task('build', gulp.series(['compress', 'css', 'minify-ejs-pages', 'minify-ejs-snippets']));
gulp.task('start', gulp.series(['compress', 'css', 'minify-ejs-pages', 'minify-ejs-snippets'], () => {
require('./server');
}));