@cloud411716/fancy-webnovel 0.1.7 → 0.1.10

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.7",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "main": "plugins/fancy-bootstrap/index.js",
6
6
  "exports": {
@@ -4,6 +4,7 @@
4
4
  import { spawn } from 'child_process';
5
5
  import { fileURLToPath } from 'url';
6
6
  import { dirname, join } from 'path';
7
+ import { appendFileSync } from 'fs';
7
8
 
8
9
  const __filename = fileURLToPath(import.meta.url);
9
10
  const __dirname = dirname(__filename);
@@ -22,9 +23,10 @@ export async function apply(ctx) {
22
23
  }
23
24
  const result = await runInit(projectRoot);
24
25
  if (result.ok) {
25
- return { kind: 'success', text: `Done: ${result.output}` };
26
+ return { kind: 'success', text: result.output };
26
27
  } else {
27
- return { kind: 'error', text: `Error: ${result.error}` };
28
+ const err = result.error ?? `exit code ${result.code ?? 'unknown'}`;
29
+ return { kind: 'error', text: `Error: ${err}` };
28
30
  }
29
31
  }
30
32
  });
@@ -34,20 +36,19 @@ function runInit(projectRoot) {
34
36
  return new Promise((resolve) => {
35
37
  const scriptPath = join(__dirname, 'scripts', 'init.js');
36
38
  const proc = spawn('npx', ['tsx', scriptPath, projectRoot], { timeout: 60000 });
37
- let stdout = '';
38
- let stderr = '';
39
+ let stdout = '', stderr = '';
39
40
  proc.stdout?.on('data', (data) => { stdout += data.toString(); });
40
41
  proc.stderr?.on('data', (data) => { stderr += data.toString(); });
41
42
  proc.on('close', (code) => {
42
43
  try {
43
44
  const parsed = JSON.parse(stdout);
44
- resolve({ ok: parsed.ok === true, output: stdout, error: stderr || undefined });
45
+ resolve({ ok: parsed.ok === true, output: stdout, error: stderr || undefined, code });
45
46
  } catch {
46
- resolve({ ok: false, output: stdout, error: stderr || `exit code ${code}` });
47
+ resolve({ ok: false, output: stdout, error: stderr || `exit code ${code}`, code });
47
48
  }
48
49
  });
49
50
  proc.on('error', (err) => {
50
- resolve({ ok: false, output: '', error: err.message });
51
+ resolve({ ok: false, output: '', error: err.message, code: null });
51
52
  });
52
53
  });
53
54
  }
@@ -27,6 +27,12 @@ function nowIso() {
27
27
  function main() {
28
28
  const projectRootRaw = process.argv[2] ?? '';
29
29
 
30
+ // 调试:打印接收到的参数
31
+ console.error(`[/tmp/fancy-init-debug.txt] argv=${JSON.stringify(process.argv)} raw=${projectRootRaw}`);
32
+ try {
33
+ require('fs').appendFileSync('/tmp/fancy-init-debug.txt', `argv=${JSON.stringify(process.argv)}\nraw=${projectRootRaw}\n`);
34
+ } catch(e) {}
35
+
30
36
  if (projectRootRaw.includes('..') || /[<>:"'|?*]/.test(projectRootRaw) || /[\x00-\x1f]/.test(projectRootRaw)) {
31
37
  console.log(JSON.stringify({ ok: false, error: { code: 1, code_name: 'EC001', message: '路径不合法' } }));
32
38
  process.exit(1);
@@ -95,7 +101,9 @@ function main() {
95
101
  writeFileSync(joinPath(archive, '_author_intent.md'), intentMd, 'utf-8');
96
102
 
97
103
  } catch (e) {
98
- console.log(JSON.stringify({ ok: false, error: { code: 17, code_name: 'EC017', message: `初始化失败: ${e instanceof Error ? e.message : String(e)}` } }));
104
+ const errMsg = e instanceof Error ? e.message : String(e);
105
+ try { require('fs').appendFileSync('/tmp/fancy-init-debug.txt', `catch: ${errMsg}\n`); } catch(_) {}
106
+ console.log(JSON.stringify({ ok: false, error: { code: 17, code_name: 'EC017', message: `初始化失败: ${errMsg}` } }));
99
107
  process.exit(17);
100
108
  }
101
109