#! /usr/bin/env runjs

var main = () => {
    var readmeTemplate = __.rfile.from('README_template.md').string();
    var tree = $$.shell().sh('tree -L 2').start()[0];
    var treeLines = [];
    var treeOrigLines = $STR(tree).split('\n');
    var ignoreFileList = ['LICENSE', 'README.md', 'README_template.md', 'build_readme.js'];
    for (var i = 0; i < treeOrigLines.length; i++) {
        var ln = treeOrigLines[i];
        var matches = false;
        ignoreFileList.forEach((f) => { if (ln.endsWith(f)) { matches = true; } });
        if (!matches) {
            treeLines.push(ln);
        }
    }
    __.rfile.from('README.md').write(readmeTemplate.replace('$$TREE_L2$$', treeLines.join('\n')));
};

main();

