Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { transformSync } from "@babel/core";
import { IModImplementation } from "./api/ModImplementation.js";
// import { addCode } from "./api/RuntimeGenerators.js";

if (process.argv.length != 5) {
if (process.argv[5] != undefined && process.argv[5] !== "--entrypoint") {
console.error(`Usage:\n\t${myPackageName} <input file> <target client mod> <output file> --entrypoint\nExample:\n\t${myPackageName} ./index.js BetterDiscord ./dist/index.js --entrypoint`);
process.exit(1);
}
if (process.argv.length < 5) { // TODO: make a proper option parser
console.error(`Usage:\n\t${myPackageName} <input file> <target client mod> <output file>\nExample:\n\t${myPackageName} ./index.js BetterDiscord ./dist/index.js`);
process.exit(1);
}
Expand Down Expand Up @@ -48,7 +52,7 @@ const filler = import(url.pathToFileURL(`${__dirname}/converters/${targetDiscord
filler.then(async (x: { default: IModImplementation }) => {
if (x.default.importsForbidden)
console.warn('\x1b[33m%s\x1b[0m', `Warning: Target mod ${targetDiscordMod} requires your code to be bundled into single file`);
const out = await converter(ast as File & { errors: [] }, x);
const out = await converter(ast as File & { errors: [] }, x, process.argv[5] !== undefined ? process.argv[5] === "--entrypoint" : true);
const outMod = {
...ast,
program: {
Expand Down
4 changes: 2 additions & 2 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function deepFind<K>(obj: any, path: string): K | undefined {
return current;
}

export default async function (ast: ParseResult<File>, targetedDiscordModApiLibrary: { default: IModImplementation }): Promise<Statement[]> {
export default async function (ast: ParseResult<File>, targetedDiscordModApiLibrary: { default: IModImplementation }, shouldConvertFormat: boolean = true): Promise<Statement[]> {
const parsedBody = ast.program.body;
const importStatements = parsedBody.filter(x => x.type == "ImportDeclaration") as Statement[];
const importAliasMap = [] as { internalName: string, codeName: string }[];
Expand Down Expand Up @@ -183,7 +183,7 @@ export default async function (ast: ParseResult<File>, targetedDiscordModApiLibr
}
}
parsedBodyWithoutOurImports.unshift(...await addCode(targetedDiscordModApiLibrary.default));
if ((targetedDiscordModApiLibrary as { default: IModImplementation } & { convertFormat: (ast_: Statement[]) => Statement[] }).convertFormat == undefined)
if (shouldConvertFormat == false || (targetedDiscordModApiLibrary as { default: IModImplementation } & { convertFormat: (ast_: Statement[]) => Statement[] }).convertFormat == undefined)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, could you use !shouldConvertFormat ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if it is a string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

networking taught me to never trust the user

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldConvertFormat is a boolean. What "string" are you referencing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if somehow user passes a string to that function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!

return parsedBodyWithoutOurImports;
return (targetedDiscordModApiLibrary as { default: IModImplementation } & { convertFormat: (ast_: Statement[]) => Statement[] }).convertFormat(parsedBodyWithoutOurImports);
}