Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -t, --trace CLI option; enable TypeScript source maps #142

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ program
.requiredOption("-i, --input <path>", "The path to the input project")
.addOption(new Option("-it, --input-type <type>", "The type of input file").choices(["sb3"]))
.requiredOption("-o, --output <path>", "The path to the output project")
.addOption(new Option("-ot, --output-type <type>", "The type of output file").choices(["leopard", "leopard-zip"]));
.addOption(new Option("-ot, --output-type <type>", "The type of output file").choices(["leopard", "leopard-zip"]))
.addOption(new Option("-t, --trace", "Show a detailed error trace"));

program.parse();

Expand All @@ -25,6 +26,7 @@ const options: {
inputType: "sb3";
output: string;
outputType: "leopard" | "leopard-zip";
trace: boolean | undefined;
} = program.opts();

let { input, inputType, output, outputType } = options;
Expand Down Expand Up @@ -106,14 +108,22 @@ async function run() {
value = await fn();
process.stdout.write(chalk.bold.green(" Done.\n"));
} catch (err) {
const indent = " ".repeat(4 + String(thisStepNumber).length);
if (err instanceof StepError) {
process.stdout.write(chalk.bold.red(`\n${" ".repeat(4 + String(thisStepNumber).length)}${err.message}`));
process.stdout.write(chalk.bold.red(`\n${indent}${err.message}`));
process.stdout.write(chalk.red(`\n\nProject conversion failed.\n`));
} else {
process.stdout.write(
chalk.bold.red`\n${" ".repeat(4 + String(thisStepNumber).length)}An unknown error occurred.`
);
process.stderr.write(chalk.red`\n\n${err}\n`);
process.stdout.write(chalk.bold.red`\n${indent}An unknown error occurred.`);
process.stdout.write(chalk.red`\n${indent}The JavaScript details are shown below.`);
process.stdout.write(chalk.red`\n${indent}This is a bug, please share the project you used on:`);
process.stdout.write(`\n${indent}https://github.com/leopard-js/sb-edit/issues`);
process.stdout.write(`\n\n`);

if (options.trace && err instanceof Error) {
console.error(err.stack);
} else {
console.error(String(err));
}
}
process.exit(1);
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"declaration": true,
"outDir": "./lib",
"strict": true,
"esModuleInterop": true
"esModuleInterop": true,
"inlineSourceMap": true
},
"include": ["src"],
"exclude": ["node_modules", "**/*.test.ts"]
Expand Down
Loading