From 924810e1ac654ba54745ad4b42bcc931c0b21bac Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 28 Apr 2024 18:45:26 -0500 Subject: [PATCH] refactor out --- src/commands/build.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/commands/build.ts b/src/commands/build.ts index 4efdf36..6b94b37 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -49,6 +49,13 @@ type BuildOptions = { env?: string; }; +const resolveBuildConfig = (path: string|undefined, language: string) => { + if(language === 'javascript') { + return path ?? p.resolve('jsconfig.json') + } + return path ?? p.resolve('tsconfig.json') +} + export async function build(options: Record) { if (!options.supressWarnings) { console.info(`${magentaBright('EXPERIMENTAL')}: This API has not been stabilized. add -W or --suppress-warnings flag to suppress`); @@ -57,13 +64,6 @@ export async function build(options: Record) { let buildConfig: Partial = {}; const buildConfigPath = p.resolve(options.project ?? 'sern.build.js'); - const resolveBuildConfig = (path: string|undefined, language: string) => { - if(language === 'javascript') { - return path ?? p.resolve('jsconfig.json') - } - return path ?? p.resolve('tsconfig.json') - } - const defaultBuildConfig = { defineVersion: true, format: options.format ?? 'esm', @@ -74,10 +74,7 @@ export async function build(options: Record) { }; if (pathExistsSync(buildConfigPath)) { //throwable, buildConfigPath may not exist - buildConfig = { - ...defaultBuildConfig, - ...(await import('file:///' + buildConfigPath)).default, - }; + buildConfig = { ...defaultBuildConfig, ...(await import('file:///' + buildConfigPath)).default }; } else { buildConfig = defaultBuildConfig; console.log('No build config found, defaulting'); @@ -197,14 +194,17 @@ export async function build(options: Record) { cwd: "./src/commands/" }); const commandNames = commandsPaths.map(p.parse) - const commandsImports = commandNames.map(fname => { - return `import ${fname.name} from "./${p.join(`./commands/${fname.base}`).split(p.sep).join(p.posix.sep)}"` + const commandsImports = commandNames.map((fname, i) => { + return `import m${i} from "./${p.join(`./commands/${fname.name}.js`).split(p.sep).join(p.posix.sep)}"` }); const commandMapTemplate = - `const commands = new Map();\n` + - commandNames.map(({ name }) => `commands.set(${name}.id, ${name})`).join("\n"); + `export const commands = new Map();\n` + + commandNames.map((_, i) => `commands.set(m${i}.meta.id, m${i})`).join("\n"); - + await writeFile("./dist/out.js", + commandsImports.join("\n") + '\n' + + commandMapTemplate); + console.log(entryPoints) console.log(commandsImports) console.log(commandMapTemplate)