node-asset-studio-mod 1.0.2 → 1.0.3
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/dist/index.js +30 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -126,12 +126,39 @@ export class AssetExporter {
|
|
|
126
126
|
console.log("exec:", cliPath, args.join(" "));
|
|
127
127
|
await new Promise((resolve, reject) => {
|
|
128
128
|
const proc = spawn(cliPath, args, { shell: true, windowsHide: true });
|
|
129
|
+
let settled = false; // 防止重复 resolve/reject
|
|
130
|
+
const fail = (err) => {
|
|
131
|
+
if (!settled) {
|
|
132
|
+
settled = true;
|
|
133
|
+
proc.kill(); // 终止子进程
|
|
134
|
+
reject(err);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
129
137
|
if (useLog) {
|
|
130
|
-
proc.stdout.on("data", (d) =>
|
|
131
|
-
|
|
138
|
+
proc.stdout.on("data", (d) => {
|
|
139
|
+
const text = d.toString();
|
|
140
|
+
process.stdout.write(text);
|
|
141
|
+
// 检测错误关键字
|
|
142
|
+
if (/error|exception|failed/i.test(text)) {
|
|
143
|
+
fail(new Error(`AssetStudio CLI runtime error: ${text}`));
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
proc.stderr.on("data", (d) => {
|
|
147
|
+
const text = d.toString();
|
|
148
|
+
process.stderr.write(text);
|
|
149
|
+
// stderr 一般就是错
|
|
150
|
+
if (/error|exception|failed/i.test(text)) {
|
|
151
|
+
fail(new Error(`AssetStudio CLI stderr error: ${text}`));
|
|
152
|
+
}
|
|
153
|
+
});
|
|
132
154
|
}
|
|
133
|
-
proc.on("error",
|
|
155
|
+
proc.on("error", (err) => {
|
|
156
|
+
fail(err);
|
|
157
|
+
});
|
|
134
158
|
proc.on("close", (code) => {
|
|
159
|
+
if (settled)
|
|
160
|
+
return; // 已经处理过
|
|
161
|
+
settled = true;
|
|
135
162
|
if (code === 0) {
|
|
136
163
|
resolve();
|
|
137
164
|
}
|