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 +37 -33
- package/bin/postinstall.js +60 -141
- package/package.json +1 -1
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
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
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(
|
|
33
|
-
console.error('š”
|
|
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('
|
|
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
|
|
63
|
-
console.error(
|
|
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
|
|
75
|
+
console.error('ā Failed to start:', err.message);
|
|
72
76
|
}
|
|
73
77
|
process.exit(1);
|
|
74
78
|
});
|
package/bin/postinstall.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* Post-install script for doc-fetch-cli
|
|
4
|
-
*
|
|
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
|
-
//
|
|
19
|
-
let
|
|
20
|
-
let expectedBinary;
|
|
21
|
-
|
|
17
|
+
// Define binary names to search for (in priority order)
|
|
18
|
+
let searchNames = [];
|
|
22
19
|
if (platform === 'win32') {
|
|
23
|
-
|
|
24
|
-
expectedBinary = 'doc-fetch_windows_amd64.exe';
|
|
20
|
+
searchNames = ['doc-fetch.exe', 'doc-fetch_windows_amd64.exe'];
|
|
25
21
|
} else if (platform === 'darwin') {
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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(
|
|
39
|
-
console.log(`š¦ Will copy to: ${binaryName}\n`);
|
|
33
|
+
console.log(`š Searching for binary...\n`);
|
|
40
34
|
|
|
41
|
-
// List all
|
|
42
|
-
console.log('š Available binaries
|
|
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('
|
|
50
|
-
|
|
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
|
-
|
|
85
|
-
fs.
|
|
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
|
|
88
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
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(
|
|
66
|
+
console.log('');
|
|
138
67
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
console.
|
|
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('š”
|
|
166
|
-
console.error(
|
|
167
|
-
console.error(
|
|
168
|
-
|
|
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
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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('
|
|
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
|
|
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