forked from verbose/verb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
143 lines (124 loc) · 3.01 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
'use strict';
var diff = require('diff');
var chalk = require('chalk');
var extend = require('extend-shallow');
var Template = require('template');
var Composer = require('composer');
var vfs = require('vinyl-fs');
var stack = require('./lib/stack');
var init = require('./lib/init');
/**
* Initialize `Verb`
*
* @param {Object} `context`
* @api private
*/
function Verb() {
Template.apply(this, arguments);
Composer.call(this, 'verb');
init(this);
}
extend(Verb.prototype, Composer.prototype);
Template.extend(Verb.prototype);
/**
* Set application defaults that may be overridden by the user.
* This is a temporary method and should not be used.
*
* @param {String} `key`
* @param {*} `value`
* @api private
*/
Verb.prototype.defaults = function(key/*, value*/) {
if (typeof key === 'object') {
arguments[0] = {defaults: arguments[0]};
} else {
arguments[0] = 'defaults.' + arguments[0];
}
this.option.apply(this, arguments);
return this;
};
/**
* Glob patterns or filepaths to source files.
*
* ```js
* verb.src('src/*.hbs', {layout: 'default'})
* ```
*
* @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
*/
Verb.prototype.src = function(glob, opts) {
return stack.src(this, glob, opts);
};
/**
* Specify a destination for processed files.
*
* ```js
* verb.dest('dist')
* ```
*
* @param {String|Function} `dest` File path or rename function.
* @param {Object} `options` Options and locals to pass to `dest` plugins
* @api public
*/
Verb.prototype.dest = function(dest, opts) {
return stack.dest(this, dest, opts);
};
/**
* Copy a `glob` of files to the specified `dest`.
*
* ```js
* verb.task('assets', function() {
* verb.copy('assets/**', 'dist');
* });
* ```
*
* @param {String|Array} `glob`
* @param {String|Function} `dest`
* @return {Stream} Stream, to continue processing if necessary.
* @api public
*/
Verb.prototype.copy = function(glob, dest, opts) {
return vfs.src(glob, opts).pipe(vfs.dest(dest, opts));
};
/**
* Display a visual representation of the difference between
* two objects or strings.
*
* ```js
* var doc = verb.views.docs['foo.md'];
* verb.render(doc, function(err, content) {
* verb.diff(doc.orig, content);
* });
* ```
*
* @param {Object|String} `a`
* @param {Object|String} `b`
* @param {String} `methodName` Optionally pass a [jsdiff] method name to use. The default is `diffJson`
* @api public
*/
Verb.prototype.diff = function(a, b, method) {
method = method || 'diffJson';
a = a || this.env;
b = b || this.cache.data;
diff[method](a, b).forEach(function (res) {
var color = chalk.gray;
if (res.added) {
color = chalk.green;
}
if (res.removed) {
color = chalk.red;
}
process.stderr.write(color(res.value));
});
console.log('\n');
};
/**
* Expose `verb.Verb`
*/
Verb.prototype.Verb = Verb;
/**
* Expose `verb`
*/
module.exports = new Verb();