-
Notifications
You must be signed in to change notification settings - Fork 0
/
getnodejspath.js
132 lines (114 loc) · 4.02 KB
/
getnodejspath.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
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
var Github = require('github-api'),
Config = require('./config.js'),
d3 = require('d3'),
fs = require('fs');
var github = new Github({
username: Config.username,
password: Config.password,
auth: Config.basic
});
var output = [];
var writeFinalData = function(data){
var finalData = d3.tsv.format(data);
fs.writeFile('output/output_orgs_repos_path.tsv', finalData, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
}
var dir = 'output/orgs_repos_trees/';
fs.readdir(dir,function(err,files){
if (err) throw err;
var count = 0;
//return
var total = files.length-1;
//var total = 5;
files.forEach(function(file,i){
fs.readFile(dir+file,'utf-8',function(err,data){
var repoData = JSON.parse(data);
var filesData = repoData.filter(function(d){
var filename = d.path.split('/'),
filename = filename[filename.length-1];
return d.type == 'blob' && filename == 'bower.json' || filename == 'package.json'
})
var user = file.split('_')[0],
reponame = file.split('_');
reponame.shift();
reponame = reponame.join('_').replace('.json','');
var filesDataTotal = filesData.length;
var filesDataCount = 0;
filesData.forEach(function(d){
var elm = {
user:user,
repo: reponame,
path: d.path
}
output.push(elm)
// console.log(user, reponame, d.path)
// var repo = github.getRepo(user, reponame)
// repo.read('master', d.path, function(err, data) {
//
// if(!err){
// var content;
// try {
// content = JSON.parse(data);
// } catch (e) {
// content = {};
// }
// //var content = JSON.parse(data);
//
// var dep = content.dependencies;
// if(dep){
// var filename = d.path.split('/'),
// filename = filename[filename.length-1];
// var depList = d3.entries(dep);
// depList.forEach(function(e){
// var elm = {
// user:user,
// repo: reponame,
// lib: e.key,
// ver: e.value,
// type: filename.replace('.json', '')
// }
// output.push(elm)
// filesDataCount++
// if(filesDataCount == filesDataTotal){
// count++
// console.log(count + '/' + total)
// if(count == total){
// writeFinalData(output);
// //break;
// }
// }
// })
// }else{
// filesDataCount++
// if(filesDataCount == filesDataTotal){
// count++
// console.log(count + '/' + total)
// if(count == total){
// writeFinalData(output);
// }
// }
// }
// }else{
// filesDataCount++
// if(filesDataCount == filesDataTotal){
// count++
// console.log(count + '/' + total)
// if(count == total){
// writeFinalData(output);
// }
// }
// }
//
// });
});
console.log(file, count++, total)
if(count == total){
writeFinalData(output);
}
});
});
});