3 var gulp
= require('gulp');
4 var sourcemaps
= require('gulp-sourcemaps');
5 var less
= require('gulp-less');
6 var Promise
= require('bluebird');
7 var _
= require('lodash');
9 var lessWatcher
= require('./less-watcher');
15 streamTransform: function(stream
) {
18 // Also see `LessWatcher` opts, `watchGlob`, `lessOptions`
21 module
.exports = function(entryPoints
, options
) {
22 var opts
= _
.extend({}, defaults
, options
);
24 var myLessWatcher
= lessWatcher(entryPoints
, opts
);
26 var buildStyles = function(entryPoints
) {
27 return new Promise(function(resolve
, reject
) {
28 // We use gulp here for easy building
31 .pipe(sourcemaps
.init())
32 .pipe(less(opts
.lessOptions
));
35 .streamTransform(stream
)
36 .pipe(sourcemaps
.write(opts
.sourceMapOptions
.dest
, opts
.sourceMapOptions
.options
))
37 .pipe(gulp
.dest(opts
.dest
))
38 .on('end', function() {
41 .on('error', function(err
) {
47 myLessWatcher
.affectedEmitter
.on('change', function(result
) {
48 console
.log('affected', result
);
49 buildStyles(result
).then(function() {
50 console
.log('building done');
55 build: function(force
) {
56 var getTargetEntryPointsPromise
= Promise
.resolve(entryPoints
);
58 getTargetEntryPointsPromise
= myLessWatcher
.getDirtyEntryPoints();
61 return getTargetEntryPointsPromise
62 .then(function(targetEntryPoints
) {
63 return buildStyles(targetEntryPoints
);
66 console
.log('building done');
69 startWatching
: myLessWatcher
.startWatching
.bind(myLessWatcher
),
70 stopWatching
: myLessWatcher
.stopWatching
.bind(myLessWatcher
)