-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathrecurse.js
42 lines (37 loc) · 1.01 KB
/
recurse.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
import { is } from './utils'
import path from 'path'
import through from 'through2'
import vfs from 'vinyl-fs'
/**
* Return a transform stream recursing through directory to yield
* Sass/SCSS files instead.
*
* @return {Object}
*/
export default function recurse () {
return through.obj(function (file, enc, cb) {
if (!is.vinylFile(file)) {
// Don't know how to handle this object.
return cb(new Error('Unsupported stream object. Vinyl file expected.'))
}
if (file.isBuffer() || file.isStream()) {
// Pass-through.
return cb(null, file)
}
if (!file.isDirectory()) {
// At that stage we want only dirs. Dismiss file.isNull.
return cb()
}
// It's a directory, find inner Sass/SCSS files.
let pattern = path.resolve(file.path, '**/*.+(sass|scss)')
vfs.src(pattern)
.pipe(through.obj((file, enc, cb) => {
// Append to "parent" stream.
this.push(file)
cb()
}, () => {
// All done.
cb()
}))
})
}