From 18bd4119deba5044b8a91762b2d31b3a99e27de9 Mon Sep 17 00:00:00 2001 From: Shibo Date: Thu, 26 Sep 2024 21:54:44 +0200 Subject: [PATCH] format --- cli/lib/export-fns/export-gerbers.ts | 6 +- cli/lib/soupify/run-entrypoint-file.ts | 99 +++++++++++++------------- cli/lib/soupify/soupify-with-core.ts | 13 ++-- 3 files changed, 58 insertions(+), 60 deletions(-) diff --git a/cli/lib/export-fns/export-gerbers.ts b/cli/lib/export-fns/export-gerbers.ts index 95fd50de..a7244ae4 100644 --- a/cli/lib/export-fns/export-gerbers.ts +++ b/cli/lib/export-fns/export-gerbers.ts @@ -29,7 +29,7 @@ export const exportGerbersToFile = async ( }, ctx, ) - console.log(soup,'soup') + console.log(soup, "soup") console.log(kleur.gray("[soup to gerber json]...")) const gerber_layer_cmds = convertSoupToGerberCommands(soup, { @@ -92,7 +92,7 @@ export const exportGerbersToZipBuffer = async ( ) => { const tempDir = Path.join(".tscircuit", "tmp-gerber-zip") fs.mkdirSync(tempDir, { recursive: true }) -console.log('step two') + console.log("step two") await exportGerbersToFile( { example_file_path: params.example_file_path, @@ -101,7 +101,7 @@ console.log('step two') }, ctx, ) - console.log('step last') + console.log("step last") const buffer = fs.readFileSync(Path.join(tempDir, "gerbers.zip")) diff --git a/cli/lib/soupify/run-entrypoint-file.ts b/cli/lib/soupify/run-entrypoint-file.ts index 59e5f354..212f8a55 100644 --- a/cli/lib/soupify/run-entrypoint-file.ts +++ b/cli/lib/soupify/run-entrypoint-file.ts @@ -17,58 +17,57 @@ export const runEntrypointFile = async ( }: { tmpEntrypointPath: string; tmpOutputPath: string }, ctx: Pick, ) => { - try{ - console.log(1) - debug(`using runtime ${ctx.runtime}`) - const processCmdPart1 = - ctx.runtime === "node" - ? $`npx tsx ${tmpEntrypointPath}` - : $`bun ${tmpEntrypointPath}` - console.log(2) + try { + console.log(1) + debug(`using runtime ${ctx.runtime}`) + const processCmdPart1 = + ctx.runtime === "node" + ? $`npx tsx ${tmpEntrypointPath}` + : $`bun ${tmpEntrypointPath}` + console.log(2) - debug(`starting process....`) - console.log(debug.enabled) - - try{ - const processResult = await processCmdPart1 - .stderr(debug.enabled ? "inheritPiped" : "piped") - .stdout(debug.enabled ? "inheritPiped" : "piped") - }catch(e){ - console.log(e) - } - - console.log(tmpOutputPath - ) - const rawSoup = await readFile(tmpOutputPath, "utf-8") - // const errText = processResult.stderr + debug(`starting process....`) + console.log(debug.enabled) - console.log(4) - if (ctx.params.cleanup !== false) { - debug(`deleting ${tmpEntrypointPath}`) - await unlink(tmpEntrypointPath) - debug(`deleting ${tmpOutputPath}`) - await unlink(tmpOutputPath) - } - - try { - debug(`parsing result of soupify...`) - const soup = JSON.parse(rawSoup) - - if (soup.COMPILE_ERROR) { - // console.log(kleur.red(`Failed to compile ${filePath}`)) - console.log(kleur.red(soup.COMPILE_ERROR)) - throw new Error(soup.COMPILE_ERROR) + try { + const processResult = await processCmdPart1 + .stderr(debug.enabled ? "inheritPiped" : "piped") + .stdout(debug.enabled ? "inheritPiped" : "piped") + } catch (e) { + console.log(e) } - console.log('final') - return soup - } catch (e: any) { - // console.log(kleur.red(`Failed to parse result of soupify: ${e.toString()}`)) - const t = Date.now() - console.log(`Dumping raw output to .tscircuit/err-${t}.log`) - // writeFileSync(`.tscircuit/err-${t}.log`, rawSoup + "\n\n" + errText) - // throw new Error(errText) + + console.log(tmpOutputPath) + const rawSoup = await readFile(tmpOutputPath, "utf-8") + // const errText = processResult.stderr + + console.log(4) + if (ctx.params.cleanup !== false) { + debug(`deleting ${tmpEntrypointPath}`) + await unlink(tmpEntrypointPath) + debug(`deleting ${tmpOutputPath}`) + await unlink(tmpOutputPath) + } + + try { + debug(`parsing result of soupify...`) + const soup = JSON.parse(rawSoup) + + if (soup.COMPILE_ERROR) { + // console.log(kleur.red(`Failed to compile ${filePath}`)) + console.log(kleur.red(soup.COMPILE_ERROR)) + throw new Error(soup.COMPILE_ERROR) + } + console.log("final") + return soup + } catch (e: any) { + // console.log(kleur.red(`Failed to parse result of soupify: ${e.toString()}`)) + const t = Date.now() + console.log(`Dumping raw output to .tscircuit/err-${t}.log`) + // writeFileSync(`.tscircuit/err-${t}.log`, rawSoup + "\n\n" + errText) + // throw new Error(errText) + } + } catch (e) { + console.log(e) } -}catch(e){ - console.log(e) -} } diff --git a/cli/lib/soupify/soupify-with-core.ts b/cli/lib/soupify/soupify-with-core.ts index f209477b..4524a088 100644 --- a/cli/lib/soupify/soupify-with-core.ts +++ b/cli/lib/soupify/soupify-with-core.ts @@ -24,8 +24,8 @@ export const soupifyWithCore = async ( let { filePath, exportName } = params exportName ??= await getExportNameFromFile(filePath) - - let { tmpEntrypointPath, tmpOutputPath } = await getTmpEntrypointFilePath(filePath) + let { tmpEntrypointPath, tmpOutputPath } = + await getTmpEntrypointFilePath(filePath) // Remove existing entrypoint or tmp output files await fs.unlink(tmpEntrypointPath).catch(() => {}) await fs.unlink(tmpOutputPath).catch(() => {}) @@ -65,8 +65,7 @@ export const soupifyWithCore = async ( writeFileSync("${tmpOutputPath}", JSON.stringify(project.getCircuitJson())) `.trim(), - ) - - return await runEntrypointFile({ tmpEntrypointPath, tmpOutputPath }, ctx) - } - \ No newline at end of file + ) + + return await runEntrypointFile({ tmpEntrypointPath, tmpOutputPath }, ctx) +}