@himamshus06/git-auto 1.3.0 → 1.3.1
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/package.json +1 -1
- package/src/tree.js +18 -9
package/package.json
CHANGED
package/src/tree.js
CHANGED
|
@@ -18,18 +18,17 @@ async function parseAndCreateTree(text) {
|
|
|
18
18
|
|
|
19
19
|
for (const line of lines) {
|
|
20
20
|
// 1. Determine depth
|
|
21
|
-
//
|
|
22
|
-
// Standard tree indentation is typically 4 spaces or characters.
|
|
21
|
+
// We find the first character that isn't a tree symbol or whitespace
|
|
23
22
|
const match = line.match(/^([│\s├└]*)(.*)$/);
|
|
24
23
|
if (!match) continue;
|
|
25
24
|
|
|
26
25
|
const prefix = match[1];
|
|
27
|
-
|
|
26
|
+
let name = match[2].trim();
|
|
28
27
|
|
|
29
28
|
if (!name) continue;
|
|
30
29
|
|
|
31
|
-
//
|
|
32
|
-
//
|
|
30
|
+
// Depth is determined by the number of "blocks" of indentation.
|
|
31
|
+
// Most trees use 4 chars per level (e.g., "│ " or "├── ").
|
|
33
32
|
const depth = Math.floor(prefix.length / 4);
|
|
34
33
|
|
|
35
34
|
// 2. Adjust stack to current depth
|
|
@@ -37,13 +36,23 @@ async function parseAndCreateTree(text) {
|
|
|
37
36
|
stack.pop();
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
// 3.
|
|
41
|
-
|
|
39
|
+
// 3. Clean name (remove trailing slash for directory creation)
|
|
40
|
+
const isDirectory = name.endsWith('/') || !name.includes('.');
|
|
41
|
+
const cleanName = isDirectory ? name.replace(/\/$/, '') : name;
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
stack.push(cleanName);
|
|
44
|
+
|
|
45
|
+
// 4. Form full path
|
|
44
46
|
const fullPath = path.join(...stack);
|
|
45
47
|
try {
|
|
46
|
-
|
|
48
|
+
if (isDirectory) {
|
|
49
|
+
fs.mkdirSync(fullPath, { recursive: true });
|
|
50
|
+
} else {
|
|
51
|
+
// Ensure parent directory exists
|
|
52
|
+
const parentDir = path.dirname(fullPath);
|
|
53
|
+
fs.mkdirSync(parentDir, { recursive: true });
|
|
54
|
+
fs.writeFileSync(fullPath, ''); // Create empty file
|
|
55
|
+
}
|
|
47
56
|
created.push(fullPath);
|
|
48
57
|
} catch (err) {
|
|
49
58
|
errors.push(`Failed to create ${fullPath}: ${err.message}`);
|