UNPKG

@zapier/stubtree

Version:

CLI tool to generate ASCII tree of project structure with symbol stubs using universal-ctags

44 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatTag = formatTag; exports.renderTree = renderTree; function formatTag(tag) { let result = tag.name; if (tag.signature) { result += tag.signature; } else if (tag.kind === 'function' || tag.kind === 'method') { result += '()'; } if (tag.kind === 'class') { result += ':'; } return result; } function renderTree(node, writeLine, prefix = '', isLast = true) { const connector = isLast ? '└── ' : '├── '; const name = node.name === '.' ? node.name : node.name; if (prefix === '') { writeLine(name + '/'); } else { writeLine(prefix + connector + (node.type === 'directory' ? name + '/' : name)); } const extension = isLast ? ' ' : '│ '; const newPrefix = prefix + extension; if (node.tags && node.tags.length > 0) { node.tags.forEach((tag, index) => { const isLastTag = index === node.tags.length - 1 && (!node.children || node.children.length === 0); const tagConnector = isLastTag ? '└── ' : '├── '; const tagStr = formatTag(tag); writeLine(newPrefix + tagConnector + tagStr); }); } if (node.children) { node.children.forEach((child, index) => { const isLastChild = index === node.children.length - 1; renderTree(child, writeLine, newPrefix, isLastChild); }); } } //# sourceMappingURL=renderer.js.map