Skip to content

Commit

Permalink
fixed filepath bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiboSoftwareDev committed Sep 26, 2024
1 parent 1187321 commit 0363c1f
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 73 deletions.
2 changes: 1 addition & 1 deletion api/db/generic-json-level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
2 changes: 1 addition & 1 deletion api/db/get-db.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/dev/check-if-initialized.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/dev/start-edit-event-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/dev/upload-examples-from-directory.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/init/create-or-modify-npmrc.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/open.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/publish/index.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/render.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cmd-fns/soupify.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 4 additions & 2 deletions cli/lib/export-fns/export-gerbers.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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,
Expand All @@ -100,6 +101,7 @@ export const exportGerbersToZipBuffer = async (
},
ctx,
)
console.log('step last')

const buffer = fs.readFileSync(Path.join(tempDir, "gerbers.zip"))

Expand Down
2 changes: 1 addition & 1 deletion cli/lib/export-fns/export-pnp-csv.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/soupify/get-tmp-entrpoint-filepath.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
34 changes: 24 additions & 10 deletions cli/lib/soupify/run-entrypoint-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,58 @@ export const runEntrypointFile = async (
}: { tmpEntrypointPath: string; tmpOutputPath: string },
ctx: Pick<AppContext, "runtime" | "params">,
) => {
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)
}
}
82 changes: 40 additions & 42 deletions cli/lib/soupify/soupify-with-core.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -22,53 +22,51 @@ export const soupifyWithCore = async (
ctx: Pick<AppContext, "runtime" | "params">,
) => {
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(<Component />)
} 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(<Component />)
} 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)
}

2 changes: 1 addition & 1 deletion cli/lib/util/lint-project.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/export-gerber-keyboard.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/export-gerber.test.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/export-kicad-pcb.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down

0 comments on commit 0363c1f

Please sign in to comment.