Skip to content

Commit

Permalink
Merge pull request #142 from towerofnix/cli-trace
Browse files Browse the repository at this point in the history
Add -t, --trace CLI option; enable TypeScript source maps
  • Loading branch information
PullJosh authored Jun 17, 2024
2 parents bed196c + 2d91c5a commit 27ed1dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
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

0 comments on commit 27ed1dc

Please sign in to comment.