@dongowu/git-ai-cli 2.0.0 → 2.0.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/git-ai.cjs CHANGED
File without changes
package/install.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const os = require('os');
6
+ const { spawnSync } = require('child_process');
6
7
 
7
8
  // Detect platform and architecture
8
9
  const platform = os.platform();
@@ -17,25 +18,81 @@ const platformMap = {
17
18
  'win32-x64': 'win32-x64',
18
19
  };
19
20
 
20
- const key = `${platform}-${arch}`;
21
+ const key = platform + '-' + arch;
21
22
  const platformKey = platformMap[key];
23
+ const npmjsRegistry = 'https://registry.npmjs.org/';
22
24
 
23
25
  if (!platformKey) {
24
- console.error(`Unsupported platform: ${platform} ${arch}`);
26
+ console.error('Unsupported platform: ' + platform + ' ' + arch);
25
27
  process.exit(1);
26
28
  }
27
29
 
28
30
  // Try to find the binary from the platform-specific package
29
- const packageName = `@dongowu/git-ai-cli-${platformKey}`;
31
+ const packageName = '@dongowu/git-ai-cli-' + platformKey;
30
32
  const nodeModulesPath = path.join(__dirname, 'node_modules');
31
33
  const binaryName = platform === 'win32' ? 'git-ai.exe' : 'git-ai';
32
34
  const binaryPath = path.join(nodeModulesPath, packageName, 'bin', binaryName);
33
35
 
36
+ function getRootPackageVersion() {
37
+ try {
38
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
39
+ return pkg.version;
40
+ } catch (err) {
41
+ console.warn('Warning: Failed to read package version: ' + err.message);
42
+ return 'latest';
43
+ }
44
+ }
45
+
46
+ function installPlatformPackageFromNpmjs(packageSpec) {
47
+ const npmExecPath = process.env.npm_execpath;
48
+ let command = 'npm';
49
+ const args = [];
50
+
51
+ if (npmExecPath && npmExecPath.endsWith('.js')) {
52
+ command = process.execPath;
53
+ args.push(npmExecPath);
54
+ } else if (npmExecPath && fs.existsSync(npmExecPath)) {
55
+ command = npmExecPath;
56
+ }
57
+
58
+ args.push(
59
+ 'install',
60
+ '--no-save',
61
+ '--no-package-lock',
62
+ '--ignore-scripts',
63
+ '--registry',
64
+ npmjsRegistry,
65
+ packageSpec
66
+ );
67
+
68
+ const result = spawnSync(command, args, {
69
+ cwd: __dirname,
70
+ stdio: 'inherit',
71
+ env: process.env,
72
+ });
73
+
74
+ return result.status === 0;
75
+ }
76
+
34
77
  // Check if binary exists
35
78
  if (!fs.existsSync(binaryPath)) {
36
- console.warn(`Warning: Binary not found at ${binaryPath}`);
37
- console.warn(`Please ensure the ${packageName} package is installed.`);
38
- process.exit(1);
79
+ console.warn('Warning: Binary not found at ' + binaryPath);
80
+
81
+ const packageVersion = getRootPackageVersion();
82
+ const packageSpec = packageName + '@' + packageVersion;
83
+
84
+ console.warn('Trying to install ' + packageSpec + ' from ' + npmjsRegistry + '...');
85
+
86
+ const installed = installPlatformPackageFromNpmjs(packageSpec);
87
+ if (!installed || !fs.existsSync(binaryPath)) {
88
+ const detectedRegistry = process.env.npm_config_registry || 'unknown';
89
+ console.error('Failed to install ' + packageSpec + '.');
90
+ console.error('Detected npm registry: ' + detectedRegistry);
91
+ console.error('Please retry with: npm install -g @dongowu/git-ai-cli --registry=' + npmjsRegistry);
92
+ process.exit(1);
93
+ }
94
+
95
+ console.log('✅ Installed missing platform package: ' + packageSpec);
39
96
  }
40
97
 
41
98
  // Make binary executable on Unix-like systems
@@ -43,8 +100,8 @@ if (process.platform !== 'win32') {
43
100
  try {
44
101
  fs.chmodSync(binaryPath, 0o755);
45
102
  } catch (err) {
46
- console.warn(`Warning: Could not make binary executable: ${err.message}`);
103
+ console.warn('Warning: Could not make binary executable: ' + err.message);
47
104
  }
48
105
  }
49
106
 
50
- console.log(`✅ git-ai binary installed for ${platformKey}`);
107
+ console.log('✅ git-ai binary installed for ' + platformKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongowu/git-ai-cli",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Generate git commit messages using AI - Rust Edition",
5
5
  "main": "bin/git-ai.cjs",
6
6
  "bin": {
@@ -43,10 +43,10 @@
43
43
  "LICENSE"
44
44
  ],
45
45
  "optionalDependencies": {
46
- "@dongowu/git-ai-cli-linux-x64": "2.0.0",
47
- "@dongowu/git-ai-cli-linux-arm64": "2.0.0",
48
- "@dongowu/git-ai-cli-darwin-x64": "2.0.0",
49
- "@dongowu/git-ai-cli-darwin-arm64": "2.0.0",
50
- "@dongowu/git-ai-cli-win32-x64": "2.0.0"
46
+ "@dongowu/git-ai-cli-linux-x64": "2.0.2",
47
+ "@dongowu/git-ai-cli-linux-arm64": "2.0.2",
48
+ "@dongowu/git-ai-cli-darwin-x64": "2.0.2",
49
+ "@dongowu/git-ai-cli-darwin-arm64": "2.0.2",
50
+ "@dongowu/git-ai-cli-win32-x64": "2.0.2"
51
51
  }
52
52
  }