This commit is contained in:
thororen1234 2025-04-04 21:40:18 -04:00
parent 92ac5787c0
commit f605231a36
No known key found for this signature in database
2 changed files with 36 additions and 23 deletions

View file

@ -169,17 +169,24 @@ async function parseFile(fileName: string) {
data.hasCommands = true;
if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal");
data.commands = value.elements.map((e) => {
if (!isObjectLiteralExpression(e)) throw fail("commands array contains non-object literals");
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
});
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
});
if (!nameProperty || !descriptionProperty) throw fail("Command missing required properties");
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
return { name, description };
if (isObjectLiteralExpression(e)) {
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
});
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
});
if (!nameProperty || !descriptionProperty) throw fail("command missing required properties");
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
return { name, description };
} else if (isCallExpression(e) && isIdentifier(e.expression)) {
const [nameArg] = e.arguments;
if (!isStringLiteral(nameArg)) throw fail("first argument must be a string");
const name = nameArg.text;
return { name, description: "" };
}
throw fail("commands array contains invalid elements");
});
break;
case "authors":

View file

@ -169,19 +169,25 @@ async function parseFile(fileName: string) {
data.hasCommands = true;
if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal");
data.commands = value.elements.map((e) => {
if (!isObjectLiteralExpression(e)) throw fail("commands array contains non-object literals");
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
});
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
});
if (!nameProperty || !descriptionProperty) throw fail("Command missing required properties");
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
return { name, description };
if (isObjectLiteralExpression(e)) {
const nameProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'name';
});
const descriptionProperty = e.properties.find((p): p is PropertyAssignment => {
return isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === 'description';
});
if (!nameProperty || !descriptionProperty) throw fail("command missing required properties");
const name = isStringLiteral(nameProperty.initializer) ? nameProperty.initializer.text : '';
const description = isStringLiteral(descriptionProperty.initializer) ? descriptionProperty.initializer.text : '';
return { name, description };
} else if (isCallExpression(e) && isIdentifier(e.expression)) {
const [nameArg] = e.arguments;
if (!isStringLiteral(nameArg)) throw fail("first argument must be a string");
const name = nameArg.text;
return { name, description: "" };
}
throw fail("commands array contains invalid elements");
});
break;
case "authors":
if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal");
data.authors = value.elements.map(e => {