mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2025-12-17 06:14:21 +01:00
handle lsp errors
This commit is contained in:
committed by
Tony Giorgio
parent
3f36d5a475
commit
3d2195e6cf
35
scripts/errorsToTs.cjs
Normal file
35
scripts/errorsToTs.cjs
Normal 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.");
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user