Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
add errors to export_request in db, allow exporting tscircuit soup, a…
Browse files Browse the repository at this point in the history
…dd open in vs code option
  • Loading branch information
seveibar committed Apr 16, 2024
1 parent 69494e4 commit a3c36bf
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 15 deletions.
18 changes: 14 additions & 4 deletions dev-server-api/routes/api/export_requests/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@ export default withEdgeSpec({
methods: ["POST"],
jsonBody: z.object({
export_request_id: z.coerce.number(),
is_complete: z.boolean(),
is_complete: z.boolean().optional(),
has_error: z.boolean().optional(),
error: z.string().optional(),
}),
jsonResponse: z.object({}),
auth: "none",
})(async (req, ctx) => {
await ctx.db
.updateTable("export_request")
.set({
is_complete: req.jsonBody.is_complete ? 1 : 0,
})
.$if(req.jsonBody.is_complete !== undefined, (qb) =>
qb.set({
is_complete: req.jsonBody.is_complete ? 1 : 0,
})
)
.$if(req.jsonBody.has_error !== undefined, (qb) =>
qb.set({
has_error: req.jsonBody.has_error ? 1 : 0,
error: req.jsonBody.error,
})
)
.where("export_request_id", "=", req.jsonBody.export_request_id)
.execute()

Expand Down
2 changes: 2 additions & 0 deletions dev-server-api/src/db/create-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const createSchema = async (db: DbClient) => {
.addColumn("export_parameters", "json")
.addColumn("export_name", "text")
.addColumn("is_complete", "boolean", (col) => col.defaultTo(0).notNull())
.addColumn("has_error", "boolean", (col) => col.defaultTo(0).notNull())
.addColumn("error", "text")
.addColumn("created_at", "text")
.execute()

Expand Down
2 changes: 2 additions & 0 deletions dev-server-api/src/db/get-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface ExportRequest {
export_parameters: string
export_name: string
is_complete: 1 | 0
has_error: 1 | 0
error?: string
created_at: string
}

Expand Down
2 changes: 2 additions & 0 deletions dev-server-api/src/lib/zod/export_parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ export const export_parameters = z.object({
should_export_gerber_zip: z.boolean().default(false),
should_export_pnp_csv: z.boolean().default(false),
should_export_bom_csv: z.boolean().default(false),
should_export_soup_json: z.boolean().default(false),
gerbers_zip_file_name: z
.string()
.nullable()
.optional()
.default("gerbers.zip"),
pnp_csv_file_name: z.string().nullable().optional().default("pnp.csv"),
bom_csv_file_name: z.string().nullable().optional().default("bom.csv"),
soup_json_file_name: z.string().nullable().optional().default("soup.json"),
})

export type ExportParametersInput = z.input<typeof export_parameters>
Expand Down
Binary file modified dev-server-frontend/bun.lockb
Binary file not shown.
13 changes: 13 additions & 0 deletions dev-server-frontend/src/HeaderMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export const HeaderMenu = () => {
should_export_bom_csv: true,
},
})
const soupExportDialog = useGenericExportDialog({
dialogTitle: "Export tscircuit Soup",
dialogDescription:
"Export the tscircuit soup for this example export. This is an internal compiled JSON representation of your circuit.",
exportFileName: "soup.json",
exportParameters: {
should_export_soup_json: true,
},
})

return (
<>
Expand Down Expand Up @@ -92,6 +101,9 @@ export const HeaderMenu = () => {
>
Schematic (PDF)
</MenubarItem>
<MenubarItem onSelect={() => soupExportDialog.openDialog()}>
tscircuit Soup JSON
</MenubarItem>
</MenubarSubContent>
</MenubarSub>
</MenubarContent>
Expand Down Expand Up @@ -255,6 +267,7 @@ export const HeaderMenu = () => {
<gerberExportDialog.Component />
<pnpExportDialog.Component />
<bomExportDialog.Component />
<soupExportDialog.Component />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export const useGenericExportDialog = ({
if (exportParameters.should_export_bom_csv) {
exportParameters.bom_csv_file_name ??= exportFileName
}
if (exportParameters.should_export_soup_json) {
exportParameters.soup_json_file_name ??= exportFileName
}

let export_request = await axios
.post("/api/export_requests/create", {
Expand Down
30 changes: 30 additions & 0 deletions lib/cmd-fns/dev/fulfill-export-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AxiosInstance } from "axios"
import { ExportRequest } from "@server/lib/zod/export_request"
import { exportPnpCsvToBuffer } from "lib/export-fns/export-pnp-csv"
import { exportBomCsvToBuffer } from "lib/export-fns/export-bom-csv"
import { soupify } from "lib/soupify"

export const uploadBufferToExportFile = async ({
dev_server_axios,
Expand Down Expand Up @@ -59,6 +60,17 @@ export const fulfillExportRequests = async (

if (export_request.export_parameters.should_export_gerber_zip) {
console.log(kleur.gray(`\n exporting gerbers...`))
if (typeof Bun !== "undefined") {
const err_str =
"Bun currently isn't capable of exporting due to an archiver bug, exports will not work."
console.log(kleur.red(err_str))
await dev_server_axios.post("/api/export_requests/update", {
export_request_id: export_request.export_request_id,
has_error: true,
error: err_str,
})
return
}
const zip_buffer = await exportGerbersToZipBuffer(
{
example_file_path: export_request.example_file_path,
Expand Down Expand Up @@ -116,5 +128,23 @@ export const fulfillExportRequests = async (
export_request_id: export_request.export_request_id,
})
}

if (export_request.export_parameters.should_export_soup_json) {
console.log(kleur.gray(`\n exporting soup...`))
const soup = await soupify(
{
filePath: export_request.example_file_path,
exportName: export_request.export_name,
},
ctx
)

await uploadBufferToExportFile({
dev_server_axios,
file_buffer: Buffer.from(JSON.stringify(soup, null, 2), "utf-8"),
file_name: export_request.export_parameters.soup_json_file_name!,
export_request_id: export_request.export_request_id,
})
}
}
}
7 changes: 7 additions & 0 deletions lib/cmd-fns/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createOrModifyNpmrc } from "../init/create-or-modify-npmrc"
import { checkIfInitialized } from "./check-if-initialized"
import { initCmd } from "../init"
import { startExportRequestWatcher } from "./start-export-request-watcher"
import $ from "dax-sh"

export const devCmd = async (ctx: AppContext, args: any) => {
const params = z
Expand Down Expand Up @@ -88,6 +89,10 @@ export const devCmd = async (ctx: AppContext, args: any) => {
title: "Open in Browser",
value: "open-in-browser",
},
{
title: "Open Directory in VS Code",
value: "open-in-vs-code",
},
{
title: "Stop Server",
value: "stop",
Expand All @@ -96,6 +101,8 @@ export const devCmd = async (ctx: AppContext, args: any) => {
})
if (action === "open-in-browser") {
open(serverUrl)
} else if (action === "open-in-vs-code") {
await $`code ${cwd}`
} else if (!action || action === "stop") {
if (server.stop) server.stop()
if (server.close) server.close()
Expand Down
11 changes: 0 additions & 11 deletions lib/cmd-fns/dev/start-export-request-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ export const startExportRequestWatcher = async (
},
ctx: AppContext
) => {
if (typeof Bun !== "undefined") {
console.log(
kleur.yellow(
"Bun currently isn't capable of exporting due to an archiver bug, exports will not work."
)
)
return {
stop: () => {},
}
}

let running = true

;(async () => {
Expand Down

0 comments on commit a3c36bf

Please sign in to comment.