compose.js (731B)
1 // Test harness: build folder pages the way the browser does (app/static/fasttree.js), from the saved 2 // /api/tree and /api/shell responses. Usage: node tests/compose.js tree.json shell.json path1 path2 ... 3 // Prints {"<path>": "<html>"} as JSON (null for a folder the tree doesn't have). 4 const fs = require('node:fs'); 5 const { buildIndex, compose } = require('../app/static/fasttree.js'); 6 7 const [treeFile, shellFile, ...paths] = process.argv.slice(2); 8 const tree = JSON.parse(fs.readFileSync(treeFile, 'utf8')); 9 const shell = JSON.parse(fs.readFileSync(shellFile, 'utf8')); 10 const index = buildIndex(tree.files); 11 const out = {}; 12 for (const p of paths) out[p] = compose(shell, index, p); 13 process.stdout.write(JSON.stringify(out));