@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/tree.js +23 -10
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.2",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "bin": {
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
- // 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.
33
- const depth = Math.floor(prefix.length / 4);
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. Push clean name to stack
41
- stack.push(name.endsWith('/') ? name.slice(0, -1) : name);
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
- // 4. Form full path and create directory
47
+ stack.push(cleanName);
48
+
49
+ // 4. Form full path
44
50
  const fullPath = path.join(...stack);
45
51
  try {
46
- fs.mkdirSync(fullPath, { recursive: true });
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}`);