-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (51 loc) · 1.3 KB
/
index.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
'use strict';
// Modules:
var pkg = require('./package.json');
var path = require('path');
var gulpLess = require('gulp-less');
var gulpRename = require('gulp-rename');
// Locals:
var bus = null;
// Exports:
module.exports = {
less: gulpLess,
lessTask: lessTask,
register: register,
watch: true
};
function lessTask (options) {
options = config(options);
// Task:
return function () {
var gulp = this;
var dest = path.dirname(options.dest);
var filename = path.basename(options.dest);
function error (e) {
var error = e.message;
if (bus) {
bus.error.call(this, (options.gibTaskName || pkg.name), error);
} else {
console.log(error);
this.emit('end');
}
}
return gulp.src(options.src)
.pipe(gulpLess(options.less))
.on('error', error)
.pipe(gulpRename(filename))
.pipe(gulp.dest(dest))
.pipe(bus.refreshStream());
};
}
function config (options) {
// Defaults:
options = options || {};
options.dest = options.dest || './build/styles-bundle.css';
// Assertions:
if (!options.src) throw new Error('less-recipe `options.src` required');
if (!options.dest) throw new Error('less-recipe `options.dest` required');
return options;
}
function register (b) {
bus = b;
}