diff --git a/src/cli.ts b/src/cli.ts index 9f0b2b2..691f022 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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} --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} \nExample:\n\t${myPackageName} ./index.js BetterDiscord ./dist/index.js`); process.exit(1); } @@ -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: { diff --git a/src/converter.ts b/src/converter.ts index 4d8b1a2..c8c87db 100644 --- a/src/converter.ts +++ b/src/converter.ts @@ -95,7 +95,7 @@ function deepFind(obj: any, path: string): K | undefined { return current; } -export default async function (ast: ParseResult, targetedDiscordModApiLibrary: { default: IModImplementation }): Promise { +export default async function (ast: ParseResult, targetedDiscordModApiLibrary: { default: IModImplementation }, shouldConvertFormat: boolean = true): Promise { const parsedBody = ast.program.body; const importStatements = parsedBody.filter(x => x.type == "ImportDeclaration") as Statement[]; const importAliasMap = [] as { internalName: string, codeName: string }[]; @@ -183,7 +183,7 @@ export default async function (ast: ParseResult, 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) return parsedBodyWithoutOurImports; return (targetedDiscordModApiLibrary as { default: IModImplementation } & { convertFormat: (ast_: Statement[]) => Statement[] }).convertFormat(parsedBodyWithoutOurImports); }