/
vinyl-fs.js
129 lines (112 loc) · 3.21 KB
/
vinyl-fs.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*!
* assemble <https://github.com/assemble/assemble>
*
* Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.
* Licensed under the MIT license.
*/
'use strict';
var es = require('event-stream');
var fs = require('vinyl-fs');
var _ = require('lodash');
var stack = require('../stack');
var utils = require('../utils');
module.exports = function (Assemble) {
/**
* Glob patterns or filepaths to source files.
*
* **Example**
*
* ```js
* assemble.task('site', function() {
* assemble.src('src/*.hbs', {layout: 'default'})
* assemble.dest('dist')
* });
* ```
*
* @param {String|Array|Function} `patterns` Glob patterns, file paths, or renaming function.
* @param {Object} `options` Options to pass to source plugins.
* @api public
*/
Assemble.prototype.src = function (glob, options) {
options = _.extend({}, this.options, options);
if(this.enabled('minimal config') || options.minimal) {
return fs.src(glob, options);
}
return es.pipe.apply(es, utils.arrayify([
fs.src(glob, options),
stack.src.call(this, glob, options)
]));
};
/**
* Specify a destination for processed files.
*
* **Example**
*
* ```js
* assemble.task('sitemap', function() {
* assemble.src('src/*.txt')
* assemble.dest('dist', {ext: '.xml'})
* });
* ```
* @param {String} `dest` Destination directory
* @param {Object} `options` Options to be passed to `dest` plugins.
* @api public
*/
Assemble.prototype.dest = function (dest, options) {
var opts = _.extend({}, options);
if (this.enabled('minimal config') || opts.minimal) {
return fs.dest(dest, opts);
}
return es.pipe.apply(es, utils.arrayify([
stack.dest.call(this, dest, opts),
fs.dest(dest, opts)
]));
};
/**
* Rerun the specified task when a file changes.
*
* ```js
* assemble.task('watch', function() {
* assemble.watch('docs/*.md', ['docs']);
* });
* ```
*
* @param {String|Array} `glob` Filepaths or glob patterns.
* @param {String} `options`
* @param {Function} `fn` Task(s) to watch.
* @return {String}
*/
Assemble.prototype.watch = function(glob, options, fn) {
if (typeof options === 'function' || Array.isArray(options)) {
fn = options;
options = null;
}
// Tasks to watch
if (Array.isArray(fn)) {
return fs.watch(glob, options, function() {
this.start.apply(this, fn);
}.bind(this));
}
return fs.watch(glob, options, fn);
};
/**
* Copy a `glob` of files to the specified `dest`.
*
* **Example**
*
* ```js
* assemble.task('copy-assets', function() {
* return assemble.copy('assets/**', 'dist/');
* });
* ```
*
* @param {String|Array} `filepath` Source file path and/or glob patterns.
* @param {String|Function} `dest` Destination folder or function for renaming.
* @param {Object} `options` Additional options
* @return {Stream} Stream to allow doing additional work.
*/
Assemble.prototype.copy = function(glob, dest, options) {
var opts = _.extend({ minimal: true }, options);
return this.src(glob, opts).pipe(this.dest(dest, opts));
};
};