diff --git a/scripts/generateEquicordPluginList.ts b/scripts/generateEquicordPluginList.ts index 5b551a2a7..d3f564237 100644 --- a/scripts/generateEquicordPluginList.ts +++ b/scripts/generateEquicordPluginList.ts @@ -167,27 +167,33 @@ async function parseFile(fileName: string) { break; case "commands": data.hasCommands = true; - if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal"); - data.commands = value.elements.map((e) => { - 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"); - }); + if (isArrayLiteralExpression(value)) { + data.commands = value.elements.map((e) => { + if (isObjectLiteralExpression(e)) { + const nameProperty = e.properties.find((p): p is PropertyAssignment => + isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === "name" + ); + const descriptionProperty = e.properties.find((p): p is PropertyAssignment => + 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"); + return { name: nameArg.text, description: "" }; + } else if (e.kind === SyntaxKind.SpreadElement) { + return undefined; + } + throw fail("commands array contains invalid elements"); + }).filter((c): c is { name: string; description: string; } => Boolean(c)) as Command[]; + } else if (isIdentifier(value)) { + data.commands = []; + } else { + throw fail("commands is not an array literal or identifier"); + } break; case "authors": if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal"); @@ -229,8 +235,7 @@ async function parseFile(fileName: string) { data.filePath = posixNormalize(fileName) .split(sep) .join(posixSep) - .replace(/\/index\.([jt]sx?)$/, "") - .replace(/^src\/equicordplugins\//, ""); + .replace(/\/index\.([jt]sx?)$/, ""); return [data] as const; } diff --git a/scripts/generatePluginList.ts b/scripts/generatePluginList.ts index facefa711..3e402264b 100644 --- a/scripts/generatePluginList.ts +++ b/scripts/generatePluginList.ts @@ -167,27 +167,33 @@ async function parseFile(fileName: string) { break; case "commands": data.hasCommands = true; - if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal"); - data.commands = value.elements.map((e) => { - 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"); - }); + if (isArrayLiteralExpression(value)) { + data.commands = value.elements.map((e) => { + if (isObjectLiteralExpression(e)) { + const nameProperty = e.properties.find((p): p is PropertyAssignment => + isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === "name" + ); + const descriptionProperty = e.properties.find((p): p is PropertyAssignment => + 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"); + return { name: nameArg.text, description: "" }; + } else if (e.kind === SyntaxKind.SpreadElement) { + return undefined; + } + throw fail("commands array contains invalid elements"); + }).filter((c): c is { name: string; description: string; } => Boolean(c)) as Command[]; + } else if (isIdentifier(value)) { + data.commands = []; + } else { + throw fail("commands is not an array literal or identifier"); + } break; case "authors": if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal"); diff --git a/scripts/generateVencordPluginList.ts b/scripts/generateVencordPluginList.ts index 5f38509bf..01b22cc8d 100644 --- a/scripts/generateVencordPluginList.ts +++ b/scripts/generateVencordPluginList.ts @@ -166,27 +166,33 @@ async function parseFile(fileName: string) { break; case "commands": data.hasCommands = true; - if (!isArrayLiteralExpression(value)) throw fail("commands is not an array literal"); - data.commands = value.elements.map((e) => { - 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"); - }); + if (isArrayLiteralExpression(value)) { + data.commands = value.elements.map((e) => { + if (isObjectLiteralExpression(e)) { + const nameProperty = e.properties.find((p): p is PropertyAssignment => + isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === "name" + ); + const descriptionProperty = e.properties.find((p): p is PropertyAssignment => + 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"); + return { name: nameArg.text, description: "" }; + } else if (e.kind === SyntaxKind.SpreadElement) { + return undefined; + } + throw fail("commands array contains invalid elements"); + }).filter((c): c is { name: string; description: string; } => Boolean(c)) as Command[]; + } else if (isIdentifier(value)) { + data.commands = []; + } else { + throw fail("commands is not an array literal or identifier"); + } break; case "authors": if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal"); @@ -228,8 +234,7 @@ async function parseFile(fileName: string) { data.filePath = posixNormalize(fileName) .split(sep) .join(posixSep) - .replace(/\/index\.([jt]sx?)$/, "") - .replace(/^src\/plugins\//, ""); + .replace(/\/index\.([jt]sx?)$/, ""); return [data] as const; } diff --git a/src/equicordplugins/moreCommands/index.ts b/src/equicordplugins/moreCommands/index.ts index 1bb528e01..19560cfee 100644 --- a/src/equicordplugins/moreCommands/index.ts +++ b/src/equicordplugins/moreCommands/index.ts @@ -26,7 +26,6 @@ import system from "./commands/system"; import text from "./commands/text"; import time from "./commands/time"; - migratePluginSettings("MoreCommands", "CuteAnimeBoys", "CuteNekos", "CutePats", "Slap"); export default definePlugin({ name: "MoreCommands",