@extenv/saw-it 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +56 -0
  2. package/package.json +18 -0
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // index.ts
5
+ import { readdirSync, statSync, mkdirSync, writeFileSync } from "fs";
6
+ import { join, dirname } from "path";
7
+ function generateTree(dir, prefix = "", lines = []) {
8
+ const items = readdirSync(dir);
9
+ items.forEach((item, index) => {
10
+ const fullPath = join(dir, item);
11
+ const isLast = index === items.length - 1;
12
+ const stats = statSync(fullPath);
13
+ const connector = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
14
+ const line = prefix + connector + item;
15
+ lines.push(line);
16
+ if (stats.isDirectory()) {
17
+ const newPrefix = prefix + (isLast ? " " : "\u2502 ");
18
+ generateTree(fullPath, newPrefix, lines);
19
+ }
20
+ });
21
+ return lines;
22
+ }
23
+ function showHelp() {
24
+ console.log(`
25
+ saw-it - Folder Tree Viewer
26
+
27
+ Usage:
28
+ saw-it <folder>
29
+
30
+ Examples:
31
+ saw-it src
32
+ saw-it src > tree.txt
33
+ saw-it src > folder/tree.txt
34
+ `);
35
+ }
36
+ var args = process.argv.slice(2);
37
+ var folder = args[0];
38
+ if (!folder || folder === "-h" || folder === "--help") {
39
+ showHelp();
40
+ process.exit(0);
41
+ }
42
+ var lines = [];
43
+ lines.push(folder + "/");
44
+ generateTree(folder, "", lines);
45
+ var output = lines.join(`
46
+ `);
47
+ if (process.stdout.isTTY) {
48
+ console.log(output);
49
+ } else {
50
+ const outputPath = process.stdout.path;
51
+ if (outputPath) {
52
+ const dir = dirname(outputPath);
53
+ mkdirSync(dir, { recursive: true });
54
+ writeFileSync(outputPath, output);
55
+ }
56
+ }
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@extenv/saw-it",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight CLI tool to display folder structures in a tree format",
5
+ "type": "module",
6
+ "public": true,
7
+ "bin": {
8
+ "saw-it": "./dist/index.js"
9
+ },
10
+ "keywords": [
11
+ "cli",
12
+ "tree",
13
+ "folder",
14
+ "filesystem"
15
+ ],
16
+ "author": "Extenv",
17
+ "license": "MIT"
18
+ }