@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/tree.js +18 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@himamshus06/git-auto",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "bin": {
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
- // Depth is based on the number of leading spaces/tree characters.
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
- const name = match[2].trim();
26
+ let name = match[2].trim();
28
27
 
29
28
  if (!name) continue;
30
29
 
31
- // Calculate depth based on the prefix.
32
- // Each 'level' in a standard tree is usually 4 characters.
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. Push clean name to stack
41
- stack.push(name.endsWith('/') ? name.slice(0, -1) : name);
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
- // 4. Form full path and create directory
43
+ stack.push(cleanName);
44
+
45
+ // 4. Form full path
44
46
  const fullPath = path.join(...stack);
45
47
  try {
46
- fs.mkdirSync(fullPath, { recursive: true });
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}`);