-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
63 lines (47 loc) · 1.44 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
/**
* API 出口
* @author ydr.me
* @create 2014-10-22 16:16
*/
'use strict';
var object = require('blear.utils.object');
var console = require('blear.node.console');
var path = require('blear.node.path');
var fse = require('fs-extra');
console.config({
level: process.env.CLOUDCOME_MAC === 'YES' ? ['log', 'error'] : ['log']
});
var requireParser = require('./src/parse/require');
var NODE_MODUELS = 'node_modules';
var parseRequire = exports.parseRequire = function (file, options) {
options = object.assign({
deep: true,
nodeModulesDirname: path.join(process.cwd(), NODE_MODUELS),
code: null
}, options);
options.code = options.code || fse.readFileSync(file, 'utf-8');
options.srcCoolieConfigNodeModulesDirname = options.nodeModulesDirname;
options.coolieConfigs = {};
options.async = false;
var requireList = requireParser(file, options);
if (!options.deep) {
return requireList;
}
var parsedMap = {};
var parsedList = [];
options.deep = false;
options.code = null;
function deep(fileList) {
fileList.forEach(function (fileItem) {
var file = fileItem.file;
if (parsedMap[fileItem.file]) {
return;
}
parsedList.push(fileItem);
parsedMap[fileItem.file] = true;
deep(parseRequire(file, options));
});
}
deep(requireList);
return parsedList;
};