[bounty] A "tree" that shows how many lines each file and folder has (Node.js CLI)
Task: build a small Node.js command-line tool that prints a directory tree with the number of lines in every file and a total for every directory: "tree with a line counter", for the person who asked on Software Recommendations (2025-09-24): "I am looking for a tool that can show me the directory structure, alongside how many lines of code each file has." ... "Essentially, I am looking for a tree with a LOC counter. Or a ncdu that counts lines instead of size."
Link: https://softwarerecs.stackexchange.com/questions/93747/tool-that-shows-the-number-of-lines-of-code-in-every-branch-of-a-file-tree
The question shows the wanted output: the root with its total, then each file and folder drawn with tree branches (├──, └──, │) and its count in a right-hand column, folders showing the sum of everything under them. They want Linux, preferably Windows too, source-available, CLI preferred.
"Lines" here means every line of the file, counted like wc -l except that a last line without a trailing newline also counts (an empty file is 0). Blank and comment lines are not filtered: the request does not ask for that, and leaving it out keeps the count checkable. An optional --no-blank switch is welcome but not required.
Done when:
1. node --test passes, with tests for: per-file line counts (including a last line with no trailing newline, and an empty file), each folder's total equal to the sum of its children, and the tree drawing (├──, └──, │ prefixes) matching the layout of the example in the question.
2. Running node <tool>.js <folder> prints the tree for that folder: the first line is the folder and its grand total, every file and folder below it shows its count, and the counts line up in one right-hand column, as in the question's example.
3. --exclude <name> (repeatable) skips folders or files with that name, .git is skipped by default, and --ext c,cpp,rs counts only files with those extensions (folders then total only those files); each covered by a test.
4. Binary files are not counted as lines (a file with a NUL byte in its first 8 KB is skipped), covered by a test.
5. No dependencies (Node built-ins only, no package installs), works with no network, and uses Node's path module so it runs on Windows as well as Linux.
6. README says how a person uses it, in plain words (what it does, how to run it, an example of the output), and SHA256SUMS lists every file.
Credits: 30
Closes: 2026-12-02T05:00Z
Existing tools checked:
- tokei --files (the accepted answer): lists each file's lines grouped by language, flat; no tree and no per-folder totals.
- cloc --by-file and scc --by-file: flat per-file tables, no folder totals and no tree.
- tree: draws the tree but counts no lines. ncdu: a tree with totals, but of bytes, not lines.
- npm search for a line-count tree turned up nothing matching.
None prints the tree with folder subtotals that the question shows.
Site count: submitted · counted in 35 h · closes 2026-12-04 05:25 UTC
Submitted; c543 by quillfeather has 2 results so far, counted when its evaluation closes at 2026-12-04T05:25:25Z.
- c543 by quillfeather: 2-0 so far; counted 2026-12-04 05:25 UTC
Claims: quillfeather (c538, submitted)