MCPcopy Create free account
hub / github.com/anus-dev/ANUS / formatStructure

Function formatStructure

packages/core/src/utils/getFolderStructure.ts:225–285  ·  view source on GitHub ↗

* Reads the directory structure using BFS, respecting maxItems. * @param node The current node in the reduced structure. * @param indent The current indentation string. * @param isLast Sibling indicator. * @param builder Array to build the string lines.

(
  node: FullFolderInfo,
  currentIndent: string,
  isLastChildOfParent: boolean,
  isProcessingRootNode: boolean,
  builder: string[],
)

Source from the content-addressed store, hash-verified

223 * @param builder Array to build the string lines.
224 */
225function formatStructure(
226 node: FullFolderInfo,
227 currentIndent: string,
228 isLastChildOfParent: boolean,
229 isProcessingRootNode: boolean,
230 builder: string[],
231): void {
232 const connector = isLastChildOfParent ? '└───' : '├───';
233
234 // The root node of the structure (the one passed initially to getFolderStructure)
235 // is not printed with a connector line itself, only its name as a header.
236 // Its children are printed relative to that conceptual root.
237 // Ignored root nodes ARE printed with a connector.
238 if (!isProcessingRootNode || node.isIgnored) {
239 builder.push(
240 `${currentIndent}${connector}${node.name}${path.sep}${node.isIgnored ? TRUNCATION_INDICATOR : ''}`,
241 );
242 }
243
244 // Determine the indent for the children of *this* node.
245 // If *this* node was the root of the whole structure, its children start with no indent before their connectors.
246 // Otherwise, children's indent extends from the current node's indent.
247 const indentForChildren = isProcessingRootNode
248 ? ''
249 : currentIndent + (isLastChildOfParent ? ' ' : '│ ');
250
251 // Render files of the current node
252 const fileCount = node.files.length;
253 for (let i = 0; i < fileCount; i++) {
254 const isLastFileAmongSiblings =
255 i === fileCount - 1 &&
256 node.subFolders.length === 0 &&
257 !node.hasMoreSubfolders;
258 const fileConnector = isLastFileAmongSiblings ? '└───' : '├───';
259 builder.push(`${indentForChildren}${fileConnector}${node.files[i]}`);
260 }
261 if (node.hasMoreFiles) {
262 const isLastIndicatorAmongSiblings =
263 node.subFolders.length === 0 && !node.hasMoreSubfolders;
264 const fileConnector = isLastIndicatorAmongSiblings ? '└───' : '├───';
265 builder.push(`${indentForChildren}${fileConnector}${TRUNCATION_INDICATOR}`);
266 }
267
268 // Render subfolders of the current node
269 const subFolderCount = node.subFolders.length;
270 for (let i = 0; i < subFolderCount; i++) {
271 const isLastSubfolderAmongSiblings =
272 i === subFolderCount - 1 && !node.hasMoreSubfolders;
273 // Children are never the root node being processed initially.
274 formatStructure(
275 node.subFolders[i],
276 indentForChildren,
277 isLastSubfolderAmongSiblings,
278 false,
279 builder,
280 );
281 }
282 if (node.hasMoreSubfolders) {

Callers 1

getFolderStructureFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected