-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
77 lines (65 loc) · 2.28 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
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const uglify = require('gulp-uglifyjs');
const concat = require('gulp-concat');
const exit = require('gulp-exit');
const ejsmin = require('gulp-ejsmin');
const babel = require('gulp-babel');
const gutil = require('gulp-util');
const through = require('through2')
gulp.task('minify-ejs-pages', () => {
// Save the pre tag contents
let preLocs = [];
return gulp.src(['views/pages/*.ejs', '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 = new Buffer(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 = new Buffer(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('testEnv', () => {
return process.env.spec = true;
});
gulp.task('specnyan', ['default', 'testEnv'], () => {
return gulp.src('spec/randomapi.js', {read: false})
.pipe(mocha({require: ['mocha-clean'], reporter: 'nyan'}))
.pipe(exit());
});
gulp.task('spec', ['default', 'testEnv'], () => {
return gulp.src('spec/randomapi.js', {read: false})
.pipe(mocha({require: ['mocha-clean'], reporter: 'spec'}))
.pipe(exit());
});
gulp.task('es6toes5', () => {
return gulp.src('src/js/*.js')
.pipe(babel({
presets: ["es2015-without-strict"]
}).on('error', () => process.exit(1)))
.pipe(gulp.dest('public/js'))
});
gulp.task('default', ['minify-ejs-pages', 'minify-ejs-snippets', 'es6toes5']);