@cloud411716/fancy-webnovel 0.1.9 → 0.1.11
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
|
@@ -4,7 +4,6 @@
|
|
|
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';
|
|
8
7
|
|
|
9
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
9
|
const __dirname = dirname(__filename);
|
|
@@ -17,17 +16,19 @@ export async function apply(ctx) {
|
|
|
17
16
|
name: 'fancy-bootstrap',
|
|
18
17
|
description: '初始化项目根 (Usage)',
|
|
19
18
|
handler: async (invocation) => {
|
|
20
|
-
const debug = `[/tmp/fancy-bootstrap-debug.txt] rawInput=${JSON.stringify(invocation.rawInput)} keys=${JSON.stringify(Object.keys(invocation))}\n`;
|
|
21
|
-
appendFileSync('/tmp/fancy-bootstrap-debug.txt', debug);
|
|
22
19
|
const projectRoot = invocation.rawInput?.trim();
|
|
23
20
|
if (!projectRoot) {
|
|
24
|
-
return { kind: 'error', text:
|
|
21
|
+
return { kind: 'error', text: 'Usage: /fancy-bootstrap <project-root>' };
|
|
25
22
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
try {
|
|
24
|
+
const result = await runInit(projectRoot);
|
|
25
|
+
if (result.ok) {
|
|
26
|
+
return { kind: 'success', text: result.output };
|
|
27
|
+
} else {
|
|
28
|
+
return { kind: 'error', text: `Error: ${result.error ?? 'unknown'}` };
|
|
29
|
+
}
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return { kind: 'error', text: `Exception: ${e instanceof Error ? e.message : String(e)}` };
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
});
|
|
@@ -36,17 +37,16 @@ export async function apply(ctx) {
|
|
|
36
37
|
function runInit(projectRoot) {
|
|
37
38
|
return new Promise((resolve) => {
|
|
38
39
|
const scriptPath = join(__dirname, 'scripts', 'init.js');
|
|
39
|
-
const proc = spawn('
|
|
40
|
-
let stdout = '';
|
|
41
|
-
|
|
42
|
-
proc.
|
|
43
|
-
proc.stderr?.on('data', (data) => { stderr += data.toString(); });
|
|
40
|
+
const proc = spawn('node', [scriptPath, projectRoot], { timeout: 30000, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
41
|
+
let stdout = '', stderr = '';
|
|
42
|
+
proc.stdout.on('data', (data) => { stdout += data.toString(); });
|
|
43
|
+
proc.stderr.on('data', (data) => { stderr += data.toString(); });
|
|
44
44
|
proc.on('close', (code) => {
|
|
45
45
|
try {
|
|
46
46
|
const parsed = JSON.parse(stdout);
|
|
47
|
-
resolve({ ok: parsed.ok === true, output: stdout, error: stderr ||
|
|
47
|
+
resolve({ ok: parsed.ok === true, output: stdout, error: parsed.error ?? (parsed.ok ? undefined : stderr || `exit ${code}`) });
|
|
48
48
|
} catch {
|
|
49
|
-
resolve({ ok: false, output: stdout, error: stderr || `exit
|
|
49
|
+
resolve({ ok: false, output: stdout, error: stderr || `exit ${code}` });
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
proc.on('error', (err) => {
|
|
@@ -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
|
-
|
|
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
|
|