This repository has been archived by the owner on Dec 31, 2017. It is now read-only.
forked from SitePen/js-doc-parse
-
Notifications
You must be signed in to change notification settings - Fork 7
/
parse.js
84 lines (72 loc) · 1.99 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*jshint node:true */
if (typeof process !== 'undefined' && typeof define === 'undefined') {
(function () {
var pathUtil = require('path');
global.dojoConfig = {
async: true,
deps: [ 'js-doc-parse/parse' ],
packages: [
{ name: 'dojo', location: pathUtil.join(__dirname, 'dojo') },
{ name: 'js-doc-parse', location: __dirname }
]
};
require('./dojo/dojo.js');
})();
}
else {
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…');
var packagePaths = (function () {
var paths = [],
packages = env.config.packages;
for (var k in packages) {
paths.push(packages[k]);
}
return paths;
})();
packagePaths.forEach(function processPath(parent, 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)));
}
}.bind(this, env.config.basePath));
console.status('Exporting results…');
env.exporters.forEach(function (exporter) {
exporter.run(exporter.config);
});
console.status('Done!');
});
});
}