-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
100 lines (87 loc) · 2.54 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*!
* base-fs <https://github.com/jonschlinkert/base-fs>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var utils = require('./utils');
/**
* Support using the plugin on `app` or a
* `collection` instance
*/
module.exports = function(config) {
return function plugin(app) {
if (!utils.isValid(app)) return;
/**
* Glob patterns or filepaths to source files.
*
* ```js
* app.src('src/*.hbs', {layout: 'default'});
* ```
* @name .src
* @param {String|Array} `glob` Glob patterns or file paths to source files.
* @param {Object} `options` Options or locals to merge into the context and/or pass to `src` plugins
* @api public
*/
this.define('src', function(patterns, options) {
var opts = utils.extend({ allowEmpty: true }, config, this.options, options);
return (this.stream = utils.vfs.src(patterns, opts));
});
/**
* Glob patterns or paths for symlinks.
*
* ```js
* app.symlink('src/**');
* ```
* @name .symlink
* @param {String|Array} `glob`
* @api public
*/
this.define('symlink', function() {
return utils.fs.symlink.apply(this, arguments);
});
/**
* Specify a destination for processed files.
*
* ```js
* app.dest('dist/');
* ```
* @name .dest
* @param {String|Function} `dest` File path or rename function.
* @param {Object} `options` Options and locals to pass to `dest` plugins
* @api public
*/
this.define('dest', function(dir, options) {
if (!dir) {
throw new TypeError('expected dest to be a string or function.');
}
var opts = utils.extend({}, config, this.options, options);
return utils.exhaust(utils.dest(dir, opts));
});
/**
* Copy files with the given glob `patterns` to the specified `dest`.
*
* ```js
* app.task('assets', function(cb) {
* app.copy('assets/**', 'dist/')
* .on('error', cb)
* .on('finish', cb)
* });
* ```
* @name .copy
* @param {String|Array} `patterns` Glob patterns of files to copy.
* @param {String|Function} `dest` Desination directory.
* @return {Stream} Stream, to continue processing if necessary.
* @api public
*/
this.define('copy', function(patterns, dest, options) {
return this.src(patterns, options)
.pipe(this.dest(dest, options));
});
// return plugin if the instance is `app`
if (this.isApp) {
return plugin;
}
};
};