-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (57 loc) · 1.79 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
/*!
* base-resolver <https://github.com/jonschlinkert/base-resolver>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var fs = require('fs');
var path = require('path');
var utils = require('./utils');
module.exports = function(moduleName) {
if (typeof moduleName !== 'string') {
throw new TypeError('expected "moduleName" to be a string');
}
return function(app) {
var Resolver = utils.Resolver;
var opts = utils.extend({ module: moduleName }, this.options);
/**
* Initialize resolver defaults
*/
this.define('resolver', new Resolver(opts));
/**
* Forward `config` events from `resovler`
*/
this.resolver.on('config', this.emit.bind(this, 'config'));
/**
* Passes the given glob pattern(s) to [matched][] and emits a
* `config` object for each matching file.
*
* ```js
* resolver.on('config', function(config) {
* // do stuff with "config"
* });
*
* resolver
* .resolve('foo', {pattern: 'generator.js', cwd: 'foo'})
* .resolve('bar', {pattern: 'generator.js', cwd: 'bar'})
* .resolve('baz', {pattern: 'generator.js', cwd: 'baz'})
* ```
* @param {String} `name` Optionally specify a namespace for storing resolved configs.
* @param {Object} `options` Options to pass to [matched][]
* @param {String|Array} `option.patterns` Glob patterns to search
* @param {String} `option.cwd` The starting directory to search from
* @return {Object}
* @api public
*/
app.define('resolve', this.resolver.resolve.bind(this.resolver));
/**
* Add the `Resolver` ctor to the instance
*/
app.define('Resolver', Resolver);
};
};
/**
* Expose `Resolver`
*/
module.exports.Resolver = utils.Resolver;