-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (37 loc) · 1.06 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
'use strict';
var acquire = require('acquire'),
mapKeys = require('map-keys'),
camelCase = require('camel-case');
var fs = require('fs'),
path = require('path'),
EventEmitter = require('events').EventEmitter;
module.exports = function (repl, dir, opts) {
opts = opts || {};
var ee = new EventEmitter;
process.nextTick(function () {
var modules = acquire.resolve({ basedir: dir,
ignore: opts.ignore,
skipFailures: ee.emit.bind(ee, 'fail') });
if (opts.loadMain) {
try {
var name = path.basename(dir);
modules[name] = require.resolve(dir);
}
catch (e) {
ee.emit('fail', name, dir);
}
}
modules = mapKeys(modules, camelCase);
Object.keys(modules).forEach(function (name) {
try {
repl.context[name] = require(modules[name]);
ee.emit('load', name, modules[name]);
}
catch (e) {
ee.emit('fail', name, modules[name]);
}
});
ee.emit('end');
});
return ee;
};