-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
29 lines (26 loc) · 945 Bytes
/
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
'use strict';
const _ = require('lodash');
const path = require('path');
const through = require('through2');
const isLess = require('./lib/isLess');
const logger = require('./lib/logger');
const fetchDeps = require('./lib/fetchDeps');
const PluginError = require('gulp-util').PluginError;
const defaultOpts = {
useLocal: true,
base: path.join(process.cwd(), 'remote'),
timeout: 5000,
debug: false
};
module.exports = config => {
config = _.defaults(config || {}, defaultOpts);
return through.obj((file, encoding, callback) => {
if (file.isNull()) return callback(null, file);
if (file.isStream()) return callback(new PluginError('gulp-remote-less', `Stream is not supported`));
if (config.debug) logger.setDebug(true);
if (!isLess(file)) return callback(null, file);
fetchDeps(file, config)
.then(() => callback(null, file))
.catch(e => callback(new PluginError('gulp-remote-less', e)));
});
};