node-asset-studio-mod 1.0.2 → 1.0.4
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 +31 -4
- package/package.json +1 -1
- package/scripts/download-cli.js +11 -10
package/dist/index.js
CHANGED
|
@@ -89,7 +89,7 @@ export class AssetExporter {
|
|
|
89
89
|
fs.mkdirSync(output, { recursive: true });
|
|
90
90
|
let cliPath = cfg.cliPath || this.getDefaultCliPath();
|
|
91
91
|
if (!cliPath)
|
|
92
|
-
throw new Error("Cannot find AssetStudioModCLI,please run `pnpm install` or check the folder /bin");
|
|
92
|
+
throw new Error("Cannot find AssetStudioModCLI,please run `npm/yarn/pnpm install` or check the folder /bin");
|
|
93
93
|
let types = "all";
|
|
94
94
|
if (cfg.assetType) {
|
|
95
95
|
types = Array.isArray(cfg.assetType) ? cfg.assetType.join(",") : cfg.assetType;
|
|
@@ -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 (/\[Warning] No Unity file can be loaded/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
|
}
|
package/package.json
CHANGED
package/scripts/download-cli.js
CHANGED
|
@@ -16,12 +16,13 @@ async function checkDotnet() {
|
|
|
16
16
|
try {
|
|
17
17
|
const out = execSync('dotnet --list-runtimes').toString();
|
|
18
18
|
if (out.includes('Microsoft.NETCore.App 9.')) {
|
|
19
|
-
console.log('
|
|
19
|
+
console.log('.NET 9 Runtime Found');
|
|
20
20
|
return true;
|
|
21
21
|
}
|
|
22
22
|
} catch {}
|
|
23
|
-
console.
|
|
24
|
-
|
|
23
|
+
console.error(`
|
|
24
|
+
.NET 9 Runtime Not Found.
|
|
25
|
+
Please install before using this package.
|
|
25
26
|
Windows (.NET Desktop): https://dotnet.microsoft.com/download/dotnet/9.0
|
|
26
27
|
Linux/macOS (.NET Runtime): https://dotnet.microsoft.com/download/dotnet/9.0
|
|
27
28
|
`);
|
|
@@ -81,28 +82,28 @@ async function extract() {
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
async function main() {
|
|
84
|
-
await checkDotnet();
|
|
85
|
+
if (!await checkDotnet()) throw new Error('Please install dotnet');
|
|
85
86
|
|
|
86
87
|
const url = getDownloadURL();
|
|
87
88
|
const urls = [...mirrorURLs(url), url];
|
|
88
89
|
|
|
89
90
|
for (const u of urls) {
|
|
90
91
|
try {
|
|
91
|
-
console.log('
|
|
92
|
+
console.log('trying to download:', u);
|
|
92
93
|
await download(u);
|
|
93
|
-
console.log('
|
|
94
|
+
console.log('download successfully:', u);
|
|
94
95
|
await extract();
|
|
95
|
-
console.log('AssetStudioModCLI
|
|
96
|
+
console.log('extract AssetStudioModCLI successfully');
|
|
96
97
|
fs.unlinkSync(zipPath);
|
|
97
|
-
console.log('
|
|
98
|
+
console.log('clean temp file: cli.zip');
|
|
98
99
|
return;
|
|
99
100
|
} catch (err) {
|
|
100
|
-
console.log(`✘
|
|
101
|
+
console.log(`✘ Fail: ${u}`);
|
|
101
102
|
console.log(err.message);
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
console.error('
|
|
106
|
+
console.error('Download AssetStudioModCLI Fail, Please install in another way');
|
|
106
107
|
process.exit(1);
|
|
107
108
|
}
|
|
108
109
|
|