@himamshus06/git-auto 1.3.0 → 1.3.2
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 +23 -10
package/package.json
CHANGED
package/src/tree.js
CHANGED
|
@@ -18,32 +18,45 @@ 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
|
-
//
|
|
33
|
-
|
|
30
|
+
// Depth is determined by the number of 4-character blocks in the prefix.
|
|
31
|
+
// For most visual trees, each level of nesting is 4 characters (e.g., "│ " or "├── ").
|
|
32
|
+
// We strip the final tree symbol (├ or └) from the length if it's there.
|
|
33
|
+
const effectivePrefixLength = prefix.endsWith('├') || prefix.endsWith('└')
|
|
34
|
+
? prefix.length - 1
|
|
35
|
+
: prefix.length;
|
|
36
|
+
const depth = Math.floor(effectivePrefixLength / 4);
|
|
34
37
|
|
|
35
38
|
// 2. Adjust stack to current depth
|
|
36
39
|
while (stack.length > depth) {
|
|
37
40
|
stack.pop();
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
// 3.
|
|
41
|
-
|
|
43
|
+
// 3. Clean name (remove trailing slash for directory creation)
|
|
44
|
+
const isDirectory = name.endsWith('/') || !name.includes('.');
|
|
45
|
+
const cleanName = isDirectory ? name.replace(/\/$/, '') : name;
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
stack.push(cleanName);
|
|
48
|
+
|
|
49
|
+
// 4. Form full path
|
|
44
50
|
const fullPath = path.join(...stack);
|
|
45
51
|
try {
|
|
46
|
-
|
|
52
|
+
if (isDirectory) {
|
|
53
|
+
fs.mkdirSync(fullPath, { recursive: true });
|
|
54
|
+
} else {
|
|
55
|
+
// Ensure parent directory exists
|
|
56
|
+
const parentDir = path.dirname(fullPath);
|
|
57
|
+
fs.mkdirSync(parentDir, { recursive: true });
|
|
58
|
+
fs.writeFileSync(fullPath, ''); // Create empty file
|
|
59
|
+
}
|
|
47
60
|
created.push(fullPath);
|
|
48
61
|
} catch (err) {
|
|
49
62
|
errors.push(`Failed to create ${fullPath}: ${err.message}`);
|