@cloud411716/fancy-webnovel 0.1.50 → 0.1.51
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/package.json
CHANGED
|
@@ -178,11 +178,16 @@ function spawnScraper(platform, length, outDir) {
|
|
|
178
178
|
const args = scraperArgs(platform, length, outDir);
|
|
179
179
|
const ports = ['9222', '9223'];
|
|
180
180
|
let portIdx = 0;
|
|
181
|
+
let dots = 0;
|
|
182
|
+
const interval = setInterval(() => {
|
|
183
|
+
dots++;
|
|
184
|
+
process.stderr.write('.');
|
|
185
|
+
}, 3000);
|
|
181
186
|
|
|
182
187
|
function tryPort(port) {
|
|
188
|
+
process.stderr.write(`\n → 端口 ${port} ...`);
|
|
183
189
|
const scraperScript = join(dirname(fileURLToPath(import.meta.url)), 'scrapers', args.script);
|
|
184
190
|
const fullArgs = ['--port', port, ...args.extra];
|
|
185
|
-
// stderr 透传到父进程 stderr,用户实时看到进度
|
|
186
191
|
const p = spawn('node', [scraperScript, ...fullArgs], {
|
|
187
192
|
timeout: 120000,
|
|
188
193
|
stdio: ['ignore', 'pipe', 'inherit'],
|
|
@@ -190,20 +195,27 @@ function spawnScraper(platform, length, outDir) {
|
|
|
190
195
|
let out = '';
|
|
191
196
|
p.stdout.on('data', d => { out += d.toString(); });
|
|
192
197
|
p.on('close', (code) => {
|
|
198
|
+
clearInterval(interval);
|
|
193
199
|
if (code === 0 && out.trim()) {
|
|
194
200
|
resolve({ ok: true, output: out, stderr: '' });
|
|
195
201
|
} else if (portIdx < ports.length - 1) {
|
|
196
202
|
portIdx++;
|
|
203
|
+
process.stderr.write(` (失败)\n`);
|
|
197
204
|
tryPort(ports[portIdx]);
|
|
198
205
|
} else {
|
|
199
|
-
|
|
206
|
+
process.stderr.write(` (失败)\n`);
|
|
200
207
|
const errTail = out.trimEnd().slice(-300);
|
|
201
208
|
resolve({ ok: false, output: out, error: errTail || `exit ${code}` });
|
|
202
209
|
}
|
|
203
210
|
});
|
|
204
211
|
p.on('error', (e) => {
|
|
205
|
-
|
|
206
|
-
|
|
212
|
+
clearInterval(interval);
|
|
213
|
+
if (portIdx < ports.length - 1) {
|
|
214
|
+
portIdx++;
|
|
215
|
+
tryPort(ports[portIdx]);
|
|
216
|
+
} else {
|
|
217
|
+
resolve({ ok: false, output: '', error: e.message });
|
|
218
|
+
}
|
|
207
219
|
});
|
|
208
220
|
}
|
|
209
221
|
tryPort(ports[portIdx]);
|