-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (36 loc) · 935 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*!
* gulp-drafts <https://github.com/jonschlinkert/gulp-drafts>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var get = require('get-first');
var typeOf = require('kind-of');
var through = require('through2');
var mm = require('micromatch');
module.exports = function drafts(pattern, opts) {
opts = opts || {};
if (typeOf(pattern) === 'object') {
opts = pattern;
pattern = null;
}
opts = opts || {};
return through.obj(function (file, enc, cb) {
var isDraft = false;
if (pattern) {
if (typeof pattern === 'function') {
isDraft = pattern(file);
} else {
isDraft = mm(file.relative, pattern, opts).length > 0;
}
}
var drafts = ['draft', 'data.draft'].concat(opts.props || []);
if (isDraft || Boolean(get(file, drafts))) {
cb();
return;
}
this.push(file);
return cb();
});
};