@cloud411716/fancy-webnovel 0.1.17 → 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
|
@@ -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',
|
|
@@ -47,7 +53,7 @@ export async function apply(ctx) {
|
|
|
47
53
|
notify(session, '📍 使用当前路径:' + projectRoot);
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
if (
|
|
56
|
+
if (!isValidPath(projectRoot)) {
|
|
51
57
|
notify(session, '❌ 路径不合法(不能含空格、.. 或特殊字符)');
|
|
52
58
|
return { kind: 'success', text: '' };
|
|
53
59
|
}
|
|
@@ -64,7 +70,8 @@ export async function apply(ctx) {
|
|
|
64
70
|
],
|
|
65
71
|
}],
|
|
66
72
|
});
|
|
67
|
-
const
|
|
73
|
+
const ans = confirm.answers[0];
|
|
74
|
+
const chosen = ans?.selected?.[0] ?? ans?.custom;
|
|
68
75
|
if (chosen === '取消') {
|
|
69
76
|
notify(session, '🚫 已取消');
|
|
70
77
|
return { kind: 'success', text: '' };
|
|
@@ -90,13 +97,22 @@ export async function apply(ctx) {
|
|
|
90
97
|
function runScript(cmd, args) {
|
|
91
98
|
return new Promise((resolve) => {
|
|
92
99
|
const proc = spawn(cmd, args, { timeout: 30000, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
93
|
-
|
|
94
|
-
proc.stdout.on('data', (d) => {
|
|
95
|
-
proc.stderr.on('data', (d) => {
|
|
100
|
+
const outParts = [], errParts = [];
|
|
101
|
+
proc.stdout.on('data', (d) => { outParts.push(d.toString()); });
|
|
102
|
+
proc.stderr.on('data', (d) => { errParts.push(d.toString()); });
|
|
96
103
|
proc.on('close', (code) => {
|
|
104
|
+
const stdout = outParts.join(''), stderr = errParts.join('');
|
|
97
105
|
try {
|
|
98
106
|
const parsed = JSON.parse(stdout);
|
|
99
|
-
|
|
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
|
+
}
|
|
100
116
|
} catch (_) {
|
|
101
117
|
resolve({ ok: false, output: stdout, error: stderr || ('exit ' + code) });
|
|
102
118
|
}
|