-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
100 lines (82 loc) · 2.31 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
'use strict';
var gulp = require('gulp'),
$$ = require('gulp-load-plugins')();
var runSequence = require('run-sequence'),
browserSync = require('browser-sync').create(),
exec = require('child_process').exec,
path = require('path');
var name = 'css-injector',
srcDir = './src/',
testDir = './test/',
buildDir = './build/';
// // // // // // // // // // // //
gulp.task('lint', lint);
gulp.task('test', test);
gulp.task('doc', doc);
gulp.task('enclose', enclose);
gulp.task('serve', browserSyncLaunchServer);
gulp.task('build', function(callback) {
clearBashScreen();
runSequence(
'lint',
'test',
'doc',
'enclose',
callback);
});
gulp.task('watch', function () {
gulp.watch([srcDir + '**', testDir + '**'], ['build'])
.on('change', function(event) {
browserSync.reload();
});
});
gulp.task('default', ['watch', 'build'], browserSyncLaunchServer);
// // // // // // // // // // // //
function lint() {
return gulp.src(srcDir + name + '.js')
.pipe($$.excludeGitignore())
.pipe($$.eslint())
.pipe($$.eslint.format())
.pipe($$.eslint.failAfterError());
}
function test(cb) {
return gulp.src(testDir + 'index.js')
.pipe($$.mocha({reporter: 'spec'}));
}
function doc(cb) {
exec(path.resolve('jsdoc.sh'), function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}
function enclose() {
return gulp.src(srcDir + 'index.js')
.pipe($$.replace(
'\'use strict\';',
'\'use strict\';\n\nwindow.cssInjector = (function(){'
))
.pipe($$.replace(
'module.exports = cssInjector;',
'return cssInjector;\n\n})();'
))
.pipe($$.rename(name + '.js'))
.pipe(gulp.dest(buildDir))
.pipe($$.uglify())
.pipe($$.rename(name + '.min.js'))
.pipe(gulp.dest(buildDir))
}
function browserSyncLaunchServer() {
browserSync.init({
server: {
// Serve up our build folder
baseDir: buildDir,
index: "demo.html"
},
port: 5004
});
}
function clearBashScreen() {
var ESC = '\x1B';
console.log(ESC + 'c'); // (VT-100 escape sequence)
}