@tscircuit/cli 0.0.394 → 0.1.2

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 (246) hide show
  1. package/.github/workflows/bun-formatcheck.yml +26 -0
  2. package/.github/workflows/bun-pver-release.yml +25 -0
  3. package/.github/workflows/{typecheck.yml → bun-typecheck.yml} +0 -3
  4. package/LICENSE +21 -0
  5. package/README.md +33 -36
  6. package/biome.json +9 -9
  7. package/bun.lockb +0 -0
  8. package/cli/CliContext.ts +8 -0
  9. package/cli/auth/login/register.ts +73 -0
  10. package/cli/auth/logout/register.ts +11 -0
  11. package/cli/auth/register.ts +5 -0
  12. package/cli/clone/register.ts +99 -0
  13. package/cli/config/print/register.ts +12 -0
  14. package/cli/config/register.ts +5 -0
  15. package/cli/dev/register.ts +111 -0
  16. package/cli/main.ts +33 -0
  17. package/dist/main.js +537 -0
  18. package/docs/file-server-api-usage.md +57 -0
  19. package/docs/run-frame-usage.md +14 -0
  20. package/example-dir/manual-edits.json +1 -0
  21. package/example-dir/snippet.d.ts +13 -0
  22. package/example-dir/snippet.tsx +20 -0
  23. package/example-dir/types.d.ts +11 -0
  24. package/lib/cli-config/TypedConfigStore.ts +50 -0
  25. package/lib/cli-config/index.ts +16 -0
  26. package/lib/dependency-analysis/DependencyAnalyzer.ts +129 -0
  27. package/lib/dependency-analysis/getLocalFileDependencies.ts +101 -0
  28. package/lib/dependency-analysis/installNodeModuleTypes.ts +74 -0
  29. package/lib/index.ts +2 -0
  30. package/lib/project-config/index.ts +5 -0
  31. package/lib/registry-api/endpoint-types.ts +20 -0
  32. package/lib/registry-api/get-ky.ts +30 -0
  33. package/lib/server/EventsWatcher.ts +75 -0
  34. package/lib/server/createServer.ts +62 -0
  35. package/lib/site/getIndex.ts +18 -0
  36. package/package.json +27 -144
  37. package/tsconfig.json +25 -22
  38. package/.github/workflows/formatbot.yml +0 -63
  39. package/.github/workflows/release.yml +0 -40
  40. package/.github/workflows/test.yml +0 -32
  41. package/.github/workflows/windows-tests.yml +0 -32
  42. package/.prettierrc +0 -1
  43. package/DEVELOPMENT.md +0 -7
  44. package/api/README.md +0 -3
  45. package/api/db/generic-json-level.ts +0 -123
  46. package/api/db/get-db.ts +0 -26
  47. package/api/db/schema.ts +0 -65
  48. package/api/db/zod-level-db.ts +0 -148
  49. package/api/index.ts +0 -4
  50. package/api/lib/middlewares/with-db.ts +0 -18
  51. package/api/lib/middlewares/with-debug-request-logging.ts +0 -13
  52. package/api/lib/middlewares/with-error-response.ts +0 -37
  53. package/api/lib/with-winter-spec.ts +0 -9
  54. package/api/lib/zod/export_parameters.ts +0 -25
  55. package/api/routes/api/db/download.ts +0 -25
  56. package/api/routes/api/dev_package_examples/create.ts +0 -43
  57. package/api/routes/api/dev_package_examples/get.ts +0 -46
  58. package/api/routes/api/dev_package_examples/list.ts +0 -36
  59. package/api/routes/api/dev_package_examples/update.ts +0 -59
  60. package/api/routes/api/dev_server/reset.ts +0 -13
  61. package/api/routes/api/export_files/create.ts +0 -27
  62. package/api/routes/api/export_files/download.ts +0 -25
  63. package/api/routes/api/export_requests/create.ts +0 -30
  64. package/api/routes/api/export_requests/get.ts +0 -43
  65. package/api/routes/api/export_requests/list.ts +0 -26
  66. package/api/routes/api/export_requests/update.ts +0 -34
  67. package/api/routes/api/health.ts +0 -11
  68. package/api/routes/api/package_info/create.ts +0 -26
  69. package/api/routes/api/package_info/get.ts +0 -16
  70. package/api/routes/health.ts +0 -11
  71. package/api/routes/index.ts +0 -16
  72. package/api/server.ts +0 -20
  73. package/api/static-routes.ts +0 -24
  74. package/api/tests/fixtures/get-test-server.ts +0 -31
  75. package/api/tests/fixtures/start-server.ts +0 -41
  76. package/api/tests/routes/dev_package_examples/create.test.ts +0 -19
  77. package/api/tests/routes/dev_package_examples/get.test.ts +0 -25
  78. package/api/tests/routes/dev_package_examples/list.test.ts +0 -32
  79. package/api/tests/routes/dev_package_examples/update.test.ts +0 -38
  80. package/api/tests/routes/export_files/create.test.ts +0 -18
  81. package/api/tests/routes/export_files/download.test.ts +0 -29
  82. package/api/tests/routes/export_requests/create.test.ts +0 -24
  83. package/api/tests/routes/export_requests/get.test.ts +0 -41
  84. package/api/tests/routes/export_requests/list.test.ts +0 -35
  85. package/api/tests/routes/export_requests/update.test.ts +0 -50
  86. package/api/tests/routes/health.test.ts +0 -10
  87. package/bunfig.toml +0 -2
  88. package/cli/cli.ts +0 -13
  89. package/cli/lib/cmd-fns/add.ts +0 -34
  90. package/cli/lib/cmd-fns/auth-login.ts +0 -59
  91. package/cli/lib/cmd-fns/auth-logout.ts +0 -7
  92. package/cli/lib/cmd-fns/auth-sessions-create.ts +0 -3
  93. package/cli/lib/cmd-fns/auth-sessions-get.ts +0 -3
  94. package/cli/lib/cmd-fns/auth-sessions-list.ts +0 -5
  95. package/cli/lib/cmd-fns/config-clear.ts +0 -5
  96. package/cli/lib/cmd-fns/config-print-config.ts +0 -6
  97. package/cli/lib/cmd-fns/config-reveal-location.ts +0 -5
  98. package/cli/lib/cmd-fns/config-set-log-requests.ts +0 -7
  99. package/cli/lib/cmd-fns/config-set-registry.ts +0 -9
  100. package/cli/lib/cmd-fns/config-set-runtime.ts +0 -7
  101. package/cli/lib/cmd-fns/config-set-session.ts +0 -7
  102. package/cli/lib/cmd-fns/dev/check-if-initialized.ts +0 -22
  103. package/cli/lib/cmd-fns/dev/derive-selector-from-pcb-component-id.ts +0 -23
  104. package/cli/lib/cmd-fns/dev/dev-server-request-handler.ts +0 -61
  105. package/cli/lib/cmd-fns/dev/find-available-port.ts +0 -32
  106. package/cli/lib/cmd-fns/dev/fulfill-export-requests.ts +0 -162
  107. package/cli/lib/cmd-fns/dev/get-dev-server-axios.ts +0 -29
  108. package/cli/lib/cmd-fns/dev/index.ts +0 -168
  109. package/cli/lib/cmd-fns/dev/infer-export-name-from-source.ts +0 -17
  110. package/cli/lib/cmd-fns/dev/mark-all-examples-loading.ts +0 -18
  111. package/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts +0 -62
  112. package/cli/lib/cmd-fns/dev/start-dev-server.ts +0 -34
  113. package/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts +0 -347
  114. package/cli/lib/cmd-fns/dev/start-export-request-watcher.ts +0 -33
  115. package/cli/lib/cmd-fns/dev/start-fs-watcher.ts +0 -54
  116. package/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts +0 -42
  117. package/cli/lib/cmd-fns/dev-server-fulfill-export-requests.ts +0 -43
  118. package/cli/lib/cmd-fns/dev-server-upload.ts +0 -56
  119. package/cli/lib/cmd-fns/export-gerbers.ts +0 -28
  120. package/cli/lib/cmd-fns/export-kicad-pcb.ts +0 -36
  121. package/cli/lib/cmd-fns/export-pnp-csv.ts +0 -32
  122. package/cli/lib/cmd-fns/gen-jlcpcb-component.ts +0 -64
  123. package/cli/lib/cmd-fns/go.ts +0 -14
  124. package/cli/lib/cmd-fns/index.ts +0 -46
  125. package/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts +0 -21
  126. package/cli/lib/cmd-fns/init/get-generated-npmrc.ts +0 -8
  127. package/cli/lib/cmd-fns/init/get-generated-readme.ts +0 -41
  128. package/cli/lib/cmd-fns/init/get-generated-tsconfig.ts +0 -34
  129. package/cli/lib/cmd-fns/init/index.ts +0 -193
  130. package/cli/lib/cmd-fns/install.ts +0 -34
  131. package/cli/lib/cmd-fns/lint.ts +0 -43
  132. package/cli/lib/cmd-fns/open.ts +0 -19
  133. package/cli/lib/cmd-fns/package-examples-create.ts +0 -36
  134. package/cli/lib/cmd-fns/package-examples-get.ts +0 -20
  135. package/cli/lib/cmd-fns/package-examples-list.ts +0 -18
  136. package/cli/lib/cmd-fns/package-files-create.ts +0 -31
  137. package/cli/lib/cmd-fns/package-files-download.ts +0 -29
  138. package/cli/lib/cmd-fns/package-files-get.ts +0 -3
  139. package/cli/lib/cmd-fns/package-files-list.ts +0 -28
  140. package/cli/lib/cmd-fns/package-files-upload-directory.ts +0 -6
  141. package/cli/lib/cmd-fns/package-releases-create.ts +0 -35
  142. package/cli/lib/cmd-fns/package-releases-get.ts +0 -3
  143. package/cli/lib/cmd-fns/package-releases-list.ts +0 -32
  144. package/cli/lib/cmd-fns/package-releases-update.ts +0 -45
  145. package/cli/lib/cmd-fns/packages-create.ts +0 -16
  146. package/cli/lib/cmd-fns/packages-get.ts +0 -16
  147. package/cli/lib/cmd-fns/packages-list.ts +0 -16
  148. package/cli/lib/cmd-fns/publish/index.ts +0 -336
  149. package/cli/lib/cmd-fns/remove.ts +0 -31
  150. package/cli/lib/cmd-fns/render.ts +0 -45
  151. package/cli/lib/cmd-fns/soupify.ts +0 -31
  152. package/cli/lib/cmd-fns/uninstall.ts +0 -31
  153. package/cli/lib/cmd-fns/version.ts +0 -38
  154. package/cli/lib/create-config-manager.ts +0 -97
  155. package/cli/lib/export-fns/export-bom-csv.ts +0 -32
  156. package/cli/lib/export-fns/export-gerbers.ts +0 -108
  157. package/cli/lib/export-fns/export-kicad-pcb.ts +0 -32
  158. package/cli/lib/export-fns/export-pnp-csv.ts +0 -31
  159. package/cli/lib/get-program.ts +0 -387
  160. package/cli/lib/param-handlers/index.ts +0 -21
  161. package/cli/lib/param-handlers/interact-for-local-directory.ts +0 -58
  162. package/cli/lib/param-handlers/interact-for-local-file.ts +0 -59
  163. package/cli/lib/param-handlers/interact-for-package-example-id.ts +0 -25
  164. package/cli/lib/param-handlers/interact-for-package-name-with-version.ts +0 -63
  165. package/cli/lib/param-handlers/interact-for-package-name.ts +0 -45
  166. package/cli/lib/param-handlers/interact-for-package-release-id.ts +0 -15
  167. package/cli/lib/param-handlers/interact-for-registry-url.ts +0 -27
  168. package/cli/lib/param-handlers/interact-for-runtime.ts +0 -33
  169. package/cli/lib/param-handlers/param-handler-type.ts +0 -7
  170. package/cli/lib/posthog.ts +0 -23
  171. package/cli/lib/soupify/get-export-name-from-file.ts +0 -29
  172. package/cli/lib/soupify/get-tmp-entrpoint-filepath.ts +0 -15
  173. package/cli/lib/soupify/index.ts +0 -1
  174. package/cli/lib/soupify/run-entrypoint-file.ts +0 -59
  175. package/cli/lib/soupify/soupify-with-core.ts +0 -74
  176. package/cli/lib/soupify/soupify.ts +0 -6
  177. package/cli/lib/util/app-context.ts +0 -17
  178. package/cli/lib/util/create-context-and-run-program.ts +0 -168
  179. package/cli/lib/util/get-all-package-files.ts +0 -66
  180. package/cli/lib/util/lint-project.ts +0 -137
  181. package/cli/tests/export-gerber-keyboard.test.ts +0 -16
  182. package/cli/tests/export-gerber.test.ts +0 -49
  183. package/cli/tests/export-kicad-pcb.test.ts +0 -23
  184. package/cli/tests/export-pnp-csv.test.ts +0 -24
  185. package/cli/tests/fixtures/preload.ts +0 -54
  186. package/cli/tests/init.test.ts +0 -9
  187. package/cli/tests/open.test.ts +0 -9
  188. package/cli/tests/soupify-builder.test.ts +0 -9
  189. package/cli/tests/soupify-core.test.ts +0 -9
  190. package/dist/cli.js +0 -3676
  191. package/docs/EDIT_EVENT_PIPELINE.md +0 -34
  192. package/example-project/README.md +0 -18
  193. package/example-project/examples/basic-capacitor.tsx +0 -5
  194. package/example-project/examples/basic-chip.tsx +0 -26
  195. package/example-project/examples/basic-resistor.tsx +0 -3
  196. package/example-project/examples/macrokeypad.tsx +0 -59
  197. package/example-project/index.ts +0 -1
  198. package/example-project/package.json +0 -5
  199. package/example-project/src/ArduinoProMicroBreakout.tsx +0 -37
  200. package/example-project/src/Key.tsx +0 -46
  201. package/example-project/src/Keyswitch.tsx +0 -26
  202. package/example-project/src/KeyswitchSocket.tsx +0 -56
  203. package/example-project/src/MyCircuit.tsx +0 -38
  204. package/example-project/src/manual-edits.ts +0 -93
  205. package/frontend/README.md +0 -3
  206. package/frontend/bun.lockb +0 -0
  207. package/frontend/components/command-k.tsx +0 -86
  208. package/frontend/components/dialogs/generic-export-dialog.tsx +0 -189
  209. package/frontend/components/dialogs/gerber-export-dialog.tsx +0 -168
  210. package/frontend/components/global-context-providers.tsx +0 -11
  211. package/frontend/components/select-example-search.tsx +0 -118
  212. package/frontend/components/ui/alert-dialog.tsx +0 -139
  213. package/frontend/components/ui/alert.tsx +0 -59
  214. package/frontend/components/ui/breadcrumb.tsx +0 -115
  215. package/frontend/components/ui/button.tsx +0 -57
  216. package/frontend/components/ui/card.tsx +0 -76
  217. package/frontend/components/ui/command.tsx +0 -153
  218. package/frontend/components/ui/context-menu.tsx +0 -202
  219. package/frontend/components/ui/dialog.tsx +0 -120
  220. package/frontend/components/ui/menubar.tsx +0 -238
  221. package/frontend/components/ui/navigation-menu.tsx +0 -128
  222. package/frontend/components/ui/popover.tsx +0 -31
  223. package/frontend/components/ui/select.tsx +0 -162
  224. package/frontend/components/ui/tabs.tsx +0 -53
  225. package/frontend/components/ui/toggle-group.tsx +0 -59
  226. package/frontend/components/ui/toggle.tsx +0 -43
  227. package/frontend/components/ui/tooltip.tsx +0 -28
  228. package/frontend/components.json +0 -17
  229. package/frontend/hooks/toast-if-api-not-connected.ts +0 -23
  230. package/frontend/hooks/use-active-dev-package-example-lite.ts +0 -39
  231. package/frontend/hooks/use-dev-package-examples.tsx +0 -18
  232. package/frontend/hooks/use-global-store.ts +0 -42
  233. package/frontend/index.css +0 -76
  234. package/frontend/index.html +0 -13
  235. package/frontend/lib/utils.ts +0 -6
  236. package/frontend/main.tsx +0 -13
  237. package/frontend/tailwind.config.js +0 -74
  238. package/frontend/views/App.tsx +0 -22
  239. package/frontend/views/Header.tsx +0 -55
  240. package/frontend/views/HeaderMenu.tsx +0 -326
  241. package/frontend/views/MainContentView.tsx +0 -172
  242. package/frontend/vite-env.d.ts +0 -1
  243. package/frontend/vite.config.ts +0 -50
  244. package/renovate.json +0 -16
  245. package/scripts/build-cli.ts +0 -12
  246. package/tsup.config.ts +0 -7
