diff --git a/scripts/generateVencordPluginList.ts b/scripts/generateVencordPluginList.ts index 41620ba10..5f38509bf 100644 --- a/scripts/generateVencordPluginList.ts +++ b/scripts/generateVencordPluginList.ts @@ -49,6 +49,7 @@ interface PluginData { filePath: string; } const devs = {} as Record; +const equicordDevs = {} as Record; function getName(node: NamedDeclaration) { return node.name && isIdentifier(node.name) ? node.name.text : undefined; @@ -95,6 +96,37 @@ function parseDevs() { throw new Error("Could not find Devs constant"); } +function parseEquicordDevs() { + const file = createSourceFile("constants.ts", readFileSync("src/utils/constants.ts", "utf8"), ScriptTarget.Latest); + + for (const child of file.getChildAt(0).getChildren()) { + if (!isVariableStatement(child)) continue; + + const devsDeclaration = child.declarationList.declarations.find(d => hasName(d, "EquicordDevs")); + if (!devsDeclaration?.initializer || !isCallExpression(devsDeclaration.initializer)) continue; + + const value = devsDeclaration.initializer.arguments[0]; + + if (!isSatisfiesExpression(value) || !isObjectLiteralExpression(value.expression)) throw new Error("Failed to parse EquicordDevs: not an object literal"); + + for (const prop of value.expression.properties) { + const name = (prop.name as Identifier).text; + const value = isPropertyAssignment(prop) ? prop.initializer : prop; + + if (!isObjectLiteralExpression(value)) throw new Error(`Failed to parse EquicordDevs: ${name} is not an object literal`); + + equicordDevs[name] = { + name: (getObjectProp(value, "name") as StringLiteral).text, + id: (getObjectProp(value, "id") as BigIntLiteral).text.slice(0, -1) + }; + } + + return; + } + + throw new Error("Could not find EquicordDevs constant"); +} + async function parseFile(fileName: string) { const file = createSourceFile(fileName, await readFile(fileName, "utf8"), ScriptTarget.Latest); @@ -160,7 +192,7 @@ async function parseFile(fileName: string) { if (!isArrayLiteralExpression(value)) throw fail("authors is not an array literal"); data.authors = value.elements.map(e => { if (!isPropertyAccessExpression(e)) throw fail("authors array contains non-property access expressions"); - const d = devs[getName(e)!]; + const d = devs[getName(e)!] || equicordDevs[getName(e)!]; if (!d) throw fail(`couldn't look up author ${getName(e)}`); return d; }); @@ -227,6 +259,7 @@ function isPluginFile({ name }: { name: string; }) { (async () => { parseDevs(); + parseEquicordDevs(); const plugins = [] as PluginData[];