-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (36 loc) · 1.07 KB
/
Copy pathindex.js
File metadata and controls
44 lines (36 loc) · 1.07 KB
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
'use strict';
var fs = require('fs');
var path = require('path');
var Vinyl = require('vinyl');
var extend = require('extend-shallow');
var glob = require('matched');
module.exports = function(patterns, options) {
options = options || {};
var ctx = this || {};
var opts = extend({}, ctx.options, options, options.hash);
var data = extend({}, ctx.context, ctx);
var app = ctx.app || {};
opts.cwd = path.resolve(opts.cwd || app.cwd || process.cwd());
var File = app.View || Vinyl;
var list = [];
var dest = data.dest;
if (typeof dest === 'undefined') {
dest = opts.dest;
}
if (typeof dest !== 'string') {
throw new Error('expected "dest" path to be defined on data');
}
var files = glob.sync(patterns, opts);
dest = path.resolve(dest);
for (var i = 0; i < files.length; i++) {
var fp = path.resolve(opts.cwd, files[i]);
var file = new File({path: fp});
if (!file.stat) file.stat = fs.lstatSync(file.path);
file.options = {};
file.data = {};
file.base = dest;
file.cwd = dest;
list.push(file);
}
return list;
};