@hpreet/gitpilot 0.1.1 → 0.1.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/bin/gitpilot.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { Command } from "commander";
3
3
  import { commitCommand } from "../src/commands/commit.js";
4
4
  import { setupCommand } from "../src/commands/setup.js";
5
+ import { enableWrapper } from "../src/commands/enable-wrapper.js";
5
6
 
6
7
  const program = new Command();
7
8
 
@@ -22,4 +23,9 @@ program
22
23
  .description("Configure your API provider and keys")
23
24
  .action(setupCommand);
24
25
 
26
+ program
27
+ .command("enable-wrapper")
28
+ .description("Enable gitpilot git wrapper")
29
+ .action(enableWrapper);
30
+
25
31
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpreet/gitpilot",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "AI-powered Git commit assistant — generates commit messages intelligently and fits seamlessly into your workflow.",
5
5
  "main": "bin/gitpilot.js",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "@google/generative-ai": "^0.24.1",
26
26
  "commander": "^14.0.2",
27
27
  "inquirer": "^12.11.1",
28
- "openai": "^6.9.0",
28
+ "openai": "^6.9.1",
29
29
  "simple-git": "^3.30.0"
30
30
  }
31
31
  }
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import os from 'os';
5
+
6
+ export function enableWrapper() {
7
+ const HOME = os.homedir();
8
+ const BIN_DIR = path.join(HOME, 'bin');
9
+
10
+ // 1. Ensure ~/bin exists
11
+ if (!fs.existsSync(BIN_DIR)) {
12
+ fs.mkdirSync(BIN_DIR, { recursive: true });
13
+ console.log(`Created ${BIN_DIR}`);
14
+ }
15
+
16
+ // 2. Write git wrapper script
17
+ const wrapperPath = path.join(BIN_DIR, 'git');
18
+
19
+ // Detect platform for wrapper script shebang
20
+ const isWindows = process.platform === 'win32';
21
+ const wrapperScript = isWindows
22
+ ? `#!/usr/bin/env bash
23
+ ORIGINAL_GIT="$(which git)"
24
+ if [[ "$1" == "commit" && "$2" == "-ai" ]]; then
25
+ gitpilot commit
26
+ else
27
+ "$ORIGINAL_GIT" "$@"
28
+ fi`
29
+ : `#!/usr/bin/env bash
30
+ ORIGINAL_GIT="$(which git)"
31
+ if [[ "$1" == "commit" && "$2" == "-ai" ]]; then
32
+ gitpilot commit
33
+ else
34
+ "$ORIGINAL_GIT" "$@"
35
+ fi`;
36
+
37
+ fs.writeFileSync(wrapperPath, wrapperScript, { mode: 0o755 });
38
+ console.log(`Installed git wrapper at ${wrapperPath}`);
39
+
40
+ // 3. Detect shell rc file
41
+ let shellRc;
42
+ const userShell = process.env.SHELL || '';
43
+ if (isWindows) {
44
+ // Git Bash / WSL
45
+ shellRc = path.join(HOME, '.bashrc');
46
+ console.log(`Using ${shellRc} for PATH configuration (Git Bash/WSL)`);
47
+ } else if (userShell.includes('zsh')) {
48
+ shellRc = path.join(HOME, '.zshrc');
49
+ } else if (userShell.includes('bash')) {
50
+ shellRc = path.join(HOME, '.bashrc');
51
+ } else {
52
+ shellRc = path.join(HOME, '.profile'); // fallback
53
+ }
54
+
55
+ // 4. Add ~/bin to PATH if not already present
56
+ const pathLine = `export PATH="$HOME/bin:$PATH"`;
57
+ const rcContent = fs.existsSync(shellRc) ? fs.readFileSync(shellRc, 'utf-8') : '';
58
+ if (!rcContent.includes(pathLine)) {
59
+ fs.appendFileSync(shellRc, `\n# Added by GitPilot enable-wrapper\n${pathLine}\n`);
60
+ console.log(`Added ~/bin to PATH in ${shellRc}`);
61
+ } else {
62
+ console.log(`~/bin is already in PATH in ${shellRc}`);
63
+ }
64
+
65
+ console.log(`\n✅ GitPilot wrapper enabled!`);
66
+ console.log(`Please restart your terminal or run:`);
67
+ console.log(`source ${shellRc}`);
68
+ }