tree-fs 0.1.5 → 0.1.6
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.
- package/bin/tree-fs.js +43 -9
- package/package.json +1 -1
package/bin/tree-fs.js
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const fs = require("fs")
|
|
4
|
+
const path = require("path")
|
|
4
5
|
const readline = require("readline")
|
|
5
6
|
const { parseTree, generateFS } = require("../src")
|
|
7
|
+
const pkg = require("../package.json")
|
|
6
8
|
|
|
7
9
|
const args = process.argv.slice(2)
|
|
10
|
+
|
|
11
|
+
// Standard Flags
|
|
12
|
+
if (args.includes("--version") || args.includes("-v")) {
|
|
13
|
+
console.log(pkg.version)
|
|
14
|
+
process.exit(0)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
18
|
+
console.log(`
|
|
19
|
+
Usage: tree-fs [file] [options]
|
|
20
|
+
|
|
21
|
+
Generate a real file system from a text-based directory tree.
|
|
22
|
+
|
|
23
|
+
Arguments:
|
|
24
|
+
file Text file containing the tree (optional)
|
|
25
|
+
If ignored, tree-fs runs in interactive mode.
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
-h, --help Show this help message
|
|
29
|
+
-v, --version Show version number
|
|
30
|
+
--dry-run Simulate execution without writing files
|
|
31
|
+
|
|
32
|
+
Examples:
|
|
33
|
+
npx tree-fs # Interactive mode
|
|
34
|
+
npx tree-fs structure.txt # Generate from file
|
|
35
|
+
npx tree-fs doc.md --dry-run # Preview changes
|
|
36
|
+
`)
|
|
37
|
+
process.exit(0)
|
|
38
|
+
}
|
|
39
|
+
|
|
8
40
|
const dryRun = args.includes("--dry-run")
|
|
9
41
|
|
|
10
42
|
async function readInteractiveInput() {
|
|
@@ -13,13 +45,12 @@ async function readInteractiveInput() {
|
|
|
13
45
|
const rl = readline.createInterface({
|
|
14
46
|
input: process.stdin,
|
|
15
47
|
output: process.stdout,
|
|
16
|
-
terminal: false
|
|
48
|
+
terminal: false
|
|
17
49
|
})
|
|
18
50
|
|
|
19
51
|
const lines = []
|
|
20
52
|
|
|
21
53
|
for await (const line of rl) {
|
|
22
|
-
// If the line is empty (user hit Enter on a new line), we are done.
|
|
23
54
|
if (line.trim() === "") {
|
|
24
55
|
rl.close()
|
|
25
56
|
break
|
|
@@ -33,16 +64,19 @@ async function readInteractiveInput() {
|
|
|
33
64
|
async function main() {
|
|
34
65
|
let input = ""
|
|
35
66
|
|
|
36
|
-
//
|
|
37
|
-
|
|
67
|
+
// 1. Check for file input (Any arg that isn't a flag)
|
|
68
|
+
const fileArg = args.find(arg => !arg.startsWith("-"))
|
|
69
|
+
|
|
70
|
+
if (fileArg) {
|
|
38
71
|
try {
|
|
39
|
-
input = fs.readFileSync(
|
|
72
|
+
input = fs.readFileSync(fileArg, "utf8")
|
|
40
73
|
} catch (err) {
|
|
41
|
-
console.error(`Error reading file: ${
|
|
74
|
+
console.error(`Error reading file: ${fileArg}`)
|
|
75
|
+
console.error(err.message)
|
|
42
76
|
process.exit(1)
|
|
43
77
|
}
|
|
44
|
-
}
|
|
45
|
-
// Interactive
|
|
78
|
+
}
|
|
79
|
+
// 2. Interactive Mode
|
|
46
80
|
else {
|
|
47
81
|
input = await readInteractiveInput()
|
|
48
82
|
}
|
|
@@ -55,7 +89,7 @@ async function main() {
|
|
|
55
89
|
try {
|
|
56
90
|
const tree = parseTree(input)
|
|
57
91
|
generateFS(tree, process.cwd(), { dryRun })
|
|
58
|
-
|
|
92
|
+
|
|
59
93
|
if (dryRun) {
|
|
60
94
|
console.log("Dry run complete. No files written.")
|
|
61
95
|
} else {
|
package/package.json
CHANGED