@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,29 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
- import { z } from "zod"
3
- import * as fs from "fs/promises"
4
-
5
- export const packageFilesDownload = async (ctx: AppContext, args: any) => {
6
- const params = z
7
- .object({
8
- packageNameWithVersion: z.string().optional(),
9
- remoteFilePath: z.string().optional(),
10
- output: z.string().optional(),
11
- })
12
- .parse(args)
13
-
14
- const { packageNameWithVersion, remoteFilePath } = params
15
-
16
- const packageContent = await ctx.axios
17
- .post("/package_files/download", {
18
- package_name_with_version: packageNameWithVersion,
19
- file_path: remoteFilePath,
20
- })
21
- .then((r) => r.data)
22
-
23
- if (params.output) {
24
- console.log("Writing to", params.output)
25
- await fs.writeFile(params.output, packageContent)
26
- } else {
27
- console.log(packageContent)
28
- }
29
- }
@@ -1,3 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
-
3
- export const packageFilesGet = async (ctx: AppContext, args: any) => {}
@@ -1,28 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
- import { z } from "zod"
3
-
4
- export const packageFilesList = async (ctx: AppContext, args: any) => {
5
- const params = z
6
- .object({
7
- packageReleaseId: z.string().optional(),
8
- packageName: z.string().optional(),
9
- packageNameWithVersion: z.string().optional(),
10
- verbose: z.boolean().optional(),
11
- })
12
- .parse(args)
13
-
14
- const package_files = await ctx.axios
15
- .post("/package_files/list", {
16
- package_release_id: params.packageReleaseId,
17
- package_name: params.packageName,
18
- use_latest_version: Boolean(params.packageName),
19
- package_name_with_version: params.packageNameWithVersion,
20
- })
21
- .then((r) => r.data.package_files)
22
-
23
- if (params.verbose) {
24
- console.log(package_files)
25
- } else {
26
- console.log(package_files.map((f: any) => f.file_path).join("\n"))
27
- }
28
- }
@@ -1,6 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
-
3
- export const packageFilesUploadDirectory = async (
4
- ctx: AppContext,
5
- args: any,
6
- ) => {}
@@ -1,35 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
- import { z } from "zod"
3
- import kleur from "kleur"
4
-
5
- export const packageReleasesCreate = async (ctx: AppContext, args: any) => {
6
- args.version = args.releaseVersion
7
- const params = z
8
- .object({
9
- packageNameWithVersion: z.string().optional(),
10
- packageName: z.string().optional(),
11
- version: z.string().optional(),
12
- })
13
- .refine((d) => {
14
- if (d.packageNameWithVersion) return true
15
- if (d.packageName && d.version) return true
16
- return false
17
- }, "Either packageNameWithVersion or packageName and version must be provided")
18
- .parse(args)
19
-
20
- let { packageNameWithVersion, packageName, version } = params
21
-
22
- if (!packageNameWithVersion) {
23
- packageNameWithVersion = `${packageName}@${version}`
24
- }
25
-
26
- const package_release = await ctx.axios
27
- .post("/package_releases/create", {
28
- package_name_with_version: packageNameWithVersion,
29
- })
30
- .then((r) => r.data.package_release)
31
-
32
- console.log(
33
- `Package release created! ${kleur.gray(package_release.package_release_id)}`,
34
- )
35
- }
@@ -1,3 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
-
3
- export const packageReleasesGet = async (ctx: AppContext, args: any) => {}
@@ -1,32 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
- import { z } from "zod"
3
-
4
- export const packageReleasesList = async (ctx: AppContext, args: any) => {
5
- const params = z
6
- .object({
7
- packageName: z.string().optional(),
8
- verbose: z.boolean().optional(),
9
- })
10
- .parse(args)
11
-
12
- const package_releases = await ctx.axios
13
- .post("/package_releases/list", {
14
- package_name: params.packageName,
15
- })
16
- .then((r) => r.data.package_releases)
17
-
18
- if (package_releases.length === 0) {
19
- console.log("No package releases found")
20
- return
21
- }
22
-
23
- if (params.verbose) {
24
- console.log(package_releases)
25
- } else {
26
- console.log(
27
- package_releases
28
- .map((f: any) => `${params.packageName}@${f.version}`)
29
- .join("\n"),
30
- )
31
- }
32
- }
@@ -1,45 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
- import { z } from "zod"
3
- import kleur from "kleur"
4
-
5
- export const packageReleasesUpdate = async (ctx: AppContext, args: any) => {
6
- const params = z
7
- .object({
8
- packageNameWithVersion: z.string().optional(),
9
- packageName: z.string().optional(),
10
- version: z.string().optional(),
11
- isLatest: z.boolean().optional(),
12
- isLocked: z.boolean().optional(),
13
- })
14
- .refine((d) => {
15
- if (d.packageNameWithVersion) return true
16
- if (d.packageName && d.version) return true
17
- return false
18
- }, "Either packageNameWithVersion or packageName and version must be provided")
19
- .parse(args)
20
-
21
- let { packageNameWithVersion, packageName, version } = params
22
-
23
- if (!packageNameWithVersion) {
24
- packageNameWithVersion = `${packageName}@${version}`
25
- }
26
-
27
- const delta: {
28
- is_latest?: boolean
29
- is_locked?: boolean
30
- } = {}
31
-
32
- if (params.isLatest !== undefined) {
33
- delta.is_latest = params.isLatest
34
- }
35
- if (params.isLocked !== undefined) {
36
- delta.is_locked = params.isLocked
37
- }
38
-
39
- await ctx.axios.post("/package_releases/update", {
40
- package_name_with_version: packageNameWithVersion,
41
- ...delta,
42
- })
43
-
44
- console.log(`Package release updated!`)
45
- }
@@ -1,16 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
- import { z } from "zod"
3
-
4
- export const packagesCreate = async (ctx: AppContext, args: any) => {
5
- const params = z
6
- .object({
7
- name: z.string(),
8
- description: z.string().optional(),
9
- authorAccountId: z.string().optional(),
10
- })
11
- .parse(args)
12
-
13
- await ctx.axios.post("/packages/create", params)
14
-
15
- console.log(`Package "${params.name}" created!`)
16
- }
@@ -1,16 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
- import { z } from "zod"
3
-
4
- export const packagesGet = async (ctx: AppContext, args: any) => {
5
- args.packageId = args.package_id
6
- const params = z
7
- .object({ package_id: z.string() })
8
- .or(z.object({ name: z.string() }))
9
- .parse(args)
10
-
11
- const {
12
- data: { package: pkg },
13
- } = await ctx.axios.post("/packages/get", params)
14
-
15
- console.log(pkg)
16
- }
@@ -1,16 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
-
3
- export const packagesList = async (ctx: AppContext, args: any) => {
4
- const {
5
- data: { packages },
6
- } = await ctx.axios.post("/packages/list", {})
7
-
8
- if (packages.length === 0) {
9
- console.log("No packages found")
10
- } else {
11
- console.log("packages:")
12
- }
13
- for (const pkg of packages) {
14
- console.log(`- ${pkg.name}`)
15
- }
16
- }
@@ -1,336 +0,0 @@
1
- import kleur from "kleur"
2
- import { z } from "zod"
3
- import { AppContext } from "../../util/app-context"
4
- import * as Path from "path/posix"
5
- import * as fs from "fs/promises"
6
- import { existsSync, readFileSync } from "fs"
7
- import { getAllPackageFiles } from "cli/lib/util/get-all-package-files"
8
- import prompts from "prompts"
9
- import { getGeneratedReadme } from "../init/get-generated-readme"
10
- import { soupify } from "../../soupify/soupify"
11
- import { inferExportNameFromSource } from "../dev/infer-export-name-from-source"
12
- import $ from "dax-sh"
13
- import semver from "semver"
14
- import { unlink } from "fs/promises"
15
- import esbuild from "esbuild"
16
-
17
- export const publish = async (ctx: AppContext, args: any) => {
18
- const params = z
19
- .object({
20
- increment: z.boolean().optional(),
21
- patch: z.boolean().optional(),
22
- lock: z.boolean().optional(),
23
- })
24
- .parse(args)
25
-
26
- const shouldIncrement = params.increment || params.patch
27
-
28
- if (!existsSync(Path.join(ctx.cwd, "package.json"))) {
29
- console.log(kleur.red("No package.json found in current directory"))
30
- process.exit(1)
31
- }
32
-
33
- const packageJson = JSON.parse(
34
- await readFileSync(Path.join(ctx.cwd, "package.json"), "utf-8"),
35
- )
36
-
37
- if (!packageJson.version) {
38
- console.log(kleur.yellow("No version found in package.json"))
39
- console.log(kleur.green("Setting package.json version to 0.0.1"))
40
- packageJson.version = "0.0.1"
41
- await fs.writeFile(
42
- Path.join(ctx.cwd, "package.json"),
43
- JSON.stringify(packageJson, null, 2),
44
- )
45
- }
46
-
47
- // This works but doesn't emit types, we're just going to build somewhat
48
- // normally for now
49
- // await esbuild.build({
50
- // entryPoints: ["index.ts"], // TODO dynamically determine entrypoint
51
- // bundle: true,
52
- // platform: "node",
53
- // packages: "external",
54
- // outdir: "dist",
55
- // })
56
- await $`npm run build`
57
-
58
- if (packageJson.module) {
59
- console.log(kleur.yellow("package.json module field detected. Removing..."))
60
- delete packageJson.module
61
- await fs.writeFile(
62
- Path.join(ctx.cwd, "package.json"),
63
- JSON.stringify(packageJson, null, 2),
64
- )
65
- }
66
-
67
- if (packageJson.main !== "./dist/index.cjs") {
68
- console.log(
69
- kleur.yellow(
70
- `package.json "main" field is not set to "./dist/index.cjs". Setting it...`,
71
- ),
72
- )
73
- packageJson.main = "./dist/index.cjs"
74
- await fs.writeFile(
75
- Path.join(ctx.cwd, "package.json"),
76
- JSON.stringify(packageJson, null, 2),
77
- )
78
- }
79
- if (packageJson.types !== "./index.ts") {
80
- console.log(
81
- kleur.yellow(
82
- `package.json "types" field is not set to "./index.ts". Setting it...`,
83
- ),
84
- )
85
- packageJson.types = "./index.ts"
86
- await fs.writeFile(
87
- Path.join(ctx.cwd, "package.json"),
88
- JSON.stringify(packageJson, null, 2),
89
- )
90
- }
91
- if (!packageJson.files) {
92
- console.log(
93
- kleur.yellow(
94
- `package.json "files" field is not set. Setting it to ["./dist", "index.ts", "./lib"]...`,
95
- ),
96
- )
97
- packageJson.files = ["dist", "index.ts", "lib"]
98
- await fs.writeFile(
99
- Path.join(ctx.cwd, "package.json"),
100
- JSON.stringify(packageJson, null, 2),
101
- )
102
- }
103
-
104
- // Upload to tscircuit registry
105
- // 1. Get the package name and version from package.json
106
- let { name, version } = packageJson
107
- name = name.replace(/^@/, "") // remove leading @ if it exists
108
- // 2.1 Check if package already exists, if it doesn't, create it
109
- const existingPackage = await ctx.axios
110
- .post("/packages/get", { name })
111
- .then((r) => r.data.package)
112
- .catch((e) => {
113
- if (e.response?.data?.error?.error_code === "package_not_found")
114
- return null
115
- throw e
116
- })
117
-
118
- if (!existingPackage) {
119
- if (!packageJson.name.includes("/")) {
120
- console.log(
121
- kleur.yellow(
122
- `Package name "${packageJson.name}" is not scoped. Scoped package names are recommended on the tscircuit registry.`,
123
- ),
124
- )
125
- const myAccount = await ctx.axios
126
- .get("/accounts/get")
127
- .then((r) => r.data.account)
128
- const newScopedName = `${myAccount.github_username}/${packageJson.name}`
129
-
130
- const { confirmNameChange } = await prompts({
131
- type: "confirm",
132
- name: "confirmNameChange",
133
- initial: true,
134
- message: `Would you like to change the package name to the scoped name "@${newScopedName}"?`,
135
- })
136
-
137
- if (confirm === undefined) {
138
- console.log(kleur.red("Aborted."))
139
- process.exit(1)
140
- }
141
-
142
- if (confirmNameChange) {
143
- packageJson.name = `@${newScopedName}`
144
- await fs.writeFile(
145
- Path.join(ctx.cwd, "package.json"),
146
- JSON.stringify(packageJson, null, 2),
147
- )
148
- name = newScopedName
149
- }
150
- }
151
-
152
- console.log(
153
- kleur.green(
154
- `Creating package "${packageJson.name}" on tscircuit registry...`,
155
- ),
156
- )
157
- let description = packageJson.description
158
- if (!description) {
159
- description = (
160
- await prompts({
161
- type: "text",
162
- name: "description",
163
- message: "Enter a description for the package",
164
- })
165
- ).description
166
- }
167
- await ctx.axios
168
- .post("/packages/create", { name, description })
169
- .then((r) => r.data.package)
170
- }
171
- // 2.2 Check if package release already exists
172
- const existingRelease = await ctx.axios
173
- .post("/package_releases/get", {
174
- package_name_with_version: `${name}@${version}`,
175
- })
176
- .then((r) => r.data.package_release)
177
- .catch((e) => {
178
- if (e.response?.data?.error?.error_code === "package_release_not_found")
179
- return null
180
- throw e
181
- })
182
- // 3. If it does, ask to increment the version or update the existing release, if increment is specified, increment the version automatically
183
- if (existingRelease) {
184
- console.log(
185
- kleur.gray(`Package release already exists: ${name}@${version}`),
186
- )
187
- if (shouldIncrement) {
188
- console.log(
189
- kleur.green(
190
- `Incrementing version from ${version} to ${semver.inc(
191
- version,
192
- "patch",
193
- )}...`,
194
- ),
195
- )
196
- version = semver.inc(version, "patch")
197
- packageJson.version = version
198
- await fs.writeFile(
199
- Path.join(ctx.cwd, "package.json"),
200
- JSON.stringify(packageJson, null, 2),
201
- )
202
- } else {
203
- console.log(
204
- kleur.blue(
205
- `Want to increment the version and publish a new release? Use "--increment"!`,
206
- ),
207
- )
208
-
209
- throw new Error("Package release already exists")
210
- }
211
- }
212
- // 4. Create new package_release
213
- const newRelease = await ctx.axios
214
- .post("/package_releases/create", {
215
- package_name_with_version: `${name}@${version}`,
216
- is_latest: false, // only make it latest when locking
217
- })
218
- .then((r) => r.data.package_release)
219
- // 5. Upload package_files
220
- const filePaths = await getAllPackageFiles(ctx)
221
- if (!filePaths.includes("README.md")) {
222
- console.log(
223
- kleur.yellow(
224
- "No README.md found in package files. A README.md is recommended on the tscircuit registry.",
225
- ),
226
- )
227
- const { confirmReadme } = await prompts({
228
- type: "confirm",
229
- name: "confirmReadme",
230
- initial: true,
231
- message: "Would you like to add a README.md?",
232
- })
233
-
234
- if (confirmReadme === undefined) {
235
- console.log(kleur.red("Aborted."))
236
- process.exit(1)
237
- }
238
-
239
- if (confirmReadme) {
240
- await fs.writeFile(
241
- Path.join(ctx.cwd, "README.md"),
242
- getGeneratedReadme({ name }),
243
- )
244
- filePaths.push("README.md")
245
- }
246
- }
247
-
248
- for (const filePath of filePaths) {
249
- const fileContent = await fs.readFile(Path.join(ctx.cwd, filePath))
250
-
251
- await ctx.axios
252
- .post("/package_files/create", {
253
- file_path: filePath,
254
- content_text: fileContent.toString(),
255
- package_name_with_version: `${name}@${version}`,
256
- })
257
- .then((r) => r.data.package_file)
258
- }
259
- // 6. Upload package_examples
260
- const exampleFilePaths = filePaths.filter((fp) => fp.startsWith("examples/"))
261
- for (const filePath of exampleFilePaths) {
262
- const fileContent = (
263
- await fs.readFile(Path.join(ctx.cwd, filePath))
264
- ).toString()
265
-
266
- const exportName = inferExportNameFromSource(fileContent)
267
-
268
- const tscircuit_soup = await soupify(
269
- {
270
- filePath,
271
- exportName,
272
- },
273
- ctx,
274
- ).catch((e) => e)
275
-
276
- if (tscircuit_soup instanceof Error) {
277
- console.log(
278
- kleur.red(`Error soupifying ${filePath}: ${tscircuit_soup}, skipping`),
279
- )
280
- continue
281
- }
282
-
283
- await ctx.axios
284
- .post("/package_examples/create", {
285
- file_path: filePath,
286
- package_name_with_version: `${name}@${version}`,
287
- export_name: exportName,
288
- source_content: fileContent,
289
- tscircuit_soup,
290
- })
291
- .then((r) => r.data.package_example)
292
- }
293
-
294
- // 7. Create tarball and upload
295
- const tmpTarballPath = Path.join(
296
- ctx.cwd,
297
- ".tscircuit/tmp",
298
- `${name.replace(/\//g, "-")}-${version}.tgz`,
299
- )
300
- await fs.mkdir(Path.dirname(tmpTarballPath), { recursive: true })
301
- const npm_pack_outputs = await $`cd ${
302
- ctx.cwd
303
- } && npm pack --json --pack-destination ${Path.dirname(
304
- tmpTarballPath,
305
- )}`.json()
306
-
307
- if (!existsSync(tmpTarballPath)) {
308
- console.log(kleur.red(`Couldn't find tarball at ${tmpTarballPath}`))
309
- process.exit(1)
310
- }
311
-
312
- // Upload tarball
313
- await ctx.axios.post("/package_files/create", {
314
- file_path: `.tscircuit-internal/tarball.tgz`,
315
- content_base64: (await fs.readFile(tmpTarballPath)).toString("base64"),
316
- package_name_with_version: `${name}@${version}`,
317
- is_release_tarball: true,
318
- npm_pack_output: npm_pack_outputs?.[0],
319
- })
320
-
321
- // Clean up .tscircuit/tmp
322
- await unlink(tmpTarballPath)
323
-
324
- // 8. Lock/set release to latest version
325
- await ctx.axios.post("/package_releases/update", {
326
- package_name_with_version: `${name}@${version}`,
327
- is_locked: params.lock ? true : false,
328
- is_latest: true,
329
- })
330
-
331
- console.log(
332
- kleur.green(
333
- `Published ${name}@${version}!\nhttps://registry.tscircuit.com/${name}`,
334
- ),
335
- )
336
- }
@@ -1,31 +0,0 @@
1
- import kleur from "kleur"
2
- import { AppContext } from "cli/lib/util/app-context"
3
- import { z } from "zod"
4
- import { createOrModifyNpmrc } from "./init/create-or-modify-npmrc"
5
- import $ from "dax-sh"
6
-
7
- export const removeCmd = async (ctx: AppContext, args: any) => {
8
- const params = z
9
- .object({
10
- packages: z.array(z.string()),
11
- flags: z.object({}).optional().default({}),
12
- })
13
- .parse(args)
14
-
15
- params.packages = params.packages.map((p) => p.replace(/^@/, ""))
16
-
17
- await createOrModifyNpmrc({ quiet: true }, ctx)
18
-
19
- $.cd(ctx.cwd)
20
-
21
- const flagsString = ""
22
-
23
- const cmd = `npm remove ${flagsString} ${params.packages
24
- .map((p) => `@tsci/${p.replace(/\//, ".")}`)
25
- .join(" ")}`
26
- console.log(kleur.gray(`> ${cmd}`))
27
-
28
- await $`npm remove ${flagsString} ${params.packages.map(
29
- (p) => `@tsci/${p.replace(/\//, ".")}`,
30
- )}`
31
- }
@@ -1,45 +0,0 @@
1
- import { soupify } from "cli/lib/soupify"
2
- import type { AppContext } from "cli/lib/util/app-context"
3
- import fs from "fs"
4
- import path from "path/posix"
5
-
6
- export const renderCmd = async (
7
- ctx: AppContext,
8
- args: {
9
- input: string
10
- pcb?: boolean
11
- schematic?: boolean
12
- output?: string
13
- type?: string
14
- },
15
- ) => {
16
- const inputFile = path.resolve(args.input)
17
- let outputFile = args.output
18
- const outputType =
19
- args.type || path.extname(args.output || "").slice(1) || "png"
20
-
21
- if (!outputFile) {
22
- const inputBase = path.basename(inputFile, path.extname(inputFile))
23
- outputFile = `${inputBase}.${outputType}`
24
- }
25
-
26
- if (!args.pcb && !args.schematic) {
27
- console.error("Error: You must specify either --pcb or --schematic")
28
- process.exit(1)
29
- }
30
-
31
- const viewType = args.pcb ? "pcb" : "schematic"
32
-
33
- console.log(`Rendering ${viewType} view of ${inputFile} to ${outputFile}`)
34
- const soup = await soupify(
35
- {
36
- filePath: inputFile,
37
- },
38
- ctx,
39
- )
40
-
41
- const { circuitToPng } = await import("circuit-to-png")
42
- const soupBuffer = circuitToPng(soup, viewType)
43
-
44
- fs.writeFileSync(outputFile, soupBuffer)
45
- }
@@ -1,31 +0,0 @@
1
- import { AppContext } from "../util/app-context"
2
- import { z } from "zod"
3
- import * as Path from "path/posix"
4
- import { unlink } from "node:fs/promises"
5
- import { soupify } from "cli/lib/soupify"
6
- import { writeFileSync } from "fs"
7
-
8
- export const soupifyCmd = async (ctx: AppContext, args: any) => {
9
- const params = z
10
- .object({
11
- file: z.string(),
12
- export: z.string().optional(),
13
- output: z.string().optional(),
14
- noCore: z.boolean().optional(),
15
- })
16
- .parse(args)
17
-
18
- const soup = await soupify(
19
- {
20
- filePath: params.file,
21
- exportName: params.export,
22
- },
23
- ctx,
24
- )
25
-
26
- if (params.output) {
27
- await writeFileSync(params.output, JSON.stringify(soup, null, 2))
28
- } else {
29
- console.log(JSON.stringify(soup, null, 2))
30
- }
31
- }