From 0363c1fd5dcd9ba2912e6cf84665fb7c448d0fc1 Mon Sep 17 00:00:00 2001 From: Shibo Date: Thu, 26 Sep 2024 16:11:47 +0200 Subject: [PATCH 1/6] fixed filepath bug --- api/db/generic-json-level.ts | 2 +- api/db/get-db.ts | 2 +- cli/lib/cmd-fns/dev/check-if-initialized.ts | 2 +- cli/lib/cmd-fns/dev/index.ts | 2 +- .../dev/soupify-and-upload-example-file.ts | 2 +- .../cmd-fns/dev/start-edit-event-watcher.ts | 2 +- .../dev/upload-examples-from-directory.ts | 2 +- .../cmd-fns/init/create-or-modify-npmrc.ts | 2 +- cli/lib/cmd-fns/init/index.ts | 2 +- cli/lib/cmd-fns/open.ts | 2 +- cli/lib/cmd-fns/publish/index.ts | 2 +- cli/lib/cmd-fns/render.ts | 2 +- cli/lib/cmd-fns/soupify.ts | 2 +- cli/lib/export-fns/export-gerbers.ts | 6 +- cli/lib/export-fns/export-pnp-csv.ts | 2 +- cli/lib/soupify/get-tmp-entrpoint-filepath.ts | 2 +- cli/lib/soupify/run-entrypoint-file.ts | 34 +++++--- cli/lib/soupify/soupify-with-core.ts | 82 +++++++++---------- cli/lib/util/lint-project.ts | 2 +- cli/tests/export-gerber-keyboard.test.ts | 2 +- cli/tests/export-gerber.test.ts | 2 +- cli/tests/export-kicad-pcb.test.ts | 2 +- 22 files changed, 87 insertions(+), 73 deletions(-) diff --git a/api/db/generic-json-level.ts b/api/db/generic-json-level.ts index 80b37ce9..c8bb1bf6 100644 --- a/api/db/generic-json-level.ts +++ b/api/db/generic-json-level.ts @@ -5,7 +5,7 @@ import { AbstractValueIterator, } from "abstract-level" import { promises as fs } from "fs" -import path from "path" +import path from "path/posix" interface JSONLevelOptions {} diff --git a/api/db/get-db.ts b/api/db/get-db.ts index 3d9da27b..862aab86 100644 --- a/api/db/get-db.ts +++ b/api/db/get-db.ts @@ -1,5 +1,5 @@ import { mkdirSync } from "fs" -import * as Path from "path" +import * as Path from "path/posix" import { ZodLevelDatabase } from "./zod-level-db" let globalDb: ZodLevelDatabase | undefined diff --git a/cli/lib/cmd-fns/dev/check-if-initialized.ts b/cli/lib/cmd-fns/dev/check-if-initialized.ts index 5f2cea77..f72282da 100644 --- a/cli/lib/cmd-fns/dev/check-if-initialized.ts +++ b/cli/lib/cmd-fns/dev/check-if-initialized.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../util/app-context" import kleur from "kleur" -import * as Path from "path" +import * as Path from "path/posix" import { existsSync, readFileSync } from "fs" export const checkIfInitialized = async (ctx: AppContext) => { diff --git a/cli/lib/cmd-fns/dev/index.ts b/cli/lib/cmd-fns/dev/index.ts index 3feb2e70..f8ffde48 100644 --- a/cli/lib/cmd-fns/dev/index.ts +++ b/cli/lib/cmd-fns/dev/index.ts @@ -4,7 +4,7 @@ import fs from "fs" import kleur from "kleur" import posthog from "cli/lib/posthog" import open from "open" -import * as Path from "path" +import * as Path from "path/posix" import prompts from "prompts" import { z } from "zod" import { AppContext } from "../../util/app-context" diff --git a/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts b/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts index 9dc555b7..c2c0d612 100644 --- a/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts +++ b/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts @@ -1,5 +1,5 @@ import kleur from "kleur" -import { join as joinPath } from "path" +import { join as joinPath } from "path/posix" import { AxiosInstance } from "axios" import { readdirSync, readFileSync } from "fs" import { soupify } from "cli/lib/soupify" diff --git a/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts b/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts index 0635bd13..e43b84b0 100644 --- a/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts +++ b/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts @@ -5,7 +5,7 @@ import { AppContext } from "cli/lib/util/app-context" import fg from "fast-glob" import fs from "fs" import { Project, ts } from "ts-morph" -import * as Path from "path" +import * as Path from "path/posix" import { deriveSelectorFromPcbComponentId } from "./derive-selector-from-pcb-component-id" import type { EditEvent } from "@tscircuit/manual-edit-events" import { diff --git a/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts b/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts index 3ff87f44..0be267d6 100644 --- a/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts +++ b/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts @@ -1,5 +1,5 @@ import kleur from "kleur" -import { join as joinPath } from "path" +import { join as joinPath } from "path/posix" import { AxiosInstance } from "axios" import { readdirSync, readFileSync } from "fs" import { soupify } from "cli/lib/soupify" diff --git a/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts b/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts index e5ad0f76..d461f7f1 100644 --- a/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts +++ b/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts @@ -1,6 +1,6 @@ import { existsSync, writeFileSync } from "fs" import kleur from "kleur" -import * as Path from "path" +import * as Path from "path/posix" import { getGeneratedNpmrc } from "./get-generated-npmrc" import { AppContext } from "cli/lib/util/app-context" diff --git a/cli/lib/cmd-fns/init/index.ts b/cli/lib/cmd-fns/init/index.ts index 57a158af..6fcb2c3e 100644 --- a/cli/lib/cmd-fns/init/index.ts +++ b/cli/lib/cmd-fns/init/index.ts @@ -8,7 +8,7 @@ import { writeFile, appendFileSync, } from "fs" -import * as Path from "node:path" +import * as Path from "node:path/posix" import $ from "dax-sh" import { getGeneratedReadme } from "./get-generated-readme" import { getGeneratedTsconfig } from "./get-generated-tsconfig" diff --git a/cli/lib/cmd-fns/open.ts b/cli/lib/cmd-fns/open.ts index 623b9c73..e9c379d0 100644 --- a/cli/lib/cmd-fns/open.ts +++ b/cli/lib/cmd-fns/open.ts @@ -1,7 +1,7 @@ import { existsSync, readFileSync } from "fs" import kleur from "kleur" import { AppContext } from "cli/lib/util/app-context" -import * as Path from "path" +import * as Path from "path/posix" import open from "open" export const openCmd = async (ctx: AppContext, args: any) => { diff --git a/cli/lib/cmd-fns/publish/index.ts b/cli/lib/cmd-fns/publish/index.ts index b4d2e8ed..bfb713d7 100644 --- a/cli/lib/cmd-fns/publish/index.ts +++ b/cli/lib/cmd-fns/publish/index.ts @@ -1,7 +1,7 @@ import kleur from "kleur" import { z } from "zod" import { AppContext } from "../../util/app-context" -import * as Path from "path" +import * as Path from "path/posix" import * as fs from "fs/promises" import { existsSync, readFileSync } from "fs" import { getAllPackageFiles } from "cli/lib/util/get-all-package-files" diff --git a/cli/lib/cmd-fns/render.ts b/cli/lib/cmd-fns/render.ts index de63ba6e..282afee9 100644 --- a/cli/lib/cmd-fns/render.ts +++ b/cli/lib/cmd-fns/render.ts @@ -1,7 +1,7 @@ import { soupify } from "cli/lib/soupify" import type { AppContext } from "cli/lib/util/app-context" import fs from "fs" -import path from "path" +import path from "path/posix" export const renderCmd = async ( ctx: AppContext, diff --git a/cli/lib/cmd-fns/soupify.ts b/cli/lib/cmd-fns/soupify.ts index eb0c8838..eff3e92e 100644 --- a/cli/lib/cmd-fns/soupify.ts +++ b/cli/lib/cmd-fns/soupify.ts @@ -1,6 +1,6 @@ import { AppContext } from "../util/app-context" import { z } from "zod" -import * as Path from "path" +import * as Path from "path/posix" import { unlink } from "node:fs/promises" import { soupify } from "cli/lib/soupify" import { writeFileSync } from "fs" diff --git a/cli/lib/export-fns/export-gerbers.ts b/cli/lib/export-fns/export-gerbers.ts index 6df2d5ef..95fd50de 100644 --- a/cli/lib/export-fns/export-gerbers.ts +++ b/cli/lib/export-fns/export-gerbers.ts @@ -1,6 +1,6 @@ import { AppContext } from "../util/app-context" import { z } from "zod" -import * as Path from "path" +import * as Path from "path/posix" import { unlink } from "node:fs/promises" import { soupify } from "cli/lib/soupify" import * as fs from "fs" @@ -29,6 +29,7 @@ export const exportGerbersToFile = async ( }, ctx, ) + console.log(soup,'soup') console.log(kleur.gray("[soup to gerber json]...")) const gerber_layer_cmds = convertSoupToGerberCommands(soup, { @@ -91,7 +92,7 @@ export const exportGerbersToZipBuffer = async ( ) => { const tempDir = Path.join(".tscircuit", "tmp-gerber-zip") fs.mkdirSync(tempDir, { recursive: true }) - +console.log('step two') await exportGerbersToFile( { example_file_path: params.example_file_path, @@ -100,6 +101,7 @@ export const exportGerbersToZipBuffer = async ( }, ctx, ) + console.log('step last') const buffer = fs.readFileSync(Path.join(tempDir, "gerbers.zip")) diff --git a/cli/lib/export-fns/export-pnp-csv.ts b/cli/lib/export-fns/export-pnp-csv.ts index 512c2313..89800564 100644 --- a/cli/lib/export-fns/export-pnp-csv.ts +++ b/cli/lib/export-fns/export-pnp-csv.ts @@ -1,6 +1,6 @@ import { AppContext } from "../util/app-context" import { z } from "zod" -import * as Path from "path" +import * as Path from "path/posix" import { unlink } from "node:fs/promises" import { soupify } from "cli/lib/soupify" import { convertCircuitJsonToPickAndPlaceCsv } from "circuit-json-to-pnp-csv" diff --git a/cli/lib/soupify/get-tmp-entrpoint-filepath.ts b/cli/lib/soupify/get-tmp-entrpoint-filepath.ts index 4911c49d..6b008a89 100644 --- a/cli/lib/soupify/get-tmp-entrpoint-filepath.ts +++ b/cli/lib/soupify/get-tmp-entrpoint-filepath.ts @@ -1,4 +1,4 @@ -import Path from "node:path" +import Path from "node:path/posix" import fs from "fs/promises" export const getTmpEntrypointFilePath = async (filePath: string) => { diff --git a/cli/lib/soupify/run-entrypoint-file.ts b/cli/lib/soupify/run-entrypoint-file.ts index 4032e33b..59e5f354 100644 --- a/cli/lib/soupify/run-entrypoint-file.ts +++ b/cli/lib/soupify/run-entrypoint-file.ts @@ -17,44 +17,58 @@ 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) debug(`starting process....`) - const processResult = await processCmdPart1 - .stdout(debug.enabled ? "inheritPiped" : "piped") + console.log(debug.enabled) + + try{ + const processResult = await processCmdPart1 .stderr(debug.enabled ? "inheritPiped" : "piped") - .noThrow() - + .stdout(debug.enabled ? "inheritPiped" : "piped") + }catch(e){ + console.log(e) + } + + console.log(tmpOutputPath + ) const rawSoup = await readFile(tmpOutputPath, "utf-8") - const errText = processResult.stderr + // 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) + // writeFileSync(`.tscircuit/err-${t}.log`, rawSoup + "\n\n" + errText) + // throw new Error(errText) } +}catch(e){ + console.log(e) +} } diff --git a/cli/lib/soupify/soupify-with-core.ts b/cli/lib/soupify/soupify-with-core.ts index e06e6f37..f209477b 100644 --- a/cli/lib/soupify/soupify-with-core.ts +++ b/cli/lib/soupify/soupify-with-core.ts @@ -1,7 +1,7 @@ import { AppContext } from "../util/app-context" import { z } from "zod" import $ from "dax-sh" -import * as Path from "path" +import * as Path from "path/posix" import { unlink } from "node:fs/promises" import kleur from "kleur" import { writeFileSync } from "fs" @@ -22,53 +22,51 @@ export const soupifyWithCore = async ( ctx: Pick, ) => { let { filePath, exportName } = params - exportName ??= await getExportNameFromFile(filePath) - const { 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(() => {}) - debug(`writing to ${tmpEntrypointPath}`) writeFileSync( tmpEntrypointPath, ` -import React from "react" -import { Circuit } from "@tscircuit/core" -import * as EXPORTS from "./${Path.basename(filePath)}" -import { writeFileSync } from "node:fs" - -const Component = EXPORTS["${exportName}"] - -const project = new Circuit() - -try { - project.add() -} catch (e: any) { - console.log("[during .add()] ", e.toString()) - writeFileSync("${tmpOutputPath}", JSON.stringify({ - COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, - })) - throw e -} - -try { - project.render() -} catch (e: any) { - console.log(e.toString()) - writeFileSync("${tmpOutputPath}", JSON.stringify({ - COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, - })) - throw e -} - - -writeFileSync("${tmpOutputPath}", JSON.stringify(project.getCircuitJson())) -`.trim(), - ) - - return await runEntrypointFile({ tmpEntrypointPath, tmpOutputPath }, ctx) -} + import React from "react" + import { Circuit } from "@tscircuit/core" + import * as EXPORTS from "./${Path.basename(filePath)}" + import { writeFileSync } from "node:fs" + + const Component = EXPORTS["${exportName}"] + + const project = new Circuit() + + try { + project.add() + } catch (e: any) { + console.log("[during .add()] ", e.toString()) + writeFileSync("${tmpOutputPath}", JSON.stringify({ + COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, + })) + throw e + } + + try { + project.render() + } catch (e: any) { + console.log(e.toString()) + writeFileSync("${tmpOutputPath}", JSON.stringify({ + COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, + })) + throw e + } + + + writeFileSync("${tmpOutputPath}", JSON.stringify(project.getCircuitJson())) + `.trim(), + ) + + return await runEntrypointFile({ tmpEntrypointPath, tmpOutputPath }, ctx) + } + \ No newline at end of file diff --git a/cli/lib/util/lint-project.ts b/cli/lib/util/lint-project.ts index 3dadd117..73bbf40c 100644 --- a/cli/lib/util/lint-project.ts +++ b/cli/lib/util/lint-project.ts @@ -1,6 +1,6 @@ import * as ts from "typescript" import * as fs from "fs" -import * as path from "path" +import * as path from "path/posix" interface LintResult { filePath: string diff --git a/cli/tests/export-gerber-keyboard.test.ts b/cli/tests/export-gerber-keyboard.test.ts index 610f3754..a24a9076 100644 --- a/cli/tests/export-gerber-keyboard.test.ts +++ b/cli/tests/export-gerber-keyboard.test.ts @@ -1,7 +1,7 @@ import { test, expect, describe } from "bun:test" import { $ } from "bun" import { temporaryDirectory } from "tempy" -import { join } from "path" +import { join } from "path/posix" import { existsSync } from "fs" test("tsci export gerbers --input example-project/examples/macrokeypad.tsx", async () => { diff --git a/cli/tests/export-gerber.test.ts b/cli/tests/export-gerber.test.ts index 21709b8b..135844cf 100644 --- a/cli/tests/export-gerber.test.ts +++ b/cli/tests/export-gerber.test.ts @@ -1,7 +1,7 @@ import { test, expect, describe } from "bun:test" import { $ } from "bun" import { temporaryDirectory } from "tempy" -import { join } from "path" +import { join } from "path/posix" import { existsSync, readdirSync, readFileSync } from "fs" import extract from "extract-zip" import pcbStackup from "pcb-stackup" diff --git a/cli/tests/export-kicad-pcb.test.ts b/cli/tests/export-kicad-pcb.test.ts index 9ce7b342..b35ddce8 100644 --- a/cli/tests/export-kicad-pcb.test.ts +++ b/cli/tests/export-kicad-pcb.test.ts @@ -1,7 +1,7 @@ import { test, expect, describe } from "bun:test" import { $ } from "bun" import { temporaryDirectory } from "tempy" -import { join } from "path" +import { join } from "path/posix" import { existsSync, readFileSync } from "fs" test("tsci export kicad_pcb --input example-project/examples/macrokeypad.tsx", async () => { From 18bd4119deba5044b8a91762b2d31b3a99e27de9 Mon Sep 17 00:00:00 2001 From: Shibo Date: Thu, 26 Sep 2024 21:54:44 +0200 Subject: [PATCH 2/6] 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) +} From 16831e02e69738a37b3b1e50001c00958916cb55 Mon Sep 17 00:00:00 2001 From: Shibo Date: Fri, 27 Sep 2024 15:37:48 +0200 Subject: [PATCH 3/6] export now works for windows --- cli/lib/soupify/run-entrypoint-file.ts | 8 -------- cli/lib/util/create-context-and-run-program.ts | 6 +++++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/cli/lib/soupify/run-entrypoint-file.ts b/cli/lib/soupify/run-entrypoint-file.ts index 212f8a55..de812fe8 100644 --- a/cli/lib/soupify/run-entrypoint-file.ts +++ b/cli/lib/soupify/run-entrypoint-file.ts @@ -18,16 +18,12 @@ export const runEntrypointFile = async ( ctx: Pick, ) => { 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 @@ -36,12 +32,9 @@ export const runEntrypointFile = async ( } catch (e) { console.log(e) } - - 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) @@ -58,7 +51,6 @@ export const runEntrypointFile = async ( 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()}`)) diff --git a/cli/lib/util/create-context-and-run-program.ts b/cli/lib/util/create-context-and-run-program.ts index 731ec460..6db4a828 100644 --- a/cli/lib/util/create-context-and-run-program.ts +++ b/cli/lib/util/create-context-and-run-program.ts @@ -104,6 +104,10 @@ export const createContextAndRunProgram = async (process_args: any) => { }, ) + function isBunRuntime() { + return typeof process !== "undefined" && "isBun" in process + } + const ctx: AppContext = { cmd: args._, cwd: args.cwd ?? process.cwd(), @@ -112,7 +116,7 @@ export const createContextAndRunProgram = async (process_args: any) => { axios, global_config, profile_config, - runtime: global_config.get("runtime") ?? "node", + runtime: isBunRuntime() ? "bun" : (global_config.get("runtime") ?? "node"), args: { cmd: args._, yes: args.y ?? args.yes, From c623299de6477abda458f6b83c624a573675dafc Mon Sep 17 00:00:00 2001 From: Shibo Date: Fri, 27 Sep 2024 23:59:27 +0200 Subject: [PATCH 4/6] building static-routes now works on windows --- bun.lockb | Bin 560586 -> 560586 bytes package.json | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bun.lockb b/bun.lockb index d9f15ea425b1b687755d05a23cb699dca5e473a6..1308833fd772276b5d98500d3c8b19354f925723 100755 GIT binary patch delta 170 zcmV;b09F6Wnm=U YaJU7xaJU9tBmp^x&fEsK&fEw5uue`=7XSbN delta 170 zcmV;b09F6WndgE;SWX3tbfsf^(8+kIFp1M9K-O$MC}u!?&mh9)u}%tC z0ala2Rwt5I2!n`Mw}@8(J+DBNO5qXbKl&HtZ#;k>ED5tBtm=7r8~bYo1^3uLQQ?61 z2$VYp1d4)2hr6++-HAO$zKWLe)0?SS$oInuHaeJx1qT9$1qTC%1qTGT1qTIcu>m%R YaJU7xaJU9tBmp*u&fEsK&fEw5u(M}Mz5oCK diff --git a/package.json b/package.json index 91d1fbc4..f4e1e8f0 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "tempy": "^3.1.0", "ts-morph": "^22.0.0", "tsup": "^8.0.2", - "winterspec": "0.0.86", + "winterspec": "0.0.89", "zod": "^3.22.4" }, "peerDependencies": { From ac800523d30ad8b41d96de5f55be44663110c337 Mon Sep 17 00:00:00 2001 From: Shibo Date: Sat, 28 Sep 2024 16:24:18 +0200 Subject: [PATCH 5/6] cleanup --- cli/lib/soupify/run-entrypoint-file.ts | 71 ++++++++++++-------------- cli/lib/soupify/soupify-with-core.ts | 69 +++++++++++++------------ 2 files changed, 68 insertions(+), 72 deletions(-) diff --git a/cli/lib/soupify/run-entrypoint-file.ts b/cli/lib/soupify/run-entrypoint-file.ts index de812fe8..826bc910 100644 --- a/cli/lib/soupify/run-entrypoint-file.ts +++ b/cli/lib/soupify/run-entrypoint-file.ts @@ -17,49 +17,42 @@ export const runEntrypointFile = async ( }: { tmpEntrypointPath: string; tmpOutputPath: string }, ctx: Pick, ) => { - try { - debug(`using runtime ${ctx.runtime}`) - const processCmdPart1 = - ctx.runtime === "node" - ? $`npx tsx ${tmpEntrypointPath}` - : $`bun ${tmpEntrypointPath}` - debug(`starting process....`) + debug(`using runtime ${ctx.runtime}`) + const processCmdPart1 = + ctx.runtime === "node" + ? $`npx tsx ${tmpEntrypointPath}` + : $`bun ${tmpEntrypointPath}` + debug(`starting process....`) - try { - const processResult = await processCmdPart1 - .stderr(debug.enabled ? "inheritPiped" : "piped") - .stdout(debug.enabled ? "inheritPiped" : "piped") - } catch (e) { - console.log(e) - } - const rawSoup = await readFile(tmpOutputPath, "utf-8") - // const errText = processResult.stderr + const processResult = await processCmdPart1 + .stderr(debug.enabled ? "inheritPiped" : "piped") + .stdout(debug.enabled ? "inheritPiped" : "piped") - if (ctx.params.cleanup !== false) { - debug(`deleting ${tmpEntrypointPath}`) - await unlink(tmpEntrypointPath) - debug(`deleting ${tmpOutputPath}`) - await unlink(tmpOutputPath) - } + const rawSoup = await readFile(tmpOutputPath, "utf-8") + const errText = processResult.stderr - try { - debug(`parsing result of soupify...`) - const soup = JSON.parse(rawSoup) + 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) - } - 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) + 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) } - } catch (e) { - console.log(e) + 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) } } diff --git a/cli/lib/soupify/soupify-with-core.ts b/cli/lib/soupify/soupify-with-core.ts index 4524a088..95555cb1 100644 --- a/cli/lib/soupify/soupify-with-core.ts +++ b/cli/lib/soupify/soupify-with-core.ts @@ -22,49 +22,52 @@ export const soupifyWithCore = async ( ctx: Pick, ) => { let { filePath, exportName } = params + exportName ??= await getExportNameFromFile(filePath) - let { tmpEntrypointPath, tmpOutputPath } = + const { tmpEntrypointPath, tmpOutputPath } = await getTmpEntrypointFilePath(filePath) + // Remove existing entrypoint or tmp output files await fs.unlink(tmpEntrypointPath).catch(() => {}) await fs.unlink(tmpOutputPath).catch(() => {}) + debug(`writing to ${tmpEntrypointPath}`) writeFileSync( tmpEntrypointPath, ` - import React from "react" - import { Circuit } from "@tscircuit/core" - import * as EXPORTS from "./${Path.basename(filePath)}" - import { writeFileSync } from "node:fs" - - const Component = EXPORTS["${exportName}"] - - const project = new Circuit() - - try { - project.add() - } catch (e: any) { - console.log("[during .add()] ", e.toString()) - writeFileSync("${tmpOutputPath}", JSON.stringify({ - COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, - })) - throw e - } - - try { - project.render() - } catch (e: any) { - console.log(e.toString()) - writeFileSync("${tmpOutputPath}", JSON.stringify({ - COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, - })) - throw e - } - - - writeFileSync("${tmpOutputPath}", JSON.stringify(project.getCircuitJson())) - `.trim(), +import React from "react" +import { Circuit } from "@tscircuit/core" +import * as EXPORTS from "./${Path.basename(filePath)}" +import { writeFileSync } from "node:fs" + +const Component = EXPORTS["${exportName}"] + +const project = new Circuit() + +try { + project.add() +} catch (e: any) { + console.log("[during .add()] ", e.toString()) + writeFileSync("${tmpOutputPath}", JSON.stringify({ + COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, + })) + throw e +} + +try { + project.render() +} catch (e: any) { + console.log(e.toString()) + writeFileSync("${tmpOutputPath}", JSON.stringify({ + COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, + })) + throw e +} + + +writeFileSync("${tmpOutputPath}", JSON.stringify(project.getCircuitJson())) +`.trim(), ) return await runEntrypointFile({ tmpEntrypointPath, tmpOutputPath }, ctx) From 41540d25514e264de785bcfc576495c6c9775160 Mon Sep 17 00:00:00 2001 From: Shibo Date: Sat, 28 Sep 2024 17:18:47 +0200 Subject: [PATCH 6/6] cleanup 2 --- cli/lib/export-fns/export-gerbers.ts | 3 --- cli/lib/soupify/run-entrypoint-file.ts | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/cli/lib/export-fns/export-gerbers.ts b/cli/lib/export-fns/export-gerbers.ts index a7244ae4..8d5d576d 100644 --- a/cli/lib/export-fns/export-gerbers.ts +++ b/cli/lib/export-fns/export-gerbers.ts @@ -29,7 +29,6 @@ export const exportGerbersToFile = async ( }, ctx, ) - console.log(soup, "soup") console.log(kleur.gray("[soup to gerber json]...")) const gerber_layer_cmds = convertSoupToGerberCommands(soup, { @@ -92,7 +91,6 @@ export const exportGerbersToZipBuffer = async ( ) => { const tempDir = Path.join(".tscircuit", "tmp-gerber-zip") fs.mkdirSync(tempDir, { recursive: true }) - console.log("step two") await exportGerbersToFile( { example_file_path: params.example_file_path, @@ -101,7 +99,6 @@ export const exportGerbersToZipBuffer = async ( }, ctx, ) - 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 826bc910..434a609f 100644 --- a/cli/lib/soupify/run-entrypoint-file.ts +++ b/cli/lib/soupify/run-entrypoint-file.ts @@ -27,6 +27,7 @@ export const runEntrypointFile = async ( const processResult = await processCmdPart1 .stderr(debug.enabled ? "inheritPiped" : "piped") .stdout(debug.enabled ? "inheritPiped" : "piped") + .noThrow() const rawSoup = await readFile(tmpOutputPath, "utf-8") const errText = processResult.stderr