doc-fetch-cli 2.0.2 → 2.0.4

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/doc-fetch.js CHANGED
@@ -1,25 +1,42 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * DocFetch CLI Wrapper
4
+ * Spawns the correct platform-specific Go binary
5
+ */
6
+
2
7
  const { spawn } = require('child_process');
3
8
  const path = require('path');
4
- const os = require('os');
5
9
  const fs = require('fs');
6
10
 
7
- // Get the package installation directory
8
11
  const packageDir = path.join(__dirname, '..');
9
12
 
10
- // Determine binary name based on platform (what postinstall creates)
11
- const platform = os.platform();
12
- const binaryName = platform === 'win32' ? 'doc-fetch.exe' : 'doc-fetch';
13
+ // Binary name is set by postinstall script
14
+ // Default fallbacks if postinstall didn't run
15
+ let binaryName = 'doc-fetch';
16
+ const platform = process.platform;
17
+
18
+ if (platform === 'win32') {
19
+ binaryName = 'doc-fetch.exe';
20
+ } else if (platform === 'darwin') {
21
+ binaryName = 'doc-fetch';
22
+ } else {
23
+ binaryName = 'doc-fetch';
24
+ }
13
25
 
14
- // Try multiple possible locations
15
- const possiblePaths = [
16
- path.join(packageDir, binaryName), // Root directory (postinstall copies here)
17
- path.join(packageDir, 'bin', binaryName), // bin/ directory (fallback)
26
+ // Try to find the actual binary
27
+ const possibleBinaries = [
28
+ binaryName,
29
+ 'doc-fetch.exe',
30
+ 'doc-fetch_windows_amd64.exe',
31
+ 'doc-fetch_darwin_amd64',
32
+ 'doc-fetch_darwin_arm64',
33
+ 'doc-fetch_linux_amd64',
34
+ 'doc-fetch_linux_arm64',
18
35
  ];
19
36
 
20
- // Find the binary
21
37
  let binaryPath = null;
22
- for (const testPath of possiblePaths) {
38
+ for (const name of possibleBinaries) {
39
+ const testPath = path.join(packageDir, name);
23
40
  if (fs.existsSync(testPath)) {
24
41
  binaryPath = testPath;
25
42
  break;
@@ -29,24 +46,12 @@ for (const testPath of possiblePaths) {
29
46
  if (!binaryPath) {
30
47
  console.error('āŒ doc-fetch binary not found!');
31
48
  console.error('');
32
- console.error(`šŸ’” Platform: ${platform} (${os.arch()})`);
33
- console.error('šŸ’” Expected: doc-fetch' + (platform === 'win32' ? '.exe' : ''));
34
- console.error('');
35
- console.error('šŸ’” Troubleshooting steps:');
36
- console.error(' 1. List files: ls -la $(npm root -g)/doc-fetch-cli/');
37
- console.error(' 2. Look for platform-specific binary:');
38
- if (platform === 'win32') {
39
- console.error(' doc-fetch_windows_amd64.exe');
40
- } else if (platform === 'darwin') {
41
- console.error(' doc-fetch_darwin_amd64 (Intel) or doc-fetch_darwin_arm64 (M1/M2)');
42
- } else {
43
- console.error(' doc-fetch_linux_amd64 (x64) or doc-fetch_linux_arm64 (ARM)');
44
- }
45
- console.error(' 3. Manually copy: cp <platform-binary> doc-fetch' + (platform === 'win32' ? '.exe' : ''));
46
- console.error(' 4. Make executable: chmod +x doc-fetch (Linux/macOS only)');
47
- console.error(' 5. Reinstall: npm uninstall -g doc-fetch-cli && npm install -g doc-fetch-cli@latest');
49
+ console.error('šŸ’” Platform:', platform, '(' + process.arch + ')');
50
+ console.error('šŸ’” Searched in:', packageDir);
48
51
  console.error('');
49
- console.error('šŸ“¦ Package directory:', packageDir);
52
+ console.error('šŸ’” Try reinstalling:');
53
+ console.error(' npm uninstall -g doc-fetch-cli');
54
+ console.error(' npm install -g doc-fetch-cli@latest');
50
55
  process.exit(1);
51
56
  }
52
57
 
@@ -59,16 +64,15 @@ const child = spawn(binaryPath, args, {
59
64
 
60
65
  child.on('error', (err) => {
61
66
  if (err.code === 'ENOENT') {
62
- console.error('āŒ Failed to execute doc-fetch binary');
63
- console.error(` Binary path: ${binaryPath}`);
67
+ console.error('āŒ Failed to execute binary');
68
+ console.error(' Path:', binaryPath);
64
69
  console.error(' Error: File not found or no execute permission');
65
- console.error('');
66
70
  if (platform !== 'win32') {
71
+ console.error('');
67
72
  console.error('šŸ’” Fix permissions: chmod +x "' + binaryPath + '"');
68
73
  }
69
- console.error('šŸ’” Or reinstall: npm uninstall -g doc-fetch-cli && npm install -g doc-fetch-cli@latest');
70
74
  } else {
71
- console.error('āŒ Failed to start doc-fetch:', err.message);
75
+ console.error('āŒ Failed to start:', err.message);
72
76
  }
73
77
  process.exit(1);
74
78
  });
Binary file
Binary file
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * Post-install script for doc-fetch-cli
4
- * Copies the correct platform-specific binary and sets up PATH
4
+ * Detects and uses the correct platform binary (no copying needed)
5
5
  */
6
6
 
7
- const { execSync } = require('child_process');
8
7
  const path = require('path');
9
8
  const os = require('os');
10
9
  const fs = require('fs');
@@ -15,185 +14,92 @@ const packageDir = path.join(__dirname, '..');
15
14
  const platform = os.platform();
16
15
  const arch = os.arch();
17
16
 
18
- // Determine which binary to use
19
- let binaryName;
20
- let expectedBinary;
21
-
17
+ // Define binary names to search for (in priority order)
18
+ let searchNames = [];
22
19
  if (platform === 'win32') {
23
- binaryName = 'doc-fetch.exe';
24
- expectedBinary = 'doc-fetch_windows_amd64.exe';
20
+ searchNames = ['doc-fetch_windows_amd64.exe', 'doc-fetch.exe'];
25
21
  } else if (platform === 'darwin') {
26
- binaryName = 'doc-fetch';
27
- expectedBinary = 'doc-fetch_darwin_amd64';
22
+ searchNames = arch === 'arm64'
23
+ ? ['doc-fetch_darwin_arm64', 'doc-fetch_darwin_amd64', 'doc-fetch']
24
+ : ['doc-fetch_darwin_amd64', 'doc-fetch_darwin_arm64', 'doc-fetch'];
28
25
  } else {
29
26
  // Linux
30
- binaryName = 'doc-fetch';
31
- expectedBinary = arch === 'arm64' ? 'doc-fetch_linux_arm64' : 'doc-fetch_linux_amd64';
27
+ searchNames = arch === 'arm64'
28
+ ? ['doc-fetch_linux_arm64', 'doc-fetch_linux_amd64', 'doc-fetch']
29
+ : ['doc-fetch_linux_amd64', 'doc-fetch_linux_arm64', 'doc-fetch'];
32
30
  }
33
31
 
34
- const sourcePath = path.join(packageDir, expectedBinary);
35
- const destPath = path.join(packageDir, binaryName);
36
-
37
32
  console.log(`šŸ“¦ Platform: ${platform} ${arch}`);
38
- console.log(`šŸ“¦ Expected binary: ${expectedBinary}`);
39
- console.log(`šŸ“¦ Will copy to: ${binaryName}\n`);
33
+ console.log(`šŸ” Searching for binary...\n`);
40
34
 
41
- // List all available binaries for debugging
42
- console.log('šŸ“‹ Available binaries in package:');
43
- let hasPlatformBinary = false;
35
+ // List all doc-fetch binaries in package
36
+ console.log('šŸ“‹ Available binaries:');
44
37
  let foundBinary = null;
45
38
  try {
46
39
  const files = fs.readdirSync(packageDir);
47
40
  const binaries = files.filter(f => f.includes('doc-fetch') && !f.endsWith('.js'));
41
+
48
42
  if (binaries.length === 0) {
49
- console.log(' āš ļø No binaries found! Package may be corrupted.');
50
- } else {
51
- binaries.forEach(file => {
52
- const stats = fs.statSync(path.join(packageDir, file));
53
- const size = (stats.size / 1024 / 1024).toFixed(2);
54
-
55
- // Check if this is the correct binary for current platform
56
- let isCorrect = false;
57
- if (platform === 'win32' && file.endsWith('.exe')) {
58
- isCorrect = true;
59
- foundBinary = file;
60
- } else if (platform !== 'win32' && !file.endsWith('.exe') &&
61
- (file === 'doc-fetch' || file.includes(`_${platform}_`))) {
62
- isCorrect = true;
63
- foundBinary = file;
64
- }
65
-
66
- const marker = isCorrect ? 'āœ…' : 'ā„¹ļø ';
67
- console.log(` ${marker} ${file} (${size} MB)`);
68
-
69
- if (isCorrect && file === expectedBinary) {
70
- hasPlatformBinary = true;
71
- }
72
- });
43
+ console.log(' āŒ No binaries found! Package is corrupted.\n');
44
+ process.exit(1);
73
45
  }
74
- } catch (e) {
75
- console.log(` āŒ Could not list directory: ${e.message}`);
76
- }
77
- console.log('');
78
-
79
- // Smart detection: Copy platform binary to generic name if needed
80
- if (foundBinary && fs.existsSync(path.join(packageDir, foundBinary))) {
81
- // Check if we need to copy (found binary != expected generic name)
82
- if (foundBinary !== binaryName) {
83
- console.log(`āœ… Found platform binary: ${foundBinary}`);
84
- console.log(`šŸ“‹ Copying to: ${binaryName}`);
46
+
47
+ binaries.forEach(file => {
48
+ const stats = fs.statSync(path.join(packageDir, file));
49
+ const size = (stats.size / 1024 / 1024).toFixed(2);
85
50
 
86
- try {
87
- fs.copyFileSync(path.join(packageDir, foundBinary), path.join(packageDir, binaryName));
88
-
89
- if (platform !== 'win32') {
90
- fs.chmodSync(path.join(packageDir, binaryName), 0o755);
91
- }
92
-
93
- console.log(`āœ… Binary installed successfully!\n`);
94
-
95
- // Verify it works
96
- const testPath = path.join(packageDir, binaryName);
97
- if (fs.existsSync(testPath)) {
98
- console.log('✨ Installation complete! You can now use: doc-fetch\n');
99
- return; // Success!
100
- }
101
- } catch (copyError) {
102
- console.error(`āš ļø Copy failed: ${copyError.message}`);
103
- console.error('');
104
- console.error('šŸ’” Manual fix:');
105
- console.error(` cd "${packageDir}"`);
106
- if (platform === 'win32') {
107
- console.error(` copy "${foundBinary}" "${binaryName}"`);
108
- } else {
109
- console.error(` cp "${foundBinary}" "${binaryName}"`);
110
- console.error(` chmod +x "${binaryName}"`);
111
- }
112
- process.exit(1);
51
+ // Check if this is a valid binary for current platform
52
+ const isValid = searchNames.includes(file);
53
+ const marker = isValid ? 'āœ…' : 'ā„¹ļø ';
54
+ console.log(` ${marker} ${file} (${size} MB)`);
55
+
56
+ // Use first valid match
57
+ if (isValid && !foundBinary) {
58
+ foundBinary = file;
113
59
  }
114
- } else {
115
- // Binary already has correct name
116
- console.log(`āœ… Binary already correctly named: ${binaryName}\n`);
117
- console.log('✨ Installation complete! You can now use: doc-fetch\n');
118
- return;
119
- }
120
- }
121
-
122
- // If we get here, something really went wrong
123
- if (!fs.existsSync(sourcePath) && !hasPlatformBinary && !foundBinary) {
124
- console.error('āš ļø CRITICAL: No compatible binary found!');
125
- console.error(` Searched for: ${expectedBinary}`);
126
- console.error(` Found instead: ${foundBinary || 'nothing compatible'}`);
127
- console.error('');
128
- console.error('šŸ’” This is a packaging error - the NPM package was published without your platform binary.');
129
- console.error('');
130
- console.error('šŸ’” Immediate workaround - Install from source:');
131
- console.error(' 1. Install Go: https://golang.org/dl/');
132
- console.error(' 2. Run these commands:');
133
- console.error(' npm uninstall -g doc-fetch-cli');
134
- console.error(' git clone https://github.com/AlphaTechini/doc-fetch.git');
135
- console.error(' cd doc-fetch');
136
- if (platform === 'win32') {
137
- console.error(' go build -o doc-fetch.exe ./cmd/docfetch');
138
- console.error(' copy doc-fetch.exe "' + packageDir + '"');
139
- } else {
140
- console.error(' go build -o doc-fetch ./cmd/docfetch');
141
- console.error(' cp doc-fetch "' + packageDir + '"');
142
- console.error(' chmod +x "' + path.join(packageDir, 'doc-fetch') + '"');
143
- }
144
- console.error('');
145
- console.error('šŸ’” Or wait for fixed version (check for updates):');
146
- console.error(' npm install -g doc-fetch-cli@latest');
60
+ });
61
+ } catch (e) {
62
+ console.log(` āŒ Error listing directory: ${e.message}\n`);
147
63
  process.exit(1);
148
64
  }
149
65
 
150
- console.log(`āœ… Found source binary: ${expectedBinary}`);
66
+ console.log('');
151
67
 
152
- // Copy the binary to the expected location
153
- try {
154
- console.log(`šŸ“‹ Copying: ${expectedBinary} → ${binaryName}`);
155
- fs.copyFileSync(sourcePath, destPath);
156
- console.log(`āœ… Copy successful`);
157
-
158
- // Verify the destination exists
159
- if (!fs.existsSync(destPath)) {
160
- throw new Error('Destination file does not exist after copy');
161
- }
162
-
163
- // Make executable on Unix-like systems
164
- if (platform !== 'win32') {
165
- fs.chmodSync(destPath, 0o755);
166
- console.log(`āœ… Set executable permissions`);
167
- } else {
168
- console.log(`ā„¹ļø Windows: No chmod needed`);
169
- }
170
-
171
- console.log(`\nāœ… Binary installed: ${binaryName}`);
172
- } catch (error) {
173
- console.error(`\nāŒ CRITICAL: Failed to install binary!`);
174
- console.error(` Source: ${sourcePath}`);
175
- console.error(` Destination: ${destPath}`);
176
- console.error(` Error: ${error.message}`);
68
+ if (!foundBinary) {
69
+ console.error('āŒ CRITICAL: No compatible binary found for your platform!');
70
+ console.error(` Searched for: ${searchNames.join(', ')}`);
177
71
  console.error('');
178
- console.error('šŸ’” Manual fix:');
179
- console.error(` 1. Navigate to: ${packageDir}`);
180
- console.error(` 2. Rename: ${expectedBinary} → ${binaryName}`);
181
- if (platform !== 'win32') {
182
- console.error(` 3. Run: chmod +x ${binaryName}`);
183
- }
72
+ console.error('šŸ’” This is a packaging error. Please:');
73
+ console.error(' 1. Report issue: https://github.com/AlphaTechini/doc-fetch/issues');
74
+ console.error(' 2. Include your platform: ' + platform + ' ' + arch);
75
+ console.error(' 3. Or install from source (see README)\n');
184
76
  process.exit(1);
185
77
  }
186
78
 
187
- // Verify installation
188
- try {
189
- const result = execSync(`"${destPath}" --help`, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] });
190
- console.log('āœ… Binary verified working\n');
191
- } catch (error) {
192
- console.error('āš ļø Warning: Could not verify binary execution');
193
- console.error(` Error: ${error.message}\n`);
79
+ // Update wrapper script to use found binary
80
+ const wrapperPath = path.join(packageDir, 'bin', 'doc-fetch.js');
81
+ if (fs.existsSync(wrapperPath)) {
82
+ try {
83
+ let wrapper = fs.readFileSync(wrapperPath, 'utf8');
84
+
85
+ // Update the binary name in wrapper
86
+ wrapper = wrapper.replace(
87
+ /const binaryName = ['"][^'"]+['"];/,
88
+ `const binaryName = '${foundBinary}';`
89
+ );
90
+
91
+ fs.writeFileSync(wrapperPath, wrapper);
92
+ console.log(`āœ… Configured wrapper to use: ${foundBinary}`);
93
+ } catch (e) {
94
+ console.log(`āš ļø Could not update wrapper: ${e.message}`);
95
+ console.log(` You may need to run: doc-fetch (instead of doc-fetch-cli)`);
96
+ }
194
97
  }
195
98
 
196
- console.log('✨ DocFetch CLI installed successfully!\n');
99
+ console.log('');
100
+ console.log('✨ Installation complete!');
101
+ console.log('');
197
102
  console.log('Usage:');
198
- console.log(' doc-fetch --url https://docs.example.com --output docs.md\n');
103
+ console.log(' doc-fetch --url https://docs.example.com --output docs.md');
104
+ console.log('');
199
105
  console.log('Pro tip: Use --llm-txt flag to generate AI-friendly index files!\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doc-fetch-cli",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Dynamic documentation fetching CLI that converts entire documentation sites to single markdown files for AI/LLM consumption",
5
5
  "bin": {
6
6
  "doc-fetch": "./bin/doc-fetch.js"