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

Commit

Permalink
improved watching, errors appear on page
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Mar 19, 2024
1 parent 8c9d4e4 commit f6148bc
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 9 deletions.
11 changes: 9 additions & 2 deletions dev-server-api/routes/api/dev_package_examples/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,36 @@ export default withEdgeSpec({
file_path: z.string(),
export_name: z.string().default("default"),
tscircuit_soup: z.any(),
error: z.string().nullable().optional().default(null),
}),
jsonResponse: z.object({
dev_package_example: z.object({
dev_package_example_id: z.coerce.number(),
file_path: z.string(),
tscircuit_soup: z.any(),
error: z.string().nullable().optional(),
last_updated_at: z.string().datetime(),
}),
}),
auth: "none",
})(async (req, ctx) => {
const tscircuit_soup = req.jsonBody.tscircuit_soup
? JSON.stringify(req.jsonBody.tscircuit_soup)
: undefined
const dev_package_example = await ctx.db
.insertInto("dev_package_example")
.values({
file_path: req.jsonBody.file_path,
export_name: req.jsonBody.export_name,
tscircuit_soup: JSON.stringify(req.jsonBody.tscircuit_soup),
error: req.jsonBody.error,
tscircuit_soup,
last_updated_at: new Date().toISOString(),
})
.onConflict((oc) =>
oc.columns(["file_path"]).doUpdateSet({
export_name: req.jsonBody.export_name,
tscircuit_soup: JSON.stringify(req.jsonBody.tscircuit_soup),
error: req.jsonBody.error,
tscircuit_soup,
last_updated_at: new Date().toISOString(),
})
)
Expand Down
1 change: 1 addition & 0 deletions dev-server-api/routes/api/dev_package_examples/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default withEdgeSpec({
dev_package_example_id: z.coerce.number(),
file_path: z.string(),
tscircuit_soup: z.any(),
error: z.string().nullable().optional().default(null),
last_updated_at: z.string().datetime(),
}),
}),
Expand Down
5 changes: 4 additions & 1 deletion dev-server-api/routes/api/dev_package_examples/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export default withEdgeSpec({
methods: ["POST"],
jsonBody: z.object({
dev_package_example_id: z.coerce.number(),
tscircuit_soup: z.any(),
tscircuit_soup: z.any().optional(),
error: z.string().nullable().optional().default(null),
}),
jsonResponse: z.object({
dev_package_example: z.object({
dev_package_example_id: z.coerce.number(),
tscircuit_soup: z.any(),
error: z.string().nullable().optional(),
last_updated_at: z.string().datetime(),
}),
}),
Expand All @@ -22,6 +24,7 @@ export default withEdgeSpec({
.updateTable("dev_package_example")
.set({
tscircuit_soup: req.jsonBody.tscircuit_soup,
error: req.jsonBody.error,
last_updated_at: new Date().toISOString(),
})
.returningAll()
Expand Down
1 change: 1 addition & 0 deletions dev-server-api/src/db/create-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const createSchema = async (db: DbClient) => {
.addColumn("file_path", "text", (col) => col.unique())
.addColumn("export_name", "text")
.addColumn("tscircuit_soup", "json")
.addColumn("error", "text")
.addColumn("last_updated_at", "text")
.execute()
}
1 change: 1 addition & 0 deletions dev-server-api/src/db/get-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface DevPackageExample {
tscircuit_soup: any
file_path: string
export_name: string
error: string | null
last_updated_at: string
}

Expand Down
9 changes: 9 additions & 0 deletions dev-server-frontend/src/ExampleContentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export const ExampleContentView = () => {

const itemHeight =
viewMode === "split" && splitMode === "vertical" ? halfHeight : editorHeight
console.log(pkg)

return (
<div
key={pkg?.last_updated_at}
className={cn(
"relative",
`h-[${editorHeight}px]`,
viewMode === "split" &&
splitMode === "horizontal" &&
Expand All @@ -55,6 +57,13 @@ export const ExampleContentView = () => {
soup={pkg.tscircuit_soup}
/>
)}
{pkg?.error && (
<div className="absolute top-0 w-full">
<div className="bg-red-50 shadow-lg p-4 m-16 border-red-200 border rounded-lg whitespace-pre">
{pkg?.error}
</div>
</div>
)}
</div>
)
}
12 changes: 10 additions & 2 deletions lib/cmd-fns/dev/soupify-and-upload-example-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,26 @@ export const soupifyAndUploadExampleFile = async ({
const exportName = inferExportNameFromSource(exampleContent)

console.log(kleur.gray(`[soupifying] ${exampleFileName}...`))
const soup = await soupify({
const { soup, error } = await soupify({
filePath: examplePath,
exportName,
})
.then((soup) => ({ soup, error: null }))
.catch((e) => ({ error: e, soup: undefined }))

if (error) {
console.log(kleur.red(`[ error ] couldn't soupify ${exampleFileName}`))
console.log(error.toString())
}
console.log(kleur.gray(`[uploading ] ${exampleFileName}...`))
await devServerAxios.post("/api/dev_package_examples/create", {
tscircuit_soup: soup,
error: error?.toString() || null,
file_path: examplePath,
export_name: exportName,
})
console.log(kleur.gray(`[ done ] ${exampleFileName}!`))
} catch (e: any) {
console.log(kleur.red(e.toString()))
console.log(kleur.red(`[ error ] ${e.toString()}`))
}
}
1 change: 1 addition & 0 deletions lib/cmd-fns/dev/start-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const startWatcher = async ({
should_run: true,
}
watcher.on("change", async (path) => {
if (path.endsWith(".__tmp_entrypoint.tsx")) return
console.log(`File ${path} has been changed`)
// TODO analyze to determine which examples were impacted
upload_queue_state.dirty = true
Expand Down
11 changes: 7 additions & 4 deletions lib/soupify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ console.log(JSON.stringify(elements))
`.trim()
)

const processResult = await $`bun ${tmpFilePath}`.captureCombined(true)
const processResult = await $`npx tsx ${tmpFilePath}`
.stdout("piped")
.stderr("piped")
.noThrow()

const rawSoup = processResult.stdout
const errText = processResult.stderr
Expand All @@ -56,16 +59,16 @@ console.log(JSON.stringify(elements))

if (soup.COMPILE_ERROR) {
// console.log(kleur.red(`Failed to compile ${filePath}`))
// console.log(soup.COMPILE_ERROR)
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(`Outputting raw soupify result to .tscircuit/err-${t}.log`)
console.log(`Dumping raw output to .tscircuit/err-${t}.log`)
writeFileSync(`.tscircuit/err-${t}.log`, rawSoup + "\n\n" + errText)
throw e
throw new Error(errText)
}
}

0 comments on commit f6148bc

Please sign in to comment.