-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (62 loc) · 1.63 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
62
63
64
65
66
67
68
69
70
71
72
73
74
var fs = require('fs');
var path = require('path');
var find = require('findit')
var _ = require('underscore');
var basePath = 'F:\/ui\/sc\/shortcuts';
var PATTERN = {
scname: /shortcuts\\(\w*)[\\]?/im,
jsdir: /shortcuts\\\w*\\js$/im,
jspath: /shortcuts\\?(\w*)?(\\js)?(\\\w*.js)?$/im,
plugin: /smsc\([\'\"]*(\w*)[\'\"]*/gim,
author: /\@author\s+(\w*)\s*/gim
};
var sc = {};
var finder = find(basePath);
finder.on('directory', function(dir, stat, stop) {
if (!PATTERN.jspath.test(dir)) {
stop();
}
});
finder.on('file', function(file, stat) {
if (path.extname(file) == '.js') {
var filename,
rawData,
match,
tempArr = [],
tempUnique = {};
if (PATTERN.scname.test(file)) {
filename = RegExp.$1;
}
rawData = fs.readFileSync(file).toString();
while ((match = PATTERN.plugin.exec(rawData)) !== null) {
if (RegExp.lastParen && !tempUnique[RegExp.lastParen]) {
tempUnique[RegExp.lastParen] = 1;
tempArr.push(RegExp.lastParen)
}
}
if (tempArr.length && filename) {//plugin
if (!sc[filename]) {
sc[filename] = {};
}
if (!sc[filename]['plugin']) {
sc[filename]['plugin'] = tempArr.slice(0);
} else {
sc[filename]['plugin'] = _.uniq(sc[filename]['plugin'].concat(tempArr.slice(0)));
}
if (PATTERN.author.test(rawData)) {//author
if (!sc[filename]['author']) {
sc[filename]['author'] = [];
}
sc[filename]['author'].push(RegExp.$1);
}
}
}
});
finder.on('end', function() {
var jsonData = JSON.stringify(sc);
// console.log(jsonData);
fs.writeFile('relations.json', jsonData, function(err) {
if (err) throw err;
console.log('It\'s saved!');
});
})