tree-fs 0.1.7 → 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 (3) hide show
  1. package/README.md +28 -2
  2. package/bin/tree-fs.js +29 -13
  3. package/package.json +6 -3
package/README.md CHANGED
@@ -58,7 +58,22 @@ Generate structure from a text file saved in your repo.
58
58
  tree-fs structure.txt
59
59
  ```
60
60
 
61
- ### 3. Programmatic API (For Tool Builders)
61
+ ### 3. Unix Piping (Stdin)
62
+
63
+ You can pipe tree content directly into `tree-fs`. Perfect for automation or clipboard tools.
64
+
65
+ ```bash
66
+ # Pipe from a file
67
+ cat structure.txt | tree-fs
68
+
69
+ # Pipe from clipboard (macOS)
70
+ pbpaste | tree-fs
71
+
72
+ # Echo directly
73
+ echo "src/\n index.js" | tree-fs
74
+ ```
75
+
76
+ ### 4. Programmatic API (For Tool Builders)
62
77
 
63
78
  Embed `tree-fs` into your own CLIs, generators, or scripts.
64
79
 
@@ -161,6 +176,17 @@ my-project
161
176
 
162
177
  **Note:** Internal emojis (logo_🔥.png) and filenames with parentheses (image(1).png) are preserved. We only strip "detached" decorations separated by spaces.
163
178
 
179
+ ## 🤖 The AI Workflow
180
+
181
+ To get the perfect output from ChatGPT, Claude, or DeepSeek, add this to your system prompt or custom instructions:
182
+
183
+ > "When asked to generate project directory structures, output them as a plain text tree diagram. Do not use code blocks for creation commands."
184
+
185
+ Then simply copy the output and run:
186
+ ```bash
187
+ npx tree-fs
188
+ ```
189
+
164
190
  ## 📦 CI/CD Integration
165
191
 
166
192
  You can use `tree-fs` to scaffold environments in GitHub Actions or pipelines.
@@ -177,4 +203,4 @@ tree-fs structure.txt --dry-run
177
203
 
178
204
  ## License
179
205
 
180
- MIT
206
+ MIT
package/bin/tree-fs.js CHANGED
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const fs = require("fs")
4
- const path = require("path")
5
4
  const readline = require("readline")
6
5
  const { parseTree, generateFS } = require("../src")
7
6
  const pkg = require("../package.json")
8
7
 
9
8
  const args = process.argv.slice(2)
10
9
 
11
- // Standard Flags
10
+ // --- Flag Handling ---
12
11
  if (args.includes("--version") || args.includes("-v")) {
13
12
  console.log(pkg.version)
14
13
  process.exit(0)
@@ -21,8 +20,8 @@ if (args.includes("--help") || args.includes("-h")) {
21
20
  Generate a real file system from a text-based directory tree.
22
21
 
23
22
  Arguments:
24
- file Text file containing the tree (optional)
25
- If ignored, tree-fs runs in interactive mode.
23
+ file Text file containing the tree.
24
+ If ignored, reads from STDIN or Interactive Mode.
26
25
 
27
26
  Options:
28
27
  -h, --help Show this help message
@@ -31,14 +30,30 @@ if (args.includes("--help") || args.includes("-h")) {
31
30
 
32
31
  Examples:
33
32
  npx tree-fs # Interactive mode
34
- npx tree-fs structure.txt # Generate from file
35
- npx tree-fs doc.md --dry-run # Preview changes
33
+ npx tree-fs structure.txt # From file
34
+ cat tree.txt | npx tree-fs # From pipe
36
35
  `)
37
36
  process.exit(0)
38
37
  }
39
38
 
40
39
  const dryRun = args.includes("--dry-run")
41
40
 
41
+ // --- Helper: Read from Piped Stdin (Non-Interactive) ---
42
+ async function readPipedInput() {
43
+ const rl = readline.createInterface({
44
+ input: process.stdin,
45
+ output: process.stdout,
46
+ terminal: false
47
+ })
48
+
49
+ const lines = []
50
+ for await (const line of rl) {
51
+ lines.push(line)
52
+ }
53
+ return lines.join("\n")
54
+ }
55
+
56
+ // --- Helper: Read from Interactive Prompt ---
42
57
  async function readInteractiveInput() {
43
58
  console.log("Paste directory tree. Press Enter on an empty line to finish.\n")
44
59
 
@@ -49,7 +64,6 @@ async function readInteractiveInput() {
49
64
  })
50
65
 
51
66
  const lines = []
52
-
53
67
  for await (const line of rl) {
54
68
  if (line.trim() === "") {
55
69
  rl.close()
@@ -57,26 +71,27 @@ async function readInteractiveInput() {
57
71
  }
58
72
  lines.push(line)
59
73
  }
60
-
61
74
  return lines.join("\n")
62
75
  }
63
76
 
64
77
  async function main() {
65
78
  let input = ""
66
-
67
- // 1. Check for file input (Any arg that isn't a flag)
68
79
  const fileArg = args.find(arg => !arg.startsWith("-"))
69
80
 
81
+ // 1. File Argument Provided
70
82
  if (fileArg) {
71
83
  try {
72
84
  input = fs.readFileSync(fileArg, "utf8")
73
85
  } catch (err) {
74
86
  console.error(`Error reading file: ${fileArg}`)
75
- console.error(err.message)
76
87
  process.exit(1)
77
88
  }
78
89
  }
79
- // 2. Interactive Mode
90
+ // 2. Piped Input (Unix Style)
91
+ else if (!process.stdin.isTTY) {
92
+ input = await readPipedInput()
93
+ }
94
+ // 3. Interactive Mode (Human)
80
95
  else {
81
96
  input = await readInteractiveInput()
82
97
  }
@@ -90,9 +105,10 @@ async function main() {
90
105
  const tree = parseTree(input)
91
106
  generateFS(tree, process.cwd(), { dryRun })
92
107
 
108
+ // Minimal feedback for pipes/dry-run, success message for humans
93
109
  if (dryRun) {
94
110
  console.log("Dry run complete. No files written.")
95
- } else {
111
+ } else if (process.stdin.isTTY) {
96
112
  console.log("✅ Structure created successfully.")
97
113
  }
98
114
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-fs",
3
- "version": "0.1.7",
3
+ "version": "1.0.0",
4
4
  "description": "Generate file system structures from text-based directory trees. The standard receiver for AI-generated project scaffolding.",
5
5
  "bin": {
6
6
  "tree-fs": "bin/tree-fs.js"
@@ -17,7 +17,7 @@
17
17
  "test": "echo \"Error: no test specified\" && exit 0",
18
18
  "start": "node bin/tree-fs.js"
19
19
  },
20
- "keywords": [
20
+ "keywords": [
21
21
  "filesystem",
22
22
  "scaffold",
23
23
  "tree",
@@ -26,7 +26,10 @@
26
26
  "llm",
27
27
  "ai",
28
28
  "automation",
29
- "cli"
29
+ "cli",
30
+ "fs",
31
+ "mkdir",
32
+ "unix"
30
33
  ],
31
34
  "engines": {
32
35
  "node": ">=14.0.0"