-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathlist.js
79 lines (60 loc) · 1.87 KB
/
list.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
var version = parseInt(process.argv[2] || '6');
if (!version)
version = 6;
const Fs = require('fs');
require('total4');
var templates = {};
var giturl = 'https://cdn.totaljs.com/flow/{1}.js';
var count = 0;
var countgroup = 0;
function parseValue(name, file) {
var index = file.indexOf('exports.' + name);
if (index > -1) {
index = file.indexOf('\'', index) || file.indexOf('"', index);
var i2 = file.indexOf('\';', index) || file.indexOf('"', index);
return file.substring(index + 1, i2);
}
return '';
}
U.ls('./', function callback(files,dirs) {
dirs.wait(function(dir, next){
if (dir.startsWith('.') || dir.startsWith('node_modules') || dir.startsWith('__flow'))
return next();
count++;
if (dir[dir.length - 1] === '/')
dir = dir.substring(0, dir.length - 1);
var filename = U.join(F.path.root(dir), dir + '.js');
var url = giturl.format('master', dir);
if (filename.indexOf('tutorial') !== -1) {
next();
return;
}
var file = Fs.readFileSync(filename, 'utf8');
var groupname = parseValue('group', file);
var ver = parseValue('version', file);
if (!ver) {
console.log('WARNING: "' + file + '" doesn\'t contain version.');
return next();
}
if (version >= 6)
url = { url: url, version: ver };
getGroup(groupname || 'Common').items.push(url);
next();
}, function(){
var arr = [];
Object.keys(templates).forEach(i => arr.push(templates[i]));
Fs.writeFileSync((version === 6 ? './list' : ('./templates' + version)) + '.json', JSON.stringify(arr, null, '\t'));
console.log('\nCount of components:' + count);
console.log('Count of groups:' + countgroup++);
console.log('Template file `templates' + version + '.json` created.');
});
});
function getGroup(group) {
if (!templates[group]){
countgroup++;
templates[group] = {};
templates[group].name = group;
templates[group].items = [];
}
return templates[group];
}