@himamshus06/git-auto 1.2.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/README.md CHANGED
@@ -1,17 +1,20 @@
1
1
  # Git-Auto 🚀
2
2
 
3
- `git-auto` is a lightweight CLI tool that automates the process of staging changes and generating professional, AI-powered commit messages. No more guessing what to write in your commit messages—let AI handle it!
3
+ `git-auto` is a lightweight CLI tool that automates the process of staging changes, generating professional AI-powered commit messages, and creating directory structures from pasted trees. No more guessing what to write in your commit messages or manually creating nested folders—let AI handle it!
4
4
 
5
5
  ## ✨ Features
6
6
 
7
+
7
8
  - **One-Command Workflow**: Stages all changes and commits them in one go.
8
9
  - **AI-Powered Messages**: Analyzes your `git diff` to generate a meaningful commit message.
9
10
  - **Conventional Commits**: Follows the [Conventional Commits](https://www.conventionalcommits.org/) specification (e.g., `feat:`, `fix:`, `chore:`).
10
11
  - **Smart Diff Handling**: Uses a Map-Reduce approach to summarize large changes, ensuring no detail is lost regardless of diff size.
11
12
  - **Interactive Experience**: Preview and edit AI-generated messages before they are committed to your history.
13
+ - **Tree Generation**: Instantly create complex directory structures by pasting a visual tree.
12
14
 
13
15
  ## 📦 Installation
14
16
 
17
+
15
18
  ### 1. Clone the Repository
16
19
  ```bash
17
20
  git clone https://github.com/your-username/git-auto.git
@@ -29,7 +32,7 @@ To use the `git auto` command anywhere on your system:
29
32
  npm install -g @himamshus06/git-auto
30
33
  ```
31
34
 
32
- To make it work as a git alias (`git ac commit` instead of `git-auto commit`), run:
35
+ To make it work as a git alias (`git ac commit` or `git ac tree` instead of `git-auto commit`), run:
33
36
  ```bash
34
37
  git config --global alias.ac "!git-auto"
35
38
  ```
@@ -77,7 +80,13 @@ AI_BASE_URL=http://localhost:11434/v1
77
80
  ### Basic Commit
78
81
  Stages all changes and commits with an AI-generated message:
79
82
  ```bash
80
- git auto commit
83
+ git-auto commit
84
+ ```
85
+
86
+ ### Create Directory Tree
87
+ Create a directory structure by pasting a visual tree:
88
+ ```bash
89
+ git-auto tree
81
90
  ```
82
91
 
83
92
  ### Commit with Custom Message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@himamshus06/git-auto",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ const readline = require('node:readline/promises');
4
4
  const { stdin: input, stdout: output } = require('node:process');
5
5
  const git = require('./git');
6
6
  const ai = require('./ai');
7
+ const tree = require('./tree');
7
8
  require('dotenv').config();
8
9
 
9
10
  const program = new Command();
@@ -79,4 +80,36 @@ program
79
80
  }
80
81
  });
81
82
 
83
+ program
84
+ .command('tree')
85
+ .description('Create directories from a pasted directory tree')
86
+ .action(async () => {
87
+ const rl = readline.createInterface({ input, output });
88
+ console.log('Paste your directory tree below. Press Enter on an empty line to finish:');
89
+
90
+ let treeText = '';
91
+ while (true) {
92
+ const line = await rl.question('');
93
+ if (line === '') break;
94
+ treeText += line + '\n';
95
+ }
96
+
97
+ try {
98
+ const result = await tree.parseAndCreateTree(treeText);
99
+ if (result.created.length > 0) {
100
+ console.log('\nSuccessfully created directories:');
101
+ result.created.forEach(dir => console.log(` - ${dir}`));
102
+ }
103
+ if (result.errors.length > 0) {
104
+ console.log('\nErrors encountered:');
105
+ result.errors.forEach(err => console.error(` - ${err}`));
106
+ }
107
+ } catch (error) {
108
+ console.error(`\nError: ${error.message}`);
109
+ } finally {
110
+ rl.close();
111
+ }
112
+ });
113
+
114
+
82
115
  program.parse(process.argv);
package/src/tree.js ADDED
@@ -0,0 +1,67 @@
1
+ const fs = require('node:fs');
2
+ const path = require('node:path');
3
+
4
+ /**
5
+ * Parses a visual directory tree and creates the corresponding directories.
6
+ * @param {string} text - The visual directory tree string.
7
+ * @returns {Promise<{created: string[], errors: string[]}>}
8
+ */
9
+ async function parseAndCreateTree(text) {
10
+ if (!text || text.trim() === '') {
11
+ throw new Error('No tree provided');
12
+ }
13
+
14
+ const lines = text.split('\n').filter(line => line.trim() !== '');
15
+ const stack = [];
16
+ const created = [];
17
+ const errors = [];
18
+
19
+ for (const line of lines) {
20
+ // 1. Determine depth
21
+ // We find the first character that isn't a tree symbol or whitespace
22
+ const match = line.match(/^([│\s├└]*)(.*)$/);
23
+ if (!match) continue;
24
+
25
+ const prefix = match[1];
26
+ let name = match[2].trim();
27
+
28
+ if (!name) continue;
29
+
30
+ // Depth is determined by the number of "blocks" of indentation.
31
+ // Most trees use 4 chars per level (e.g., "│ " or "├── ").
32
+ const depth = Math.floor(prefix.length / 4);
33
+
34
+ // 2. Adjust stack to current depth
35
+ while (stack.length > depth) {
36
+ stack.pop();
37
+ }
38
+
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
+
43
+ stack.push(cleanName);
44
+
45
+ // 4. Form full path
46
+ const fullPath = path.join(...stack);
47
+ try {
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
+ }
56
+ created.push(fullPath);
57
+ } catch (err) {
58
+ errors.push(`Failed to create ${fullPath}: ${err.message}`);
59
+ }
60
+ }
61
+
62
+ return { created, errors };
63
+ }
64
+
65
+ module.exports = {
66
+ parseAndCreateTree
67
+ };