Haha Funny Moment

This commit is contained in:
thororen 2024-05-04 01:10:12 -04:00
parent 1a37064f2e
commit c21e29f3d7
4 changed files with 40 additions and 6 deletions

View file

@ -44,6 +44,7 @@ interface PluginData {
}
const devs = {} as Record<string, Dev>;
const equicordDevs = {} as Record<string, Dev>;
function getName(node: NamedDeclaration) {
return node.name && isIdentifier(node.name) ? node.name.text : undefined;
@ -90,6 +91,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);
@ -134,7 +166,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;
});
@ -205,6 +237,7 @@ function isPluginFile({ name }: { name: string; }) {
(async () => {
parseDevs();
parseEquicordDevs();
const plugins = [] as PluginData[];
const readmes = {} as Record<string, string>;