@cloud411716/fancy-webnovel 0.1.62 → 0.1.64

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "0.1.62",
3
+ "version": "0.1.64",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -4,10 +4,10 @@
4
4
  import { fileURLToPath } from 'url';
5
5
  import { dirname, join } from 'path';
6
6
  import { existsSync } from 'fs';
7
- import { notify, llmFollowup } from '../../infra.js';
7
+ import { notify, llmFollowup, spawnScript } from '../../infra.js';
8
8
  import { scan, PLATFORM_TABLE, platformLabel } from './templates.js';
9
9
 
10
- export const inject = ['commands', 'userQuestions'];
10
+ export const inject = ['commands', 'userQuestions', 'tuiStatus'];
11
11
 
12
12
  const __dirname = dirname(fileURLToPath(import.meta.url));
13
13
  const SCAN_SCRIPTS_DIR = join(__dirname, 'scripts');
@@ -91,37 +91,26 @@ export async function apply(ctx) {
91
91
  }
92
92
 
93
93
  notify(session, scan.notify({ type: 'collecting', platform, length }));
94
-
95
- // 实时 spinner:每 400ms 追加一帧
96
- const { spawn } = await import('child_process');
97
- const FRAMES = '⠋⠙⠹⠸⠴⠦⠧⠇⠏';
98
- let frame = 0;
99
- const ticker = setInterval(() => {
100
- notify(session, `⏳ ${FRAMES[frame % FRAMES.length]} 采集中...`);
101
- frame++;
102
- }, 400);
103
-
104
- const proc = spawn('node', [join(SCAN_SCRIPTS_DIR, 'run-scan.js'),
105
- '--project-root', projectRoot, '--platform', platform, '--length', length], {
106
- timeout: 120000,
107
- stdio: ['ignore', 'pipe', 'inherit'],
108
- });
109
-
110
- const [code, out] = await new Promise(resolve => {
111
- const chunks = [];
112
- proc.stdout.on('data', d => chunks.push(d.toString()));
113
- proc.on('close', (c) => resolve([c, chunks.join('')]));
114
- });
115
- clearInterval(ticker);
116
-
117
- if (code !== 0) {
118
- const err = out.slice(-300) || `exit ${code}`;
94
+ ctx.tuiStatus?.set(`📊 采集中: ${platformLabel(platform)}`);
95
+
96
+ const scriptResult = await spawnScript(
97
+ 'node',
98
+ [join(SCAN_SCRIPTS_DIR, 'run-scan.js'),
99
+ '--project-root', projectRoot, '--platform', platform, '--length', length],
100
+ { timeout: 120000 }
101
+ );
102
+
103
+ if (!scriptResult.ok) {
104
+ const err = (typeof scriptResult.error === 'object' && scriptResult.error !== null)
105
+ ? (scriptResult.error.message || JSON.stringify(scriptResult.error))
106
+ : String(scriptResult.error || '未知错误');
119
107
  notify(session, scan.notify({ type: 'failed', err }));
120
108
  return { kind: 'success', text: '' };
121
109
  }
122
110
 
111
+ // 解析 receipt
123
112
  let receipt;
124
- try { receipt = JSON.parse(out); } catch (_) {
113
+ try { receipt = JSON.parse(scriptResult.output); } catch (_) {
125
114
  notify(session, scan.notify({ type: 'parse_error' }));
126
115
  return { kind: 'success', text: '' };
127
116
  }