mirror of
https://github.com/nestriness/nestri.git
synced 2026-08-01 17:34:15 +03:00
feat: Fix yargs cli
This commit is contained in:
3
bun.lock
3
bun.lock
@@ -190,6 +190,9 @@
|
|||||||
},
|
},
|
||||||
"packages/studio": {
|
"packages/studio": {
|
||||||
"name": "@nestri/studio",
|
"name": "@nestri/studio",
|
||||||
|
"dependencies": {
|
||||||
|
"yargs": "^18.0.0",
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/bun": "catalog:",
|
"@tsconfig/bun": "catalog:",
|
||||||
"@types/bun": "catalog:",
|
"@types/bun": "catalog:",
|
||||||
|
|||||||
@@ -16,5 +16,8 @@
|
|||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@nestri/core": "workspace:^",
|
"@nestri/core": "workspace:^",
|
||||||
"@nestri/function": "workspace:^"
|
"@nestri/function": "workspace:^"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"yargs": "^18.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
packages/studio/src/error.ts
Normal file
26
packages/studio/src/error.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// import { ConfigMarkdown } from "@/config/markdown"
|
||||||
|
// import { Config } from "../config/config"
|
||||||
|
// import { UI } from "./ui"
|
||||||
|
|
||||||
|
export function FormatError(input: unknown) {
|
||||||
|
// if (Config.JsonError.isInstance(input)) {
|
||||||
|
// return (
|
||||||
|
// `Config file at ${input.data.path} is not valid JSON(C)` +
|
||||||
|
// (input.data.message ? `: ${input.data.message}` : "")
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
// if (Config.ConfigDirectoryTypoError.isInstance(input)) {
|
||||||
|
// return `Directory "${input.data.dir}" in ${input.data.path} is not valid. Use "${input.data.suggestion}" instead. This is a common typo.`
|
||||||
|
// }
|
||||||
|
// if (ConfigMarkdown.FrontmatterError.isInstance(input)) {
|
||||||
|
// return `Failed to parse frontmatter in ${input.data.path}:\n${input.data.message}`
|
||||||
|
// }
|
||||||
|
// if (Config.InvalidError.isInstance(input))
|
||||||
|
// return [
|
||||||
|
// `Config file at ${input.data.path} is invalid` +
|
||||||
|
// (input.data.message ? `: ${input.data.message}` : ""),
|
||||||
|
// ...(input.data.issues?.map((issue) => "↳ " + issue.message + " " + issue.path.join(".")) ??
|
||||||
|
// []),
|
||||||
|
// ].join("\n")
|
||||||
|
return "TODO: Format this error message";
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import yargs from "yargs";
|
import yargs from "yargs";
|
||||||
|
import { FormatError } from "./error";
|
||||||
import { hideBin } from "yargs/helpers";
|
import { hideBin } from "yargs/helpers";
|
||||||
import { Log } from "@nestri/core/utils/log";
|
import { Log } from "@nestri/core/utils/log";
|
||||||
|
import { NamedError } from "@nestri/core/utils/error";
|
||||||
import { Installation } from "@nestri/core/installation/index";
|
import { Installation } from "@nestri/core/installation/index";
|
||||||
|
|
||||||
process.on("unhandledRejection", (e) => {
|
process.on("unhandledRejection", (e) => {
|
||||||
@@ -16,8 +18,51 @@ process.on("uncaughtException", (e) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const cli = yargs(hideBin(process.argv))
|
const cli = yargs(hideBin(process.argv))
|
||||||
.scriptName("nestri-studio")
|
.scriptName("nestri")
|
||||||
.help("help", "Show help")
|
.help("help", "Show help")
|
||||||
.alias("h", "help")
|
.alias("h", "help")
|
||||||
.version("version", "show version number", Installation.VERSION)
|
.version("version", "show version number", Installation.VERSION)
|
||||||
.alias("v", "version");
|
.alias("v", "version");
|
||||||
|
|
||||||
|
try {
|
||||||
|
await cli.parse();
|
||||||
|
} catch (e) {
|
||||||
|
let data: Record<string, any> = {};
|
||||||
|
if (e instanceof NamedError) {
|
||||||
|
const obj = e.toObject();
|
||||||
|
Object.assign(data, {
|
||||||
|
...obj.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e instanceof Error) {
|
||||||
|
Object.assign(data, {
|
||||||
|
name: e.name,
|
||||||
|
message: e.message,
|
||||||
|
cause: e.cause?.toString(),
|
||||||
|
stack: e.stack,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e instanceof ResolveMessage) {
|
||||||
|
Object.assign(data, {
|
||||||
|
name: e.name,
|
||||||
|
message: e.message,
|
||||||
|
code: e.code,
|
||||||
|
specifier: e.specifier,
|
||||||
|
referrer: e.referrer,
|
||||||
|
position: e.position,
|
||||||
|
importKind: e.importKind,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Log.Default.error("fatal", data);
|
||||||
|
const formatted = FormatError(e);
|
||||||
|
// if (formatted) UI.error(formatted)
|
||||||
|
if (formatted === undefined) {
|
||||||
|
// UI.error("Unexpected error, check log file at " + Log.file() + " for more details" + EOL)
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
process.exitCode = 1;
|
||||||
|
} finally {
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user