handle lsp errors

This commit is contained in:
Paul Miller
2023-07-11 16:25:50 -05:00
committed by Tony Giorgio
parent 3f36d5a475
commit 3d2195e6cf
4 changed files with 203 additions and 40 deletions

35
scripts/errorsToTs.cjs Normal file
View File

@@ -0,0 +1,35 @@
const fs = require("fs").promises;
(async () => {
const filePath = process.argv[2]; // grab the file path from the command-line arguments
if (!filePath) {
console.error("Please provide a file path.");
process.exit(1);
}
let file;
try {
file = await fs.readFile(filePath, "utf-8");
} catch (error) {
console.error(`Failed to read file at path: ${filePath}`);
console.error(error);
process.exit(1);
}
const regex = /#\s*\[error\(\s*"([^"]*)"\s*\)\]/g;
let matches = file.match(regex);
if (matches) {
let errors = matches.map((match) => match.match(/"(.*?)"/)[1]); // capture text within ""
let typeScriptTypeString = `type MutinyError = "${errors.join(
'"\n\t| "'
)}";`;
console.log(typeScriptTypeString);
} else {
console.error("No matches found in the provided file.");
}
})();