@cloud411716/fancy-webnovel 0.1.16 → 0.1.18

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.16",
3
+ "version": "0.1.18",
4
4
  "type": "module",
5
5
  "main": "plugins/fancy-bootstrap/index.js",
6
6
  "exports": {
@@ -21,6 +21,12 @@ function notify(session, text) {
21
21
  });
22
22
  }
23
23
 
24
+ const ILLEGAL_PATH_RE = /[<>:"|?*[\x00-\x1f]/;
25
+
26
+ function isValidPath(p) {
27
+ return !p.includes('..') && !ILLEGAL_PATH_RE.test(p) && !/\s/.test(p);
28
+ }
29
+
24
30
  export async function apply(ctx) {
25
31
  ctx.commands.register({
26
32
  name: 'fancy-bootstrap',
@@ -38,19 +44,24 @@ export async function apply(ctx) {
38
44
  }
39
45
 
40
46
  if (!projectRoot) {
41
- notify(session, '未提供路径,已取消');
47
+ notify(session, '⚠️ 未提供路径,已取消');
42
48
  return { kind: 'success', text: '' };
43
49
  }
44
50
 
45
- if (projectRoot.includes('..') || /[<>:"'|?*[\x00-\x1f]/.test(projectRoot) || /\s/.test(projectRoot)) {
46
- notify(session, '路径不合法(不能含空格、.. 或特殊字符)');
51
+ if (projectRoot === '.') {
52
+ projectRoot = process.cwd();
53
+ notify(session, '📍 使用当前路径:' + projectRoot);
54
+ }
55
+
56
+ if (!isValidPath(projectRoot)) {
57
+ notify(session, '❌ 路径不合法(不能含空格、.. 或特殊字符)');
47
58
  return { kind: 'success', text: '' };
48
59
  }
49
60
 
50
61
  const confirm = await ctx.userQuestions.ask({
51
62
  questions: [{
52
63
  id: 'confirm',
53
- question: '确认将以下路径作为项目根?',
64
+ question: '确认将以下路径作为项目根?',
54
65
  detail: projectRoot,
55
66
  hideCustomInput: true,
56
67
  options: [
@@ -59,21 +70,24 @@ export async function apply(ctx) {
59
70
  ],
60
71
  }],
61
72
  });
62
- const chosen = confirm.answers[0]?.selected ? confirm.answers[0].selected[0] : confirm.answers[0]?.custom;
73
+ const ans = confirm.answers[0];
74
+ const chosen = ans?.selected?.[0] ?? ans?.custom;
63
75
  if (chosen === '取消') {
64
- notify(session, '已取消');
76
+ notify(session, '🚫 已取消');
65
77
  return { kind: 'success', text: '' };
66
78
  }
67
79
 
80
+ notify(session, '⏳ 正在初始化项目...');
81
+
68
82
  const scriptPath = join(__dirname, 'scripts', 'init.js');
69
83
  const { ok, output, error } = await runScript('node', [scriptPath, projectRoot]);
70
84
 
71
85
  if (!ok) {
72
86
  let detail = error || output || '未知错误';
73
87
  try { detail = JSON.parse(output).error.message || detail; } catch (_) {}
74
- notify(session, '初始化失败:' + detail);
88
+ notify(session, '初始化失败:' + detail);
75
89
  } else {
76
- notify(session, '项目初始化完成:' + projectRoot + '\n\n下一步:/fancy-scan 扫榜分析');
90
+ notify(session, '项目初始化完成:' + projectRoot + '\n\n下一步:/fancy-scan 扫榜分析');
77
91
  }
78
92
  return { kind: 'success', text: '' };
79
93
  }
@@ -83,13 +97,22 @@ export async function apply(ctx) {
83
97
  function runScript(cmd, args) {
84
98
  return new Promise((resolve) => {
85
99
  const proc = spawn(cmd, args, { timeout: 30000, stdio: ['ignore', 'pipe', 'pipe'] });
86
- let stdout = '', stderr = '';
87
- proc.stdout.on('data', (d) => { stdout += d.toString(); });
88
- proc.stderr.on('data', (d) => { stderr += d.toString(); });
100
+ const outParts = [], errParts = [];
101
+ proc.stdout.on('data', (d) => { outParts.push(d.toString()); });
102
+ proc.stderr.on('data', (d) => { errParts.push(d.toString()); });
89
103
  proc.on('close', (code) => {
104
+ const stdout = outParts.join(''), stderr = errParts.join('');
90
105
  try {
91
106
  const parsed = JSON.parse(stdout);
92
- resolve({ ok: parsed.ok === true, output: stdout, error: parsed.error ? (parsed.error.message || JSON.stringify(parsed.error)) : stderr || undefined });
107
+ if (parsed.ok === true) {
108
+ resolve({ ok: true, output: stdout });
109
+ } else {
110
+ const e = parsed.error;
111
+ const msg = (typeof e === 'object' && e !== null)
112
+ ? (e.message || JSON.stringify(e))
113
+ : (e || stderr || ('exit ' + code));
114
+ resolve({ ok: false, output: stdout, error: msg });
115
+ }
93
116
  } catch (_) {
94
117
  resolve({ ok: false, output: stdout, error: stderr || ('exit ' + code) });
95
118
  }