@tscircuit/cli 0.0.61 → 0.0.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/cli.ts +4 -2
  2. package/dev-server-api/bun.lockb +0 -0
  3. package/dev-server-api/routes/api/export_files/create.ts +32 -0
  4. package/dev-server-api/routes/api/export_files/download.ts +24 -0
  5. package/dev-server-api/routes/api/export_requests/create.ts +17 -49
  6. package/dev-server-api/routes/api/export_requests/get.ts +37 -0
  7. package/dev-server-api/routes/api/export_requests/list.ts +28 -0
  8. package/dev-server-api/routes/api/export_requests/update.ts +26 -0
  9. package/dev-server-api/src/db/create-schema.ts +1 -1
  10. package/dev-server-api/src/db/get-db.ts +4 -4
  11. package/dev-server-api/src/lib/public-mapping/public-map-export-file.ts +17 -0
  12. package/dev-server-api/src/lib/public-mapping/public-map-export-request.ts +23 -0
  13. package/dev-server-api/src/lib/zod/export_file.ts +8 -0
  14. package/dev-server-api/src/lib/zod/export_parameters.ts +10 -0
  15. package/dev-server-api/src/lib/zod/export_request.ts +19 -0
  16. package/dev-server-frontend/src/components/dialogs/gerber-export-dialog.tsx +45 -8
  17. package/dist/cli.js +356 -114
  18. package/lib/cmd-fns/dev/fulfill-export-requests.ts +56 -0
  19. package/lib/cmd-fns/dev/index.ts +5 -2
  20. package/lib/cmd-fns/dev/start-export-request-watcher.ts +39 -0
  21. package/lib/cmd-fns/dev/upload-examples-from-directory.ts +5 -1
  22. package/lib/cmd-fns/dev-server-fulfill-export-requests.ts +43 -0
  23. package/lib/cmd-fns/index.ts +1 -0
  24. package/lib/export-gerbers.ts +10 -0
  25. package/lib/get-program.ts +4 -0
  26. package/package.json +1 -1
  27. package/dev-server-api/routes/api/export_files/create_or_update.ts +0 -0
@@ -0,0 +1,56 @@
1
+ import { AppContext } from "../../util/app-context"
2
+ import kleur from "kleur"
3
+ import { exportGerbersToZipBuffer } from "lib/export-gerbers"
4
+ import { AxiosInstance } from "axios"
5
+
6
+ export const fulfillExportRequests = async (
7
+ {
8
+ dev_server_axios,
9
+ }: {
10
+ dev_server_axios: AxiosInstance
11
+ },
12
+ ctx: AppContext
13
+ ) => {
14
+ const export_requests = await dev_server_axios
15
+ .post("/api/export_requests/list", {
16
+ is_complete: false,
17
+ })
18
+ .then((r) => r.data.export_requests)
19
+
20
+ for (const export_request of export_requests) {
21
+ console.log(kleur.gray(`Fulfilling export request ${export_request.id}`))
22
+ console.log(
23
+ kleur.gray(` example_file_path: ${export_request.example_file_path}`)
24
+ )
25
+
26
+ console.log(kleur.gray(`\n exporting gerbers...`))
27
+ const zip_buffer = await exportGerbersToZipBuffer(
28
+ {
29
+ example_file_path: export_request.example_file_path,
30
+ export_name: export_request.export_name,
31
+ },
32
+ ctx
33
+ )
34
+
35
+ console.log(
36
+ kleur.gray(
37
+ ` uploading zip "${export_request.export_parameters.gerbers_zip_file_name}" to dev server...`
38
+ )
39
+ )
40
+
41
+ await dev_server_axios.post("/api/export_files/create", {
42
+ file_content_base64: zip_buffer.toString("base64"),
43
+ file_name: export_request.export_parameters.gerbers_zip_file_name,
44
+ export_request_id: export_request.export_request_id,
45
+ })
46
+
47
+ console.log(kleur.gray(` marking export request as complete...`))
48
+
49
+ await dev_server_axios.post("/api/export_requests/update", {
50
+ export_request_id: export_request.export_request_id,
51
+ is_complete: true,
52
+ })
53
+
54
+ console.log(kleur.green(` done`))
55
+ }
56
+ }
@@ -12,6 +12,7 @@ import { startFsWatcher } from "./start-fs-watcher"
12
12
  import { createOrModifyNpmrc } from "../init/create-or-modify-npmrc"
