doc-fetch-cli 2.0.1 → 2.0.3

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
  });
@@ -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,172 +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.exe', 'doc-fetch_windows_amd64.exe'];
25
21
  } else if (platform === 'darwin') {
26
- binaryName = 'doc-fetch';
27
- expectedBinary = 'doc-fetch_darwin_amd64';
22
+ searchNames = arch === 'arm64'
23
+ ? ['doc-fetch', 'doc-fetch_darwin_arm64', 'doc-fetch_darwin_amd64']
24
+ : ['doc-fetch', 'doc-fetch_darwin_amd64', 'doc-fetch_darwin_arm64'];
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', 'doc-fetch_linux_arm64', 'doc-fetch_linux_amd64']
29
+ : ['doc-fetch', 'doc-fetch_linux_amd64', 'doc-fetch_linux_arm64'];
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: If we found a binary that works, use it!
80
- if (!hasPlatformBinary && foundBinary && fs.existsSync(path.join(packageDir, foundBinary))) {
81
- console.log(`āœ… Found compatible binary: ${foundBinary}`);
82
- console.log(`šŸ“‹ Copying: ${foundBinary} → ${binaryName}`);
83
46
 
84
- try {
85
- fs.copyFileSync(path.join(packageDir, foundBinary), path.join(packageDir, binaryName));
47
+ binaries.forEach(file => {
48
+ const stats = fs.statSync(path.join(packageDir, file));
49
+ const size = (stats.size / 1024 / 1024).toFixed(2);
86
50
 
87
- if (platform !== 'win32') {
88
- fs.chmodSync(path.join(packageDir, binaryName), 0o755);
89
- }
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)`);
90
55
 
91
- console.log(`āœ… Binary installed successfully!\n`);
92
-
93
- // Verify it works
94
- try {
95
- const testPath = path.join(packageDir, binaryName);
96
- if (fs.existsSync(testPath)) {
97
- console.log('✨ Installation complete! You can now use: doc-fetch\n');
98
- return; // Success!
99
- }
100
- } catch (e) {
101
- // Continue to error handling
56
+ // Use first valid match
57
+ if (isValid && !foundBinary) {
58
+ foundBinary = file;
102
59
  }
103
- } catch (copyError) {
104
- console.error(`āš ļø Copy failed: ${copyError.message}`);
105
- // Continue to error handling
106
- }
107
- }
108
-
109
- // If we get here, something really went wrong
110
- if (!fs.existsSync(sourcePath) && !hasPlatformBinary && !foundBinary) {
111
- console.error('āš ļø CRITICAL: No compatible binary found!');
112
- console.error(` Searched for: ${expectedBinary}`);
113
- console.error(` Found instead: ${foundBinary || 'nothing compatible'}`);
114
- console.error('');
115
- console.error('šŸ’” This is a packaging error - the NPM package was published without your platform binary.');
116
- console.error('');
117
- console.error('šŸ’” Immediate workaround - Install from source:');
118
- console.error(' 1. Install Go: https://golang.org/dl/');
119
- console.error(' 2. Run these commands:');
120
- console.error(' npm uninstall -g doc-fetch-cli');
121
- console.error(' git clone https://github.com/AlphaTechini/doc-fetch.git');
122
- console.error(' cd doc-fetch');
123
- if (platform === 'win32') {
124
- console.error(' go build -o doc-fetch.exe ./cmd/docfetch');
125
- console.error(' copy doc-fetch.exe "' + packageDir + '"');
126
- } else {
127
- console.error(' go build -o doc-fetch ./cmd/docfetch');
128
- console.error(' cp doc-fetch "' + packageDir + '"');
129
- console.error(' chmod +x "' + path.join(packageDir, 'doc-fetch') + '"');
130
- }
131
- console.error('');
132
- console.error('šŸ’” Or wait for fixed version (check for updates):');
133
- console.error(' npm install -g doc-fetch-cli@latest');
60
+ });
61
+ } catch (e) {
62
+ console.log(` āŒ Error listing directory: ${e.message}\n`);
134
63
  process.exit(1);
135
64
  }
136
65
 
137
- console.log(`āœ… Found source binary: ${expectedBinary}`);
66
+ console.log('');
138
67
 
139
- // Copy the binary to the expected location
140
- try {
141
- console.log(`šŸ“‹ Copying: ${expectedBinary} → ${binaryName}`);
142
- fs.copyFileSync(sourcePath, destPath);
143
- console.log(`āœ… Copy successful`);
144
-
145
- // Verify the destination exists
146
- if (!fs.existsSync(destPath)) {
147
- throw new Error('Destination file does not exist after copy');
148
- }
149
-
150
- // Make executable on Unix-like systems
151
- if (platform !== 'win32') {
152
- fs.chmodSync(destPath, 0o755);
153
- console.log(`āœ… Set executable permissions`);
154
- } else {
155
- console.log(`ā„¹ļø Windows: No chmod needed`);
156
- }
157
-
158
- console.log(`\nāœ… Binary installed: ${binaryName}`);
159
- } catch (error) {
160
- console.error(`\nāŒ CRITICAL: Failed to install binary!`);
161
- console.error(` Source: ${sourcePath}`);
162
- console.error(` Destination: ${destPath}`);
163
- 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(', ')}`);
164
71
  console.error('');
165
- console.error('šŸ’” Manual fix:');
166
- console.error(` 1. Navigate to: ${packageDir}`);
167
- console.error(` 2. Rename: ${expectedBinary} → ${binaryName}`);
168
- if (platform !== 'win32') {
169
- console.error(` 3. Run: chmod +x ${binaryName}`);
170
- }
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');
171
76
  process.exit(1);
172
77
  }
173
78
 
174
- // Verify installation
175
- try {
176
- const result = execSync(`"${destPath}" --help`, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] });
177
- console.log('āœ… Binary verified working\n');
178
- } catch (error) {
179
- console.error('āš ļø Warning: Could not verify binary execution');
180
- 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
+ }
181
97
  }
182
98
 
183
- console.log('✨ DocFetch CLI installed successfully!\n');
99
+ console.log('');
100
+ console.log('✨ Installation complete!');
101
+ console.log('');
184
102
  console.log('Usage:');
185
- 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('');
186
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.1",
3
+ "version": "2.0.3",
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"