forked from jpthethi/teakozi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
candidates.js
48 lines (40 loc) · 1.31 KB
/
candidates.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
var fs = require('fs');
var path = require('path');
var yaml = require('js-yaml');
const walkSync = (dir, filelist = []) => {
fs.readdirSync(dir).forEach(file => {
filelist = fs.statSync(path.join(dir, file)).isDirectory()
? walkSync(path.join(dir, file), filelist)
: filelist.concat(path.join(dir, file));
});
return filelist.filter(file=>{return file.indexOf(".yml")>0});
}
const filter_file = (dir, tags="") => {
tags = tags.toLowerCase()
var objTags = tags.split(",").map(t=>{return t.trim()})
var collect = { }
collect.godList = []
collect.matchList = []
var list = walkSync(dir);
list.forEach(f=>{
var file = {name:f,sync:true}
collect.godList.push(file)
var test_stream = fs.readFileSync(f, 'utf8');
var doc = yaml.safeLoad(test_stream);
if(doc.sync!=undefined) file.sync = doc.sync
if(tags=="") {
collect.matchList.push(file)
}
if(doc.tags!=undefined) {
doc.tags.split(",").forEach(tag=>{
tag=tag.trim().toLowerCase();
if(collect[tag]==undefined) {collect[tag]= [];}
collect[tag].push(file)
if(objTags.indexOf(tag)!=-1 && collect.matchList.indexOf(file)==-1) { collect.matchList.push(file) }
})
}
})
//console.debug(collect);
return collect.matchList
}
module.exports.file_list = filter_file