13
13
  import { checkIfInitialized } from "./check-if-initialized"
14
14
  import { initCmd } from "../init"
15
+ import { startExportRequestWatcher } from "./start-export-request-watcher"
15
16
 
16
17
  export const devCmd = async (ctx: AppContext, args: any) => {
17
18
  const params = z
@@ -74,7 +75,8 @@ export const devCmd = async (ctx: AppContext, args: any) => {
74
75
  await uploadExamplesFromDirectory({ devServerAxios, cwd }, ctx)
75
76
 
76
77
  // Start watcher
77
- const watcher = await startFsWatcher({ cwd, devServerAxios }, ctx)
78
+ const fs_watcher = await startFsWatcher({ cwd, devServerAxios }, ctx)
79
+ const er_watcher = await startExportRequestWatcher({ devServerAxios }, ctx)
78
80
 
79
81
  while (true) {
80
82
  const { action } = await prompts({
@@ -97,7 +99,8 @@ export const devCmd = async (ctx: AppContext, args: any) => {
97
99
  } else if (!action || action === "stop") {
98
100
  if (server.stop) server.stop()
99
101
  if (server.close) server.close()
100
- watcher.stop()
102
+ fs_watcher.stop()
103
+ er_watcher.stop()
101
104
  break
102
105
  }
103
106
  }
@@ -0,0 +1,39 @@
1
+ import { AxiosInstance } from "axios"
2
+ import kleur from "kleur"
3
+ import { fulfillExportRequests } from "./fulfill-export-requests"
4
+ import { AppContext } from "lib/util/app-context"
5
+
6
+ export const startExportRequestWatcher = async (
7
+ {
8
+ devServerAxios,
9
+ }: {
10
+ devServerAxios: AxiosInstance
11
+ },
12
+ ctx: AppContext
13
+ ) => {
14
+ if (typeof Bun !== "undefined") {
15
+ console.log(
16
+ kleur.yellow(
17
+ "Bun currently isn't capable of exporting due to an archiver bug, exports will not work."
18
+ )
19
+ )
20
+ return {
21
+ stop: () => {},
22
+ }
23
+ }
24
+
25
+ let running = true
26
+
27
+ ;(async () => {
28
+ while (running) {
29
+ await fulfillExportRequests({ dev_server_axios: devServerAxios }, ctx)
30
+ await new Promise((resolve) => setTimeout(resolve, 100))
31
+ }
32
+ })()
33
+
34
+ return {
35
+ stop: () => {
36
+ running = false
37
+ },
38
+ }
39
+ }
@@ -5,6 +5,7 @@ import { readdirSync, readFileSync } from "fs"
5
5
  import { soupify } from "lib/soupify"
6
6
  import { soupifyAndUploadExampleFile } from "./soupify-and-upload-example-file"
7
7
  import { markAllExamplesLoading } from "./mark-all-examples-loading"
8
+ import { readdir } from "fs/promises"
8
9
 
9
10
  export const uploadExamplesFromDirectory = async (
10
11
  {
@@ -17,7 +18,10 @@ export const uploadExamplesFromDirectory = async (
17
18
  ctx: { runtime: "node" | "bun" }
18
19
  ) => {
19
20
  const examplesDir = joinPath(cwd, "examples")
20
- const exampleFileNames = readdirSync(examplesDir)
21
+ const exampleFileNames = await readdir(examplesDir).catch((e) => {
22
+ console.log(kleur.red(`Error reading examples directory: "${examplesDir}"`))
23
+ throw e
24
+ })
21
25
 
22
26
  // Mark all examples as being "reloaded" in the database
23
27
  await markAllExamplesLoading({ devServerAxios })
@@ -0,0 +1,43 @@
1
+ import { AppContext } from "../util/app-context"
2
+ import { z } from "zod"
3
+ import { getDevServerAxios } from "./dev/get-dev-server-axios"
4
+ import kleur from "kleur"
5
+ import { fulfillExportRequests } from "./dev/fulfill-export-requests"
6
+
7
+ export const devServerFulfillExportRequests = async (
8
+ ctx: AppContext,
9
+ args: any
10
+ ) => {
11
+ const params = z.object({}).parse(args)
12
+
13
+ let server_url = `http://localhost:3020`
14
+ let dev_server_axios = getDevServerAxios({ serverUrl: server_url })
15
+
16
+ const checkHealth = () =>
17
+ dev_server_axios
18
+ .get("/api/health")
19
+ .then(() => true)
20
+ .catch((e) => false)
21
+
22
+ let is_dev_server_healthy = await checkHealth()
23
+
24
+ if (!is_dev_server_healthy) {
25
+ // attempt to use development-mode port, e.g. if someone ran
26
+ // npm run start:dev-server:dev
27
+ const devModeServerUrl = "http://localhost:3021"
28
+ dev_server_axios = getDevServerAxios({ serverUrl: devModeServerUrl })
29
+ is_dev_server_healthy = await checkHealth()
30
+ if (is_dev_server_healthy) server_url = devModeServerUrl
31
+ }
32
+
33
+ if (!is_dev_server_healthy) {
34
+ console.log(
35
+ kleur.red(
36
+ `Dev server doesn't seem to be running at ${server_url}. (Could not ping health)`
37
+ )
38
+ )
39
+ process.exit(1)
40
+ }
41
+
42
+ await fulfillExportRequests({ dev_server_axios }, ctx)
43
+ }
@@ -37,3 +37,4 @@ export { configClear } from "./config-clear"
37
37
  export { openCmd as open } from "./open"
38
38
  export { versionCmd as version } from "./version"
39
39
  export { exportGerbersCmd as exportGerbers } from "./export-gerbers"
40
+ export { devServerFulfillExportRequests } from "./dev-server-fulfill-export-requests"
@@ -44,6 +44,13 @@ export const exportGerbersToFile = async (
44
44
 
45
45
  console.log(kleur.gray("[zipping tmp dir]..."))
46
46
  const output = fs.createWriteStream(params.output_zip_path)
47
+
48
+ if (typeof Bun !== "undefined") {
49
+ throw new Error(
50
+ `Exporting gerbers doesn't currently work with Bun (bug w/ archiver module)`
51
+ )
52
+ }
53
+
47
54
  const archive = archiver("zip", {
48
55
  zlib: { level: 9 },
49
56
  })
@@ -53,7 +60,10 @@ export const exportGerbersToFile = async (
53
60
 
54
61
  await new Promise((resolve, reject) => {
55
62
  output.on("close", resolve)
63
+ output.on("finish", resolve)
64
+ output.on("end", resolve)
56
65
  output.on("error", reject)
66
+ archive.finalize()
57
67
  })
58
68
  }
59
69
 
@@ -307,6 +307,10 @@ export const getProgram = (ctx: AppContext) => {
307
307
  .option("-p, --port", "Port dev server is running on (default: 3020)")
308
308
  .action((args) => CMDFN.devServerUpload(ctx, args))
309
309
 
310
+ devServerCmd
311
+ .command("fulfill-export-requests")
312
+ .action((args) => CMDFN.devServerFulfillExportRequests(ctx, args))
313
+
310
314
  cmd
311
315
  .command("open")
312
316
  .description("Open browser to package on tscircuit registry")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Command line tool for developing, publishing and installing tscircuit circuits",