-
Notifications
You must be signed in to change notification settings - Fork 24
/
parse.js
60 lines (51 loc) · 1.5 KB
/
parse.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
define([
'./lib/env',
'./lib/File',
'./lib/Module',
'./lib/node!fs',
'./lib/node!util',
'./lib/node!path',
'./lib/console',
'./lib/esprimaParser'
], function (env, File, Module, fs, util, pathUtil, console) {
env.ready(function(){
console.status('Processing scripts…');
// For some reason commandLineArgs is an array of arrays; flatten them all
[].concat.apply([], require.rawConfig.commandLineArgs.slice(2)).forEach(function processPath(parent, path) {
if (typeof path === 'number') {
path = '';
}
path = pathUtil.join(parent, path);
var stats;
try {
stats = fs.statSync(path);
}
catch (error) {
console.error(error);
return;
}
if (stats.isDirectory()) {
fs.readdirSync(path).sort().forEach(processPath.bind(this, path));
}
else if (stats.isFile() && /\.js$/.test(path)) {
// TODO: This whole thing revolves around Modules because that's what an AMD system uses, but we really
// ought to isolate modules to the AMD callHandler so this tool can be used as an even more general
// documentation parser.
// Skip excluded paths
if (env.config.excludePaths.some(function (exclude) {
return typeof exclude === 'string' ?
path.indexOf(exclude) === 0 :
exclude.test(path);
})) {
return;
}
Module.getByFile(new File(fs.realpathSync(path)));
}
});
console.status('Exporting results…');
env.exporters.forEach(function (exporter) {
exporter.run(exporter.config);
});
console.status('Done!');
});
});