@@ -1,34 +0,0 @@
1
- import { AxiosInstance } from "axios"
2
- import { devServerRequestHandler } from "./dev-server-request-handler"
3
-
4
- export const startDevServer = async ({
5
- port,
6
- devServerAxios,
7
- }: {
8
- port: number
9
- devServerAxios: AxiosInstance
10
- }) => {
11
- let server: any
12
- if (typeof Bun !== "undefined") {
13
- server = Bun.serve({
14
- fetch: devServerRequestHandler,
15
- development: false,
16
- port,
17
- })
18
- } else {
19
- // Hono messes up the globals, only import it if we don't have Bun
20
- const { Hono } = await import("hono")
21
- const { serve } = await import("@hono/node-server")
22
- const honoApp = new Hono()
23
- honoApp.all("/*", (c) => devServerRequestHandler(c.req.raw))
24
- server = serve({
25
- fetch: honoApp.fetch,
26
- port,
27
- })
28
- }
29
-
30
- console.log("Running health check against dev server...")
31
- await devServerAxios.get("/api/health")
32
-
33
- return server
34
- }
@@ -1,347 +0,0 @@
1
- import type { DevPackageExample } from "api/db/schema"
2
- import type { AxiosInstance } from "axios"
3
- import kleur from "kleur"
4
- import { AppContext } from "cli/lib/util/app-context"
5
- import fg from "fast-glob"
6
- import fs from "fs"
7
- import { Project, ts } from "ts-morph"
8
- import * as Path from "path/posix"
9
- import { deriveSelectorFromPcbComponentId } from "./derive-selector-from-pcb-component-id"
10
- import type { EditEvent } from "@tscircuit/manual-edit-events"
11
- import {
12
- getManualTraceHintFromEvent,
13
- ManualTraceHint,
14
- ManualEditFile,
15
- } from "@tscircuit/layout"
16
- import JSON5 from "json5"
17
- import Debug from "debug"
18
-
19
- const debug = Debug("tscircuit:cli:edit-event-watcher")
20
-
21
- type ManualPcbPosition = Required<ManualEditFile>["pcb_placements"][number]
22
-
23
- export const startEditEventWatcher = async (
24
- {
25
- devServerAxios,
26
- }: {
27
- devServerAxios: AxiosInstance
28
- },
29
- ctx: AppContext,
30
- ) => {
31
- let running = true
32
- ;(async () => {
33
- let last_edit_event_update_time: Record<string, string> = {}
34
-
35
- while (running) {
36
- try {
37
- const dev_package_examples: DevPackageExample[] = await devServerAxios
38
- .post("/api/dev_package_examples/list", {})
39
- .then((r) => r.data.dev_package_examples)
40
-
41
- for (const dev_package_example of dev_package_examples) {
42
- const dev_package_example_id: number =
43
- dev_package_example.dev_package_example_id as any
44
-
45
- const last_recorded_update_time =
46
- last_edit_event_update_time[dev_package_example_id]
47
-
48
- if (
49
- last_recorded_update_time !==
50
- dev_package_example.edit_events_last_updated_at
51
- ) {
52
- console.log(
53
- kleur.gray(
54
- `Edit event detected for dev_package_example ${dev_package_example.dev_package_example_id}`,
55
- ),
56
- )
57
- debug(`file_path: ${dev_package_example.file_path}`)
58
-
59
- last_edit_event_update_time[dev_package_example_id] =
60
- dev_package_example.edit_events_last_updated_at! // TODO last_edit_event_updated_at
61
-
62
- debug(` getting new edit events...`)
63
-
64
- const dev_package_example_full = await devServerAxios
65
- .post("/api/dev_package_examples/get", {
66
- dev_package_example_id,
67
- })
68
- .then((r) => r.data.dev_package_example)
69
-
70
- // 1. Find the *.manual-edits.ts, if there are multiple error
71
- const manual_edit_files = fg.sync(
72
- ["**/*.manual-edits.ts", "**/manual-edits.ts"],
73
- {
74
- cwd: ctx.cwd,
75
- ignore: ["node_modules"],
76
- },
77
- )
78
-
79
- if (manual_edit_files.length === 0) {
80
- console.log(
81
- kleur.red(
82
- `No manual edit files found in "${ctx.cwd}", please create a file "manual-edits.ts" or "*.manual-edits.ts" to persist manual edits`,
83
- ),
84
- )
85
- continue
86
- }
87
-
88
- if (manual_edit_files.length > 1) {
89
- console.log(
90
- kleur.red(
91
- `Multiple manual edit files found, tsci currently doesn't know how to handle this, you should go upvote an issue`,
92
- ),
93
- )
94
- for (let i = 0; i < manual_edit_files.length; i++) {
95
- console.log(
96
- kleur.gray(` file ${i + 1}: ${manual_edit_files[i]}`),
97
- )
98
- }
99
- continue
100
- }
101
-
102
- const manual_edit_file = manual_edit_files[0]
103
- const manual_edit_file_content = fs.readFileSync(
104
- Path.join(ctx.cwd, manual_edit_file),
105
- "utf-8",
106
- )
107
-
108
- debug(` found manual edit file: ${manual_edit_file}`)
109
-
110
- // 2. Convert the edit events into ManualPcbPosition[] and append,
111
- // removing any old placements/positions for the same selector.
112
- // We can completely rewrite the file here for now (we'll need
113
- // to preserve comments etc. later)
114
-
115
- const edit_events: EditEvent[] =
116
- dev_package_example_full.completed_edit_events ?? []
117
-
118
- if (edit_events.length === 0) continue
119
-
120
- const project = new Project()
121
-
122
- const ts_manual_edits_file = project.createSourceFile(
123
- "manual-edits.ts",
124
- manual_edit_file_content,
125
- )
126
-
127
- // Access the default export declaration
128
- const default_export_dec = ts_manual_edits_file
129
- .getDefaultExportSymbol()!
130
- .getDeclarations()[0]
131
-
132
- // Get the object literal expression from the export default statement
133
- const object_literal =
134
- default_export_dec.getFirstChildByKindOrThrow(
135
- ts.SyntaxKind.ObjectLiteralExpression,
136
- )
137
-
138
- // Get the `pcb_placements` property
139
- const pcb_placements_ts =
140
- object_literal.getPropertyOrThrow("pcb_placements")
141
-
142
- if (object_literal.getProperty("edit_events") === undefined) {
143
- object_literal.addPropertyAssignment({
144
- name: "edit_events",
145
- initializer: "[]",
146
- })
147
- }
148
-
149
- const edit_events_ts =
150
- object_literal.getPropertyOrThrow("edit_events")
151
-
152
- if (
153
- object_literal.getProperty("manual_trace_hints") === undefined
154
- ) {
155
- object_literal.addPropertyAssignment({
156
- name: "manual_trace_hints",
157
- initializer: "[]",
158
- })
159
- }
160
- const manual_trace_hints_ts =
161
- object_literal.getPropertyOrThrow("manual_trace_hints")
162
-
163
- let pcb_placements: (ManualPcbPosition & {
164
- _edit_event_id?: string
165
- })[]
166
- let in_file_edit_events: EditEvent[]
167
- let manual_trace_hints: ManualTraceHint[]
168
- try {
169
- pcb_placements = JSON5.parse(
170
- pcb_placements_ts.getText().replace(/pcb_placements:\s/, ""),
171
- )
172
- } catch (e: any) {
173
- console.log(
174
- kleur.red(
175
- `Error parsing pcb_placements from manual edits file: ${pcb_placements_ts.getText()} ${e.toString()}`,
176
- ),
177
- )
178
- continue
179
- }
180
- try {
181
- in_file_edit_events = JSON5.parse(
182
- edit_events_ts.getText().replace(/edit_events:\s/, ""),
183
- )
184
- } catch (e: any) {
185
- console.log(
186
- kleur.red(
187
- `Error parsing edit_events from manual edits file: ${edit_events_ts.getText()} ${e.toString()}`,
188
- ),
189
- )
190
- continue
191
- }
192
- try {
193
- manual_trace_hints = JSON5.parse(
194
- manual_trace_hints_ts
195
- .getText()
196
- .replace(/manual_trace_hints:\s/, ""),
197
- )
198
- } catch (e: any) {
199
- console.log(
200
- kleur.red(
201
- `Error parsing manual_trace_hints from manual edits file: ${pcb_placements_ts.getText()} ${e.toString()}`,
202
- ),
203
- )
204
- continue
205
- }
206
-
207
- const handled_edit_events = new Set<string>(
208
- pcb_placements
209
- .map((p) => (p as any)._edit_event_id)
210
- .concat(in_file_edit_events.map((a) => a.edit_event_id)),
211
- )
212
-
213
- // Add PCB placements from edit events
214
- for (const incoming_edit_event of edit_events) {
215
- if (handled_edit_events.has(incoming_edit_event.edit_event_id))
216
- continue
217
-
218
- debug(
219
- `incoming_edit_event: ${JSON.stringify(incoming_edit_event)}`,
220
- )
221
-
222
- if (
223
- incoming_edit_event.pcb_edit_event_type ===
224
- "edit_component_location"
225
- ) {
226
- // TODO Figure out a good selector for this pcb_component
227
- let pcb_component_selector: string | null = null
228
- if (incoming_edit_event.pcb_component_id) {
229
- pcb_component_selector = deriveSelectorFromPcbComponentId({
230
- soup: dev_package_example_full.tscircuit_soup,
231
- pcb_component_id: incoming_edit_event.pcb_component_id,
232
- })
233
- }
234
-
235
- debug(
236
- `edit event pcb_component_selector: "${pcb_component_selector}"`,
237
- )
238
-
239
- // TODO we'll need to work past this for edit_event_type=edit_trace
240
- if (!pcb_component_selector) continue
241
-
242
- const existing_placement_for_selector = pcb_placements.find(
243
- (pp) => pp.selector === pcb_component_selector,
244
- )
245
-
246
- if (!existing_placement_for_selector) {
247
- console.log(
248
- kleur.gray(
249
- ` adding PCB placement from edit event for "${pcb_component_selector}"`,
250
- ),
251
- )
252
-
253
- pcb_placements.push({
254
- _edit_event_id: incoming_edit_event.edit_event_id,
255
- selector: pcb_component_selector,
256
- center: incoming_edit_event.new_center,
257
- relative_to: "group_center",
258
- })
259
- } else {
260
- existing_placement_for_selector.center =
261
- incoming_edit_event.new_center
262
- }
263
-
264
- // Edit the pcb placements object
265
- pcb_placements_ts.replaceWithText(
266
- `pcb_placements: ${JSON.stringify(
267
- pcb_placements,
268
- null,
269
- " ",
270
- )}`,
271
- )
272
-
273
- // Save the file
274
- fs.writeFileSync(
275
- Path.join(ctx.cwd, manual_edit_file),
276
- ts_manual_edits_file.getFullText(),
277
- )
278
- await devServerAxios.post("/api/dev_package_examples/update", {
279
- dev_package_example_id,
280
- edit_events_last_applied_at:
281
- dev_package_example.edit_events_last_updated_at,
282
- })
283
- } else if (
284
- incoming_edit_event.pcb_edit_event_type === "edit_trace_hint"
285
- ) {
286
- const new_trace_hint = getManualTraceHintFromEvent(
287
- dev_package_example_full.tscircuit_soup,
288
- incoming_edit_event,
289
- )
290
-
291
- manual_trace_hints_ts.replaceWithText(
292
- `manual_trace_hints: ${JSON.stringify(
293
- manual_trace_hints
294
- .filter(
295
- (th) =>
296
- th.pcb_port_selector !==
297
- new_trace_hint.pcb_port_selector,
298
- )
299
- .concat([new_trace_hint]),
300
- null,
301
- " ",
302
- )}`,
303
- )
304
-
305
- fs.writeFileSync(
306
- Path.join(ctx.cwd, manual_edit_file),
307
- ts_manual_edits_file.getFullText(),
308
- )
309
- await devServerAxios.post("/api/dev_package_examples/update", {
310
- dev_package_example_id,
311
- edit_events_last_applied_at:
312
- dev_package_example.edit_events_last_updated_at,
313
- })
314
- } else {
315
- // All other events just go to the manual-edits.ts file with
316
- // in the "edit_events" property
317
- edit_events_ts.replaceWithText(
318
- `edit_events: ${JSON.stringify(edit_events, null, " ")}`,
319
- )
320
- console.log(edit_events_ts.getFullText())
321
- fs.writeFileSync(
322
- Path.join(ctx.cwd, manual_edit_file),
323
- ts_manual_edits_file.getFullText(),
324
- )
325
- await devServerAxios.post("/api/dev_package_examples/update", {
326
- dev_package_example_id,
327
- edit_events_last_applied_at:
328
- dev_package_example.edit_events_last_updated_at,
329
- })
330
- }
331
- }
332
- }
333
- }
334
- } catch (err: any) {
335
- console.log(kleur.red(`Error in edit event watcher: ${err.toString()}`))
336
- }
337
-
338
- await new Promise((resolve) => setTimeout(resolve, 100))
339
- }
340
- })()
341
-
342
- return {
343
- stop: () => {
344
- running = false
345
- },
346
- }
347
- }
@@ -1,33 +0,0 @@
1
- import { AxiosInstance } from "axios"
2
- import kleur from "kleur"
3
- import { fulfillExportRequests } from "./fulfill-export-requests"
4
- import { AppContext } from "cli/lib/util/app-context"
5
-
6
- export const startExportRequestWatcher = async (
7
- {
8
- devServerAxios,
9
- }: {
10
- devServerAxios: AxiosInstance
11
- },
12
- ctx: AppContext,
13
- ) => {
14
- let running = true
15
- ;(async () => {
16
- while (running) {
17
- try {
18
- await fulfillExportRequests({ dev_server_axios: devServerAxios }, ctx)
19
- } catch (err: any) {
20
- console.log(
21
- kleur.red(`Error in export request watcher: ${err.toString()}`),
22
- )
23
- }
24
- await new Promise((resolve) => setTimeout(resolve, 1000))
25
- }
26
- })()
27
-
28
- return {
29
- stop: () => {
30
- running = false
31
- },
32
- }
33
- }
@@ -1,54 +0,0 @@
1
- import { AxiosInstance } from "axios"
2
- import chokidar from "chokidar"
3
- import { uploadExamplesFromDirectory } from "./upload-examples-from-directory"
4
- import kleur from "kleur"
5
- import { AppContext } from "cli/lib/util/app-context"
6
-
7
- export const startFsWatcher = async (
8
- {
9
- cwd,
10
- devServerAxios,
11
- }: {
12
- cwd: string
13
- devServerAxios: AxiosInstance
14
- },
15
- ctx: Pick<AppContext, "runtime" | "params">,
16
- ) => {
17
- const watcher = chokidar.watch([`${cwd}/**/*.tsx`, `${cwd}/**/*.ts`], {
18
- ignored: /node_modules/,
19
- persistent: true,
20
- })
21
-
22
- const upload_queue_state = {
23
- dirty: false,
24
- should_run: true,
25
- }
26
- watcher.on("change", async (path) => {
27
- console.log(path)
28
- if (path.endsWith(".__tmp_entrypoint.tsx")) return
29
- console.log(`File ${path} has been changed`)
30
- // TODO analyze to determine which examples were impacted
31
- upload_queue_state.dirty = true
32
- })
33
-
34
- async function uploadInBackground() {
35
- while (upload_queue_state.should_run) {
36
- if (upload_queue_state.dirty) {
37
- console.log(kleur.yellow("Changes detected, re-uploading examples..."))
38
- upload_queue_state.dirty = false
39
- await uploadExamplesFromDirectory({ cwd, devServerAxios }, ctx)
40
- }
41
- await new Promise((resolve) => setTimeout(resolve, 100))
42
- }
43
- }
44
-
45
- const _backgroundUploaderPromise = uploadInBackground()
46
-
47
- return {
48
- _backgroundUploaderPromise,
49
- stop: () => {
50
- upload_queue_state.should_run = false
51
- watcher.close()
52
- },
53
- }
54
- }
@@ -1,42 +0,0 @@
1
- import kleur from "kleur"
2
- import { join as joinPath } from "path/posix"
3
- import { AxiosInstance } from "axios"
4
- import { readdirSync, readFileSync } from "fs"
5
- import { soupify } from "cli/lib/soupify"
6
- import { soupifyAndUploadExampleFile } from "./soupify-and-upload-example-file"
7
- import { markAllExamplesLoading } from "./mark-all-examples-loading"
8
- import { readdir } from "fs/promises"
9
- import { AppContext } from "cli/lib/util/app-context"
10
-
11
- export const uploadExamplesFromDirectory = async (
12
- {
13
- cwd,
14
- devServerAxios,
15
- }: {
16
- cwd: string
17
- devServerAxios: AxiosInstance
18
- },
19
- ctx: Pick<AppContext, "runtime" | "params">,
20
- ) => {
21
- const examplesDir = joinPath(cwd, "examples")
22
- const exampleFileNames = await readdir(examplesDir).catch((e) => {
23
- console.log(kleur.red(`Error reading examples directory: "${examplesDir}"`))
24
- throw e
25
- })
26
-
27
- // Mark all examples as being "reloaded" in the database
28
- await markAllExamplesLoading({ devServerAxios })
29
-
30
- for (const exampleFileName of exampleFileNames) {
31
- if (exampleFileName.endsWith(".__tmp_entrypoint.tsx")) continue
32
- if (!exampleFileName.endsWith(".tsx")) continue
33
- await soupifyAndUploadExampleFile(
34
- {
35
- devServerAxios,
36
- examplesDir,
37
- exampleFileName,
38
- },
39
- ctx,
40
- )
41
- }
42
- }
@@ -1,43 +0,0 @@
1
- import kleur from "kleur"
2
- import { z } from "zod"
3
- import { AppContext } from "../util/app-context"
4
- import { fulfillExportRequests } from "./dev/fulfill-export-requests"
5
- import { getDevServerAxios } from "./dev/get-dev-server-axios"
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://127.0.0.1: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://127.0.0.1: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
- }
@@ -1,56 +0,0 @@
1
- import kleur from "kleur"
2
- import { z } from "zod"
3
- import { AppContext } from "../util/app-context"
4
- import { getDevServerAxios } from "./dev/get-dev-server-axios"
5
- import { startFsWatcher } from "./dev/start-fs-watcher"
6
- import { uploadExamplesFromDirectory } from "./dev/upload-examples-from-directory"
7
-
8
- export const devServerUpload = async (ctx: AppContext, args: any) => {
9
- const params = z
10
- .object({
11
- dir: z.string().optional().default(ctx.cwd),
12
- port: z.coerce.number().optional().nullable().default(null),
13
- watch: z.boolean().optional().default(false),
14
- })
15
- .parse(args)
16
-
17
- let serverUrl = `http://127.0.0.1:${params.port ?? 3020}`
18
- let devServerAxios = getDevServerAxios({ serverUrl })
19
-
20
- const checkHealth = () =>
21
- devServerAxios
22
- .get("/api/health")
23
- .then(() => true)
24
- .catch((e) => false)
25
-
26
- let is_dev_server_healthy = await checkHealth()
27
-
28
- if (!is_dev_server_healthy && !params.port) {
29
- // attempt to use development-mode port, e.g. if someone ran
30
- // npm run start:dev-server:dev
31
- const devModeServerUrl = "http://127.0.0.1:3021"
32
- devServerAxios = getDevServerAxios({ serverUrl: devModeServerUrl })
33
- is_dev_server_healthy = await checkHealth()
34
- if (is_dev_server_healthy) serverUrl = devModeServerUrl
35
- }
36
-
37
- if (!is_dev_server_healthy) {
38
- console.log(
39
- kleur.red(
40
- `Dev server doesn't seem to be running at ${serverUrl}. (Could not ping health)`,
41
- ),
42
- )
43
- process.exit(1)
44
- }
45
-
46
- console.log(`Loading examples...`)
47
- await uploadExamplesFromDirectory({ devServerAxios, cwd: params.dir }, ctx)
48
-
49
- if (params.watch) {
50
- // Start watcher
51
- const watcher = await startFsWatcher(
52
- { cwd: params.dir, devServerAxios },
53
- ctx,
54
- )
55
- }
56
- }
@@ -1,28 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
- import { z } from "zod"
3
- import { exportGerbersToFile } from "cli/lib/export-fns/export-gerbers"
4
-
5
- export const exportGerbersCmd = async (ctx: AppContext, args: any) => {
6
- const params = z
7
- .object({
8
- file: z.string().optional(),
9
- input: z.string().optional(),
10
- export: z.string().optional(),
11
- outputfile: z.string().optional().default("gerbers.zip"),
12
- })
13
- .refine((data) => data.file || data.input, {
14
- message: "Either 'file' or 'input' must be provided",
15
- })
16
- .parse(args)
17
-
18
- const inputFile = params.input || params.file
19
-
20
- await exportGerbersToFile(
21
- {
22
- example_file_path: inputFile!,
23
- export_name: params.export,
24
- output_zip_path: params.outputfile,
25
- },
26
- ctx,
27
- )
28
- }
@@ -1,36 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
- import { z } from "zod"
3
- import { soupify } from "cli/lib/soupify"
4
- import {
5
- convertCircuitJsonToKiCadPcb,
6
- convertKiCadPcbToSExprString,
7
- } from "kicad-converter"
8
- import fs from "fs/promises"
9
- import kleur from "kleur"
10
-
11
- export const exportKicadPcb = async (ctx: AppContext, args: any) => {
12
- const params = z
13
- .object({
14
- input: z.string(),
15
- export: z.string().optional(),
16
- outputfile: z.string().default("output.kicad_pcb"),
17
- })
18
- .parse(args)
19
-
20
- console.log(kleur.gray("[soupifying]..."))
21
- const soup = await soupify(
22
- {
23
- filePath: params.input,
24
- exportName: params.export,
25
- },
26
- ctx,
27
- )
28
-
29
- console.log(kleur.gray("[converting to KiCad PCB]..."))
30
- const kicadPcb = convertCircuitJsonToKiCadPcb(soup)
31
-
32
- console.log(kleur.gray(`[writing to ${params.outputfile}]...`))
33
- await fs.writeFile(params.outputfile, convertKiCadPcbToSExprString(kicadPcb))
34
-
35
- console.log(kleur.green(`KiCad PCB file exported to ${params.outputfile}`))
36
- }