-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
151 lines (130 loc) · 4.66 KB
/
index.js
File metadata and controls
151 lines (130 loc) · 4.66 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
var fs=require('fs');
var glob = require("glob");
var wavi = require('wavi');
var data=[];
adsf
var totLength = -1;
//swag
/*not in use yet
var jsonStructured = {name:"root"};
var buildJson = function(json,jsonObj){
var currobj = jsonObj[json.name] = {name:json.name,path:json.file};
if(json.require != null)
{
for(var i=0; i<json.require.length; i++) {
for(var j=0; j<data.length; j++) {
if(data[j].name == json.require[i]) {
buildJson(data[j], currobj);
}
}
}
}
};*/
var generateLinks = function(json,links,counter){
if(json.require != null)
{
for(var i=0; i<json.require.length; i++) {
for(var j=0; j<data.length; j++) {
if(data[j].name == json.require[i]) {
counter =counter+" "+i;
links.push({"source":json.id,"target":data[j].id,"relVar":"","type":"","id":counter});
data[j].rootParentId=json.id;
generateLinks(data[j], links,counter);
}
}
}
}
};
var buildArray = function(options,callback)
{
if(data.length == totLength) {
for(var i=0; i<data.length; i++)
{
var filename = data[i].file;
var html = data[i].html;
var matches = html.match(/require.*\)/g);
if(matches) {
for (var j = 0; j < matches.length; j++) {
matches[j] = matches[j].substr(0,matches[j].length-2);
matches[j] = matches[j].replace('"', "'");
var i1 = matches[j].indexOf("'");
var i2 = matches[j].lastIndexOf("'");
matches[j] = matches[j].substr(i1+1, matches[j].length);
}
}
data[i].name = filename.substr(filename.lastIndexOf("/") + 1, filename.length);
data[i].name = data[i].name.substr(0, data[i].name.indexOf('.jsx'));
delete data[i].html ;
data[i].require = matches;
}
if(callback) {
callback(data);
}
for(var i=0; i<data.length; i++) {
data[i].group = "js";
data[i].groupText = "JS";
data[i].rawName = data[i].name;
data[i].id = i;
var requires = data[i].require;
if (requires) {
for (var j = 0; j < requires.length; j++) {
if (requires[j].indexOf('.jsx') > -1) {
requires[j] = requires[j].substr(requires[j].lastIndexOf("/") + 1, requires[j].length);
requires[j] = requires[j].substr(0, requires[j].indexOf('.jsx'));
}
}
data[i].require = requires;
}
}
var graphJson = {};
var links = [];
for(var i=0; i<data.length; i++) {
// buildJson(data[i],jsonStructured);
generateLinks(data[i],links,i)
}
graphJson.nodes = data;
graphJson.links = links;
wavi.generateGraphFromJSON(options.format,graphJson,options.output,function(err){
});
/*fs.writeFile("./test/map.json", JSON.stringify(jsonStructured), function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});*/
}
};
exports.generateDoc = function(options,callback){
glob(options.components, options, function (err, files) {
totLength = files.length;
if(options.singleFiles)
{
totLength += options.singleFiles.length;
for(var i=0; i<options.singleFiles.length; i++){
var file = options.singleFiles[i];
fs.readFile(file, 'utf-8', function (err, html) {
if (err) throw err;
data.push({file,html});
buildArray(options,callback);
});
}
}
// files is an array of filenames.
// If the `nonull` option is set, and nothing
// was found, then files is ["**/*.js"]
// er is an error object or null.
/* var file = './frontend/main.jsx';
fs.readFile(file, 'utf-8', function (err, html) {
if (err) throw err;
data.push({file,html});
buildArray(callback);
});*/
files.forEach(function(file){
fs.readFile(file, 'utf-8', function (err, html) {
if (err) throw err;
data.push({file,html});
buildArray(options,callback);
});
});
});
};