@reliverse/rempts 1.7.25 → 1.7.27
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.
|
@@ -307,54 +307,24 @@ export async function showUsage(command, parserOptions = {}) {
|
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
export async function runMain(command, parserOptions = {}) {
|
|
310
|
-
if (typeof command.onLauncherInit === "function")
|
|
311
|
-
|
|
310
|
+
if (typeof command.onLauncherInit === "function") {
|
|
311
|
+
try {
|
|
312
|
+
await command.onLauncherInit();
|
|
313
|
+
} catch (err) {
|
|
314
|
+
relinka("error", "Error in onLauncherInit:", err);
|
|
315
|
+
if (parserOptions.autoExit !== false) process.exit(1);
|
|
316
|
+
throw err;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
312
319
|
try {
|
|
313
320
|
if (!parserOptions.fileBasedCmds && !command.commands) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const stack = err.stack?.split("\n");
|
|
319
|
-
if (stack) {
|
|
320
|
-
for (const line of stack) {
|
|
321
|
-
const match = /\((.*):(\d+):(\d+)\)/.exec(line) || /at (.*):(\d+):(\d+)/.exec(line);
|
|
322
|
-
if (match?.[1] && !match[1].includes("launcher-mod")) {
|
|
323
|
-
callerFile = match[1];
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
if (callerFile) {
|
|
329
|
-
callerDir = path.dirname(callerFile);
|
|
330
|
-
const rel = path.relative(process.cwd(), callerFile);
|
|
331
|
-
if (/app[/][^/]+[/]cmd\.(ts|js)$/.test(rel)) {
|
|
332
|
-
relinka(
|
|
333
|
-
"error",
|
|
334
|
-
`runMain() should not be called from a file-based subcommand: ${rel}
|
|
335
|
-
This can cause recursion or unexpected behavior.
|
|
336
|
-
Move your runMain() call to your main CLI entry file.`
|
|
337
|
-
);
|
|
338
|
-
process.exit(1);
|
|
339
|
-
}
|
|
340
|
-
const mainEntry = process.argv[1] ? path.resolve(process.argv[1]) : void 0;
|
|
341
|
-
if (mainEntry && path.resolve(callerFile) !== mainEntry) {
|
|
342
|
-
relinka(
|
|
343
|
-
"error",
|
|
344
|
-
`runMain() should only be called from your main CLI entry file.
|
|
345
|
-
Detected: ${callerFile}
|
|
346
|
-
Main entry: ${mainEntry}
|
|
347
|
-
This can cause recursion or unexpected behavior.`
|
|
348
|
-
);
|
|
349
|
-
process.exit(1);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
} catch (_e) {
|
|
353
|
-
}
|
|
354
|
-
const defaultCmdsRoot = path.resolve(callerDir, "app");
|
|
321
|
+
const mainEntry = process.argv[1] ? path.dirname(path.resolve(process.argv[1])) : process.cwd();
|
|
322
|
+
const defaultCmdsRoot = path.join(mainEntry, "src", "app");
|
|
323
|
+
const exists = await fs.pathExists(defaultCmdsRoot);
|
|
324
|
+
const finalCmdsRoot = exists ? defaultCmdsRoot : path.join(mainEntry, "app");
|
|
355
325
|
parserOptions.fileBasedCmds = {
|
|
356
326
|
enable: true,
|
|
357
|
-
cmdsRootPath:
|
|
327
|
+
cmdsRootPath: finalCmdsRoot
|
|
358
328
|
};
|
|
359
329
|
}
|
|
360
330
|
const rawArgv = process.argv.slice(2);
|