-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
98 lines (85 loc) · 2.08 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
var gulp = require('gulp');
var cfg = {
destination: 'build'
};
// task tree
gulp.task(serve);
gulp.task(watch);
gulp.task(clean);
gulp.task(test);
gulp.task('build', gulp.parallel(buildHTML, buildStyles));
gulp.task('build:html', buildHTML);
gulp.task('build:styles', buildStyles);
gulp.task('default', gulp.series('build', gulp.parallel(watch, serve)));
// exit
process.on('exit', clean);
// ctrl+c event
process.on('SIGINT', clean);
// uncaught exceptions
process.on('uncaughtException', clean);
// cleanup after itself
function clean(done) {
var del = require('del');
del(cfg.destination).then(function () {
if (typeof done === 'function') done();
else process.exit();
});
}
// build html
function buildHTML() {
var jade = require('gulp-jade');
return gulp.src('./test/index.jade')
.pipe(jade())
.pipe(gulp.dest(cfg.destination));
}
// build styles
function buildStyles() {
var stylus = require('gulp-stylus');
var utilus = require('./');
var sourcemaps = require('gulp-sourcemaps');
return gulp.src('./test/index.styl')
.pipe(sourcemaps.init())
.pipe(stylus({use: utilus()}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(cfg.destination));
}
// watch for source file changes
function watch() {
gulp.watch('./test/*.jade', buildHTML);
gulp.watch([
'./utilus/*',
'./lib/*',
'./plugin/*',
'./test/*.styl'
], buildStyles);
}
// watch files for changes and reload
function serve() {
var browserSync = require('browser-sync');
browserSync({
server: {
baseDir: cfg.destination
},
ui: false,
online: false,
open: false,
minify: false
});
gulp.watch(['*'], {cwd: cfg.destination}).on('change', browserSync.reload);
}
// continuous compilation of a quick test file
function test() {
var fs = require('fs');
var stylus = require('gulp-stylus').stylus;
var utilus = require('./');
gulp.watch(['./test/test.styl', './utilus/*.styl'], compile);
compile();
function compile(done) {
stylus(fs.readFileSync('./test/test.styl').toString())
.render(function (err, css) {
if (err) console.error(err.message);
else console.log(css);
if (done) done();
});
}
}