Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathgulpfile.js
More file actions
Latest commit
77 lines (65 loc) · 2.28 KB
/
Copy pathgulpfile.js
File metadata and controls
77 lines (65 loc) · 2.28 KB
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
constgulp=require('gulp');
constmocha=require('gulp-mocha');
constuglify=require('gulp-uglifyjs');
constconcat=require('gulp-concat');
constexit=require('gulp-exit');
constejsmin=require('gulp-ejsmin');
constbabel=require('gulp-babel');
constgutil=require('gulp-util');
constthrough=require('through2')
gulp.task('minify-ejs-pages',()=>{
// Save the pre tag contents
letpreLocs=[];
returngulp.src(['views/pages/*.ejs','views/pages/**/*.ejs'])
.pipe(through.obj((chunk,enc,cb)=>{
letcontents=chunk.contents.toString('utf8');
letpreMatches=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=newBuffer(contents,'utf8');
}
cb(null,chunk)
}))
.pipe(ejsmin())
.pipe(through.obj((chunk,enc,cb)=>{
letcontents=chunk.contents.toString('utf8');
letsearch=newRegExp(/PRE_MATCH_(\d+)/g);
letmatch=search.exec(contents);
while(match!=null){
contents=contents.replace('PRE_MATCH_'+match[1],preLocs[match[1]]);
match=search.exec(contents);
}
chunk.contents=newBuffer(contents,'utf8');
cb(null,chunk)
}))
.pipe(gulp.dest('.viewsMin/pages'))
});
gulp.task('minify-ejs-snippets',()=>{
returngulp.src('views/snippets/*.ejs')
.pipe(ejsmin())
.pipe(gulp.dest('.viewsMin/snippets'))
});
gulp.task('testEnv',()=>{
returnprocess.env.spec=true;
});
gulp.task('specnyan',['default','testEnv'],()=>{
returngulp.src('spec/randomapi.js',{read: false})
.pipe(mocha({require: ['mocha-clean'],reporter: 'nyan'}))
.pipe(exit());
});
gulp.task('spec',['default','testEnv'],()=>{
returngulp.src('spec/randomapi.js',{read: false})
.pipe(mocha({require: ['mocha-clean'],reporter: 'spec'}))
.pipe(exit());
});
gulp.task('es6toes5',()=>{
returngulp.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']);