forked from makepad/makepad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_index.js
31 lines (30 loc) · 947 Bytes
/
build_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
var fs = require('fs');
function readRecur(path, name){
var files = fs.readdirSync(path);
var ret = {name:name,open:false,folders:[], files:[]};
for(file of files){
let new_file = path + '/' + file
if (fs.statSync(new_file).isDirectory()) {
if( file == 'target') continue;
let sub = readRecur(new_file, file);
if(sub.folders.length > 0 || sub.files.length > 0){ // prune empty dirs
ret.folders.push(sub)
}
}
else{
if(!file.match(/\.rs/)) continue;
ret.files.push({name:file})
}
}
return ret
}
let tree = readRecur(".","");
tree.open = true;
tree.folders[0].open = true;
tree.folders[1].open = true;
tree.folders[1].folders[1].open = true;
var data_in = fs.readFileSync('./index.json');
var data_out = JSON.stringify(tree);
if(data_in != data_out){
fs.writeFileSync('./index.json', data_out);
}