constatic
Version:
Constatic is a CLI for creating and managing modern TypeScript projects, providing an organized structure and features that streamline development.
3 lines (2 loc) • 723 B
JavaScript
import d from"chalk";function g(t){const e=[];for(const n of t){const r=n.split("/");let o=e;for(const c of r){let i=o.find(s=>s.name===c);i||(i={name:c,children:[]},o.push(i)),o=i.children}}return e}function l(t,e=""){let n="";return t.forEach((r,o)=>{const c=o===t.length-1,i=c?"\u2514\u2500 ":"\u251C\u2500 ",s=r.children&&r.children.length>0,f=s?`${r.name}/`:d.yellowBright(r.name);if(n+=`${e}${i}${f}
`,s){const a=e+(c?" ":"\u2502 ");n+=l(r.children,a)}}),n}function u(t){const e=g(t);return l(e)}function m(t,e){console.log(t);const n=Object.entries(e);n.forEach(([r,o],c)=>{const i=c===n.length-1?"\u2514\u2500":"\u251C\u2500";console.log(`${i} ${r}@${o}`)})}export{u as buildAndFormatTree,m as printRecordTree};