@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.
- package/.github/workflows/bun-formatcheck.yml +26 -0
- package/.github/workflows/bun-pver-release.yml +25 -0
- package/.github/workflows/{typecheck.yml → bun-typecheck.yml} +0 -3
- package/LICENSE +21 -0
- package/README.md +33 -36
- package/biome.json +9 -9
- package/bun.lockb +0 -0
- package/cli/CliContext.ts +8 -0
- package/cli/auth/login/register.ts +73 -0
- package/cli/auth/logout/register.ts +11 -0
- package/cli/auth/register.ts +5 -0
- package/cli/clone/register.ts +99 -0
- package/cli/config/print/register.ts +12 -0
- package/cli/config/register.ts +5 -0
- package/cli/dev/register.ts +111 -0
- package/cli/main.ts +33 -0
- package/dist/main.js +537 -0
- package/docs/file-server-api-usage.md +57 -0
- package/docs/run-frame-usage.md +14 -0
- package/example-dir/manual-edits.json +1 -0
- package/example-dir/snippet.d.ts +13 -0
- package/example-dir/snippet.tsx +20 -0
- package/example-dir/types.d.ts +11 -0
- package/lib/cli-config/TypedConfigStore.ts +50 -0
- package/lib/cli-config/index.ts +16 -0
- package/lib/dependency-analysis/DependencyAnalyzer.ts +129 -0
- package/lib/dependency-analysis/getLocalFileDependencies.ts +101 -0
- package/lib/dependency-analysis/installNodeModuleTypes.ts +74 -0
- package/lib/index.ts +2 -0
- package/lib/project-config/index.ts +5 -0
- package/lib/registry-api/endpoint-types.ts +20 -0
- package/lib/registry-api/get-ky.ts +30 -0
- package/lib/server/EventsWatcher.ts +75 -0
- package/lib/server/createServer.ts +62 -0
- package/lib/site/getIndex.ts +18 -0
- package/package.json +27 -144
- package/tsconfig.json +25 -22
- package/.github/workflows/formatbot.yml +0 -63
- package/.github/workflows/release.yml +0 -40
- package/.github/workflows/test.yml +0 -32
- package/.github/workflows/windows-tests.yml +0 -32
- package/.prettierrc +0 -1
- package/DEVELOPMENT.md +0 -7
- package/api/README.md +0 -3
- package/api/db/generic-json-level.ts +0 -123
- package/api/db/get-db.ts +0 -26
- package/api/db/schema.ts +0 -65
- package/api/db/zod-level-db.ts +0 -148
- package/api/index.ts +0 -4
- package/api/lib/middlewares/with-db.ts +0 -18
- package/api/lib/middlewares/with-debug-request-logging.ts +0 -13
- package/api/lib/middlewares/with-error-response.ts +0 -37
- package/api/lib/with-winter-spec.ts +0 -9
- package/api/lib/zod/export_parameters.ts +0 -25
- package/api/routes/api/db/download.ts +0 -25
- package/api/routes/api/dev_package_examples/create.ts +0 -43
- package/api/routes/api/dev_package_examples/get.ts +0 -46
- package/api/routes/api/dev_package_examples/list.ts +0 -36
- package/api/routes/api/dev_package_examples/update.ts +0 -59
- package/api/routes/api/dev_server/reset.ts +0 -13
- package/api/routes/api/export_files/create.ts +0 -27
- package/api/routes/api/export_files/download.ts +0 -25
- package/api/routes/api/export_requests/create.ts +0 -30
- package/api/routes/api/export_requests/get.ts +0 -43
- package/api/routes/api/export_requests/list.ts +0 -26
- package/api/routes/api/export_requests/update.ts +0 -34
- package/api/routes/api/health.ts +0 -11
- package/api/routes/api/package_info/create.ts +0 -26
- package/api/routes/api/package_info/get.ts +0 -16
- package/api/routes/health.ts +0 -11
- package/api/routes/index.ts +0 -16
- package/api/server.ts +0 -20
- package/api/static-routes.ts +0 -24
- package/api/tests/fixtures/get-test-server.ts +0 -31
- package/api/tests/fixtures/start-server.ts +0 -41
- package/api/tests/routes/dev_package_examples/create.test.ts +0 -19
- package/api/tests/routes/dev_package_examples/get.test.ts +0 -25
- package/api/tests/routes/dev_package_examples/list.test.ts +0 -32
- package/api/tests/routes/dev_package_examples/update.test.ts +0 -38
- package/api/tests/routes/export_files/create.test.ts +0 -18
- package/api/tests/routes/export_files/download.test.ts +0 -29
- package/api/tests/routes/export_requests/create.test.ts +0 -24
- package/api/tests/routes/export_requests/get.test.ts +0 -41
- package/api/tests/routes/export_requests/list.test.ts +0 -35
- package/api/tests/routes/export_requests/update.test.ts +0 -50
- package/api/tests/routes/health.test.ts +0 -10
- package/bunfig.toml +0 -2
- package/cli/cli.ts +0 -13
- package/cli/lib/cmd-fns/add.ts +0 -34
- package/cli/lib/cmd-fns/auth-login.ts +0 -59
- package/cli/lib/cmd-fns/auth-logout.ts +0 -7
- package/cli/lib/cmd-fns/auth-sessions-create.ts +0 -3
- package/cli/lib/cmd-fns/auth-sessions-get.ts +0 -3
- package/cli/lib/cmd-fns/auth-sessions-list.ts +0 -5
- package/cli/lib/cmd-fns/config-clear.ts +0 -5
- package/cli/lib/cmd-fns/config-print-config.ts +0 -6
- package/cli/lib/cmd-fns/config-reveal-location.ts +0 -5
- package/cli/lib/cmd-fns/config-set-log-requests.ts +0 -7
- package/cli/lib/cmd-fns/config-set-registry.ts +0 -9
- package/cli/lib/cmd-fns/config-set-runtime.ts +0 -7
- package/cli/lib/cmd-fns/config-set-session.ts +0 -7
- package/cli/lib/cmd-fns/dev/check-if-initialized.ts +0 -22
- package/cli/lib/cmd-fns/dev/derive-selector-from-pcb-component-id.ts +0 -23
- package/cli/lib/cmd-fns/dev/dev-server-request-handler.ts +0 -61
- package/cli/lib/cmd-fns/dev/find-available-port.ts +0 -32
- package/cli/lib/cmd-fns/dev/fulfill-export-requests.ts +0 -162
- package/cli/lib/cmd-fns/dev/get-dev-server-axios.ts +0 -29
- package/cli/lib/cmd-fns/dev/index.ts +0 -168
- package/cli/lib/cmd-fns/dev/infer-export-name-from-source.ts +0 -17
- package/cli/lib/cmd-fns/dev/mark-all-examples-loading.ts +0 -18
- package/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts +0 -62
- package/cli/lib/cmd-fns/dev/start-dev-server.ts +0 -34
- package/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts +0 -347
- package/cli/lib/cmd-fns/dev/start-export-request-watcher.ts +0 -33
- package/cli/lib/cmd-fns/dev/start-fs-watcher.ts +0 -54
- package/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts +0 -42
- package/cli/lib/cmd-fns/dev-server-fulfill-export-requests.ts +0 -43
- package/cli/lib/cmd-fns/dev-server-upload.ts +0 -56
- package/cli/lib/cmd-fns/export-gerbers.ts +0 -28
- package/cli/lib/cmd-fns/export-kicad-pcb.ts +0 -36
- package/cli/lib/cmd-fns/export-pnp-csv.ts +0 -32
- package/cli/lib/cmd-fns/gen-jlcpcb-component.ts +0 -64
- package/cli/lib/cmd-fns/go.ts +0 -14
- package/cli/lib/cmd-fns/index.ts +0 -46
- package/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts +0 -21
- package/cli/lib/cmd-fns/init/get-generated-npmrc.ts +0 -8
- package/cli/lib/cmd-fns/init/get-generated-readme.ts +0 -41
- package/cli/lib/cmd-fns/init/get-generated-tsconfig.ts +0 -34
- package/cli/lib/cmd-fns/init/index.ts +0 -193
- package/cli/lib/cmd-fns/install.ts +0 -34
- package/cli/lib/cmd-fns/lint.ts +0 -43
- package/cli/lib/cmd-fns/open.ts +0 -19
- package/cli/lib/cmd-fns/package-examples-create.ts +0 -36
- package/cli/lib/cmd-fns/package-examples-get.ts +0 -20
- package/cli/lib/cmd-fns/package-examples-list.ts +0 -18
- package/cli/lib/cmd-fns/package-files-create.ts +0 -31
- package/cli/lib/cmd-fns/package-files-download.ts +0 -29
- package/cli/lib/cmd-fns/package-files-get.ts +0 -3
- package/cli/lib/cmd-fns/package-files-list.ts +0 -28
- package/cli/lib/cmd-fns/package-files-upload-directory.ts +0 -6
- package/cli/lib/cmd-fns/package-releases-create.ts +0 -35
- package/cli/lib/cmd-fns/package-releases-get.ts +0 -3
- package/cli/lib/cmd-fns/package-releases-list.ts +0 -32
- package/cli/lib/cmd-fns/package-releases-update.ts +0 -45
- package/cli/lib/cmd-fns/packages-create.ts +0 -16
- package/cli/lib/cmd-fns/packages-get.ts +0 -16
- package/cli/lib/cmd-fns/packages-list.ts +0 -16
- package/cli/lib/cmd-fns/publish/index.ts +0 -336
- package/cli/lib/cmd-fns/remove.ts +0 -31
- package/cli/lib/cmd-fns/render.ts +0 -45
- package/cli/lib/cmd-fns/soupify.ts +0 -31
- package/cli/lib/cmd-fns/uninstall.ts +0 -31
- package/cli/lib/cmd-fns/version.ts +0 -38
- package/cli/lib/create-config-manager.ts +0 -97
- package/cli/lib/export-fns/export-bom-csv.ts +0 -32
- package/cli/lib/export-fns/export-gerbers.ts +0 -108
- package/cli/lib/export-fns/export-kicad-pcb.ts +0 -32
- package/cli/lib/export-fns/export-pnp-csv.ts +0 -31
- package/cli/lib/get-program.ts +0 -387
- package/cli/lib/param-handlers/index.ts +0 -21
- package/cli/lib/param-handlers/interact-for-local-directory.ts +0 -58
- package/cli/lib/param-handlers/interact-for-local-file.ts +0 -59
- package/cli/lib/param-handlers/interact-for-package-example-id.ts +0 -25
- package/cli/lib/param-handlers/interact-for-package-name-with-version.ts +0 -63
- package/cli/lib/param-handlers/interact-for-package-name.ts +0 -45
- package/cli/lib/param-handlers/interact-for-package-release-id.ts +0 -15
- package/cli/lib/param-handlers/interact-for-registry-url.ts +0 -27
- package/cli/lib/param-handlers/interact-for-runtime.ts +0 -33
- package/cli/lib/param-handlers/param-handler-type.ts +0 -7
- package/cli/lib/posthog.ts +0 -23
- package/cli/lib/soupify/get-export-name-from-file.ts +0 -29
- package/cli/lib/soupify/get-tmp-entrpoint-filepath.ts +0 -15
- package/cli/lib/soupify/index.ts +0 -1
- package/cli/lib/soupify/run-entrypoint-file.ts +0 -59
- package/cli/lib/soupify/soupify-with-core.ts +0 -74
- package/cli/lib/soupify/soupify.ts +0 -6
- package/cli/lib/util/app-context.ts +0 -17
- package/cli/lib/util/create-context-and-run-program.ts +0 -168
- package/cli/lib/util/get-all-package-files.ts +0 -66
- package/cli/lib/util/lint-project.ts +0 -137
- package/cli/tests/export-gerber-keyboard.test.ts +0 -16
- package/cli/tests/export-gerber.test.ts +0 -49
- package/cli/tests/export-kicad-pcb.test.ts +0 -23
- package/cli/tests/export-pnp-csv.test.ts +0 -24
- package/cli/tests/fixtures/preload.ts +0 -54
- package/cli/tests/init.test.ts +0 -9
- package/cli/tests/open.test.ts +0 -9
- package/cli/tests/soupify-builder.test.ts +0 -9
- package/cli/tests/soupify-core.test.ts +0 -9
- package/dist/cli.js +0 -3676
- package/docs/EDIT_EVENT_PIPELINE.md +0 -34
- package/example-project/README.md +0 -18
- package/example-project/examples/basic-capacitor.tsx +0 -5
- package/example-project/examples/basic-chip.tsx +0 -26
- package/example-project/examples/basic-resistor.tsx +0 -3
- package/example-project/examples/macrokeypad.tsx +0 -59
- package/example-project/index.ts +0 -1
- package/example-project/package.json +0 -5
- package/example-project/src/ArduinoProMicroBreakout.tsx +0 -37
- package/example-project/src/Key.tsx +0 -46
- package/example-project/src/Keyswitch.tsx +0 -26
- package/example-project/src/KeyswitchSocket.tsx +0 -56
- package/example-project/src/MyCircuit.tsx +0 -38
- package/example-project/src/manual-edits.ts +0 -93
- package/frontend/README.md +0 -3
- package/frontend/bun.lockb +0 -0
- package/frontend/components/command-k.tsx +0 -86
- package/frontend/components/dialogs/generic-export-dialog.tsx +0 -189
- package/frontend/components/dialogs/gerber-export-dialog.tsx +0 -168
- package/frontend/components/global-context-providers.tsx +0 -11
- package/frontend/components/select-example-search.tsx +0 -118
- package/frontend/components/ui/alert-dialog.tsx +0 -139
- package/frontend/components/ui/alert.tsx +0 -59
- package/frontend/components/ui/breadcrumb.tsx +0 -115
- package/frontend/components/ui/button.tsx +0 -57
- package/frontend/components/ui/card.tsx +0 -76
- package/frontend/components/ui/command.tsx +0 -153
- package/frontend/components/ui/context-menu.tsx +0 -202
- package/frontend/components/ui/dialog.tsx +0 -120
- package/frontend/components/ui/menubar.tsx +0 -238
- package/frontend/components/ui/navigation-menu.tsx +0 -128
- package/frontend/components/ui/popover.tsx +0 -31
- package/frontend/components/ui/select.tsx +0 -162
- package/frontend/components/ui/tabs.tsx +0 -53
- package/frontend/components/ui/toggle-group.tsx +0 -59
- package/frontend/components/ui/toggle.tsx +0 -43
- package/frontend/components/ui/tooltip.tsx +0 -28
- package/frontend/components.json +0 -17
- package/frontend/hooks/toast-if-api-not-connected.ts +0 -23
- package/frontend/hooks/use-active-dev-package-example-lite.ts +0 -39
- package/frontend/hooks/use-dev-package-examples.tsx +0 -18
- package/frontend/hooks/use-global-store.ts +0 -42
- package/frontend/index.css +0 -76
- package/frontend/index.html +0 -13
- package/frontend/lib/utils.ts +0 -6
- package/frontend/main.tsx +0 -13
- package/frontend/tailwind.config.js +0 -74
- package/frontend/views/App.tsx +0 -22
- package/frontend/views/Header.tsx +0 -55
- package/frontend/views/HeaderMenu.tsx +0 -326
- package/frontend/views/MainContentView.tsx +0 -172
- package/frontend/vite-env.d.ts +0 -1
- package/frontend/vite.config.ts +0 -50
- package/renovate.json +0 -16
- package/scripts/build-cli.ts +0 -12
- package/tsup.config.ts +0 -7
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AppContext } from "../util/app-context"
|
|
2
|
-
import { z } from "zod"
|
|
3
|
-
|
|
4
|
-
export const configSetLogRequests = async (ctx: AppContext, args: any) => {
|
|
5
|
-
const params = z.object({ logRequests: z.boolean() }).parse(args)
|
|
6
|
-
ctx.global_config.set("log_requests", params.logRequests)
|
|
7
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AppContext } from "../util/app-context"
|
|
2
|
-
import { z } from "zod"
|
|
3
|
-
|
|
4
|
-
export const configSetRegistry = async (ctx: AppContext, args: any) => {
|
|
5
|
-
const params = z.object({ server: z.string().url() }).parse(args)
|
|
6
|
-
// don't want to re-use auth token
|
|
7
|
-
ctx.profile_config.clear()
|
|
8
|
-
ctx.profile_config.set("registry_url", params.server)
|
|
9
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AppContext } from "../util/app-context"
|
|
2
|
-
import { z } from "zod"
|
|
3
|
-
|
|
4
|
-
export const configSetRuntime = async (ctx: AppContext, args: any) => {
|
|
5
|
-
const params = z.object({ runtime: z.enum(["bun", "node"]) }).parse(args)
|
|
6
|
-
ctx.global_config.set("runtime", params.runtime)
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AppContext } from "../util/app-context"
|
|
2
|
-
import { z } from "zod"
|
|
3
|
-
|
|
4
|
-
export const configSetSession = async (ctx: AppContext, args: any) => {
|
|
5
|
-
const params = z.object({ sessionToken: z.string() }).parse(args)
|
|
6
|
-
ctx.profile_config.set("session_token", params.sessionToken)
|
|
7
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { AppContext } from "../../util/app-context"
|
|
2
|
-
import kleur from "kleur"
|
|
3
|
-
import * as Path from "path/posix"
|
|
4
|
-
import { existsSync, readFileSync } from "fs"
|
|
5
|
-
|
|
6
|
-
export const checkIfInitialized = async (ctx: AppContext) => {
|
|
7
|
-
const packageJsonPath = Path.join(ctx.cwd, "package.json")
|
|
8
|
-
if (!existsSync(packageJsonPath)) {
|
|
9
|
-
console.error(kleur.red(`No package.json found`))
|
|
10
|
-
return false
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const packageJsonRaw = readFileSync(packageJsonPath, "utf-8")
|
|
14
|
-
if (!packageJsonRaw.includes("tscircuit")) {
|
|
15
|
-
console.error(
|
|
16
|
-
kleur.red(`No tscircuit dependencies are installed in this project.`),
|
|
17
|
-
)
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return true
|
|
22
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { AnySoupElement } from "@tscircuit/soup"
|
|
2
|
-
import { su } from "@tscircuit/soup-util"
|
|
3
|
-
|
|
4
|
-
export const deriveSelectorFromPcbComponentId = ({
|
|
5
|
-
soup,
|
|
6
|
-
pcb_component_id,
|
|
7
|
-
}: {
|
|
8
|
-
soup: AnySoupElement[]
|
|
9
|
-
pcb_component_id: string
|
|
10
|
-
}) => {
|
|
11
|
-
const source_component = su(soup as any).source_component.getUsing({
|
|
12
|
-
pcb_component_id,
|
|
13
|
-
})
|
|
14
|
-
if (!source_component) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
`Could not find source component for pcb_component_id="${pcb_component_id}"`,
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// TODO travel up the tree to make the selector more specific
|
|
21
|
-
|
|
22
|
-
return `.${source_component.name}`
|
|
23
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import apiServer from "api/index"
|
|
2
|
-
import frontendVfs from "frontend/dist/bundle"
|
|
3
|
-
import EdgeRuntimePrimitives from "@edge-runtime/primitives"
|
|
4
|
-
import mime from "mime-types"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Handles all requests to :3020, then proxies...
|
|
8
|
-
*
|
|
9
|
-
* /api/* : to the api server
|
|
10
|
-
* /* : to the static frontend bundle inside dev-server-frontend
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
export const devServerRequestHandler = async (bunReq: Request) => {
|
|
14
|
-
const url = new URL(bunReq.url)
|
|
15
|
-
const requestType = url.pathname.startsWith("/api")
|
|
16
|
-
? "api"
|
|
17
|
-
: url.pathname.startsWith("/preview")
|
|
18
|
-
? "preview"
|
|
19
|
-
: "other"
|
|
20
|
-
|
|
21
|
-
if (requestType === "api") {
|
|
22
|
-
// We have to shim Bun's Request until they fix the issue where
|
|
23
|
-
// .clone() doesn't clone the body
|
|
24
|
-
// https://github.com/oven-sh/bun/pull/8668
|
|
25
|
-
const req = new EdgeRuntimePrimitives.Request(bunReq.url, {
|
|
26
|
-
headers: bunReq.headers,
|
|
27
|
-
method: bunReq.method,
|
|
28
|
-
body: bunReq.body,
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
const response = await apiServer.makeRequest(req as any, {})
|
|
32
|
-
return response
|
|
33
|
-
} else if (requestType === "preview") {
|
|
34
|
-
let frontendPath = url.pathname.replace("/preview", "")
|
|
35
|
-
if (frontendPath === "/" || frontendPath === "") {
|
|
36
|
-
frontendPath = "index.html"
|
|
37
|
-
}
|
|
38
|
-
frontendPath = frontendPath.replace(/^\//, "")
|
|
39
|
-
|
|
40
|
-
const fileContent: Buffer = (frontendVfs as any)[frontendPath]
|
|
41
|
-
if (!fileContent) {
|
|
42
|
-
return new Response("Not Found", { status: 404 })
|
|
43
|
-
}
|
|
44
|
-
return new Response(
|
|
45
|
-
// Buffer.from(fileContent.toString(), "base64").toString("utf-8"),
|
|
46
|
-
fileContent.toString("utf-8"),
|
|
47
|
-
{
|
|
48
|
-
headers: {
|
|
49
|
-
"Content-Type": mime.lookup(frontendPath) || "text/plain",
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
)
|
|
53
|
-
} else {
|
|
54
|
-
return new Response(null, {
|
|
55
|
-
status: 302,
|
|
56
|
-
headers: {
|
|
57
|
-
Location: "/preview",
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import net from "net"
|
|
2
|
-
|
|
3
|
-
const MAX_PORT = 65535 // Maximum valid port number
|
|
4
|
-
|
|
5
|
-
export const findAvailablePort = async (startPort: number): Promise<number> => {
|
|
6
|
-
let port = startPort
|
|
7
|
-
|
|
8
|
-
while (port <= MAX_PORT) {
|
|
9
|
-
if (!(await isPortInUse(port))) {
|
|
10
|
-
return port
|
|
11
|
-
}
|
|
12
|
-
port++
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
throw new Error(
|
|
16
|
-
`Unable to find an available port in range ${startPort}-${MAX_PORT}`,
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const isPortInUse = (port: number): Promise<boolean> => {
|
|
21
|
-
return new Promise((resolve) => {
|
|
22
|
-
const server = net.createServer()
|
|
23
|
-
server.once("error", () => {
|
|
24
|
-
resolve(true)
|
|
25
|
-
})
|
|
26
|
-
server.once("listening", () => {
|
|
27
|
-
server.close()
|
|
28
|
-
resolve(false)
|
|
29
|
-
})
|
|
30
|
-
server.listen(port)
|
|
31
|
-
})
|
|
32
|
-
}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { AppContext } from "../../util/app-context"
|
|
2
|
-
import kleur from "kleur"
|
|
3
|
-
import { exportGerbersToZipBuffer } from "cli/lib/export-fns/export-gerbers"
|
|
4
|
-
import { AxiosInstance } from "axios"
|
|
5
|
-
import { exportPnpCsvToBuffer } from "cli/lib/export-fns/export-pnp-csv"
|
|
6
|
-
import { exportBomCsvToBuffer } from "cli/lib/export-fns/export-bom-csv"
|
|
7
|
-
import { soupify } from "cli/lib/soupify"
|
|
8
|
-
import { ExportRequest } from "api/db/schema"
|
|
9
|
-
import { exportKicadPcbToBuffer } from "cli/lib/export-fns/export-kicad-pcb"
|
|
10
|
-
|
|
11
|
-
export const uploadBufferToExportFile = async ({
|
|
12
|
-
dev_server_axios,
|
|
13
|
-
file_buffer,
|
|
14
|
-
file_name,
|
|
15
|
-
export_request_id,
|
|
16
|
-
}: {
|
|
17
|
-
dev_server_axios: AxiosInstance
|
|
18
|
-
file_buffer: Buffer
|
|
19
|
-
file_name: string
|
|
20
|
-
export_request_id: number
|
|
21
|
-
}) => {
|
|
22
|
-
await dev_server_axios.post("/api/export_files/create", {
|
|
23
|
-
file_content_base64: file_buffer.toString("base64"),
|
|
24
|
-
file_name: file_name,
|
|
25
|
-
export_request_id: export_request_id,
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
console.log(kleur.gray(` marking export request as complete...`))
|
|
29
|
-
|
|
30
|
-
await dev_server_axios.post("/api/export_requests/update", {
|
|
31
|
-
export_request_id: export_request_id,
|
|
32
|
-
is_complete: true,
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
console.log(kleur.green(` done`))
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const fulfillExportRequests = async (
|
|
39
|
-
{
|
|
40
|
-
dev_server_axios,
|
|
41
|
-
}: {
|
|
42
|
-
dev_server_axios: AxiosInstance
|
|
43
|
-
},
|
|
44
|
-
ctx: AppContext,
|
|
45
|
-
) => {
|
|
46
|
-
const export_requests: ExportRequest[] = await dev_server_axios
|
|
47
|
-
.post("/api/export_requests/list", {
|
|
48
|
-
is_complete: false,
|
|
49
|
-
})
|
|
50
|
-
.then((r) => r.data.export_requests)
|
|
51
|
-
|
|
52
|
-
for (const export_request of export_requests) {
|
|
53
|
-
console.log(
|
|
54
|
-
kleur.gray(
|
|
55
|
-
`Fulfilling export request ${export_request.export_request_id}`,
|
|
56
|
-
),
|
|
57
|
-
)
|
|
58
|
-
console.log(
|
|
59
|
-
kleur.gray(` example_file_path: ${export_request.example_file_path}`),
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
if (export_request.export_parameters.should_export_gerber_zip) {
|
|
63
|
-
console.log(kleur.gray(`\n exporting gerbers...`))
|
|
64
|
-
const zip_buffer = await exportGerbersToZipBuffer(
|
|
65
|
-
{
|
|
66
|
-
example_file_path: export_request.example_file_path!,
|
|
67
|
-
export_name: export_request.export_name!,
|
|
68
|
-
},
|
|
69
|
-
ctx,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
console.log(
|
|
73
|
-
kleur.gray(
|
|
74
|
-
` uploading zip "${export_request.export_parameters.gerbers_zip_file_name}" to dev server...`,
|
|
75
|
-
),
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
await uploadBufferToExportFile({
|
|
79
|
-
dev_server_axios,
|
|
80
|
-
file_buffer: zip_buffer,
|
|
81
|
-
file_name: export_request.export_parameters.gerbers_zip_file_name!,
|
|
82
|
-
export_request_id: export_request.export_request_id,
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (export_request.export_parameters.should_export_pnp_csv) {
|
|
87
|
-
console.log(kleur.gray(`\n exporting pick'n'place...`))
|
|
88
|
-
const csv_buffer = await exportPnpCsvToBuffer(
|
|
89
|
-
{
|
|
90
|
-
example_file_path: export_request.example_file_path!,
|
|
91
|
-
export_name: export_request.export_name!,
|
|
92
|
-
},
|
|
93
|
-
ctx,
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
const pnpFileName = `${export_request.export_name}-${export_request.export_parameters.pnp_csv_file_name!}`
|
|
97
|
-
|
|
98
|
-
await uploadBufferToExportFile({
|
|
99
|
-
dev_server_axios,
|
|
100
|
-
file_buffer: csv_buffer,
|
|
101
|
-
file_name: pnpFileName,
|
|
102
|
-
export_request_id: export_request.export_request_id,
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (export_request.export_parameters.should_export_bom_csv) {
|
|
107
|
-
console.log(kleur.gray(`\n exporting bill of materials...`))
|
|
108
|
-
const csv_buffer = await exportBomCsvToBuffer(
|
|
109
|
-
{
|
|
110
|
-
example_file_path: export_request.example_file_path!,
|
|
111
|
-
export_name: export_request.export_name!,
|
|
112
|
-
},
|
|
113
|
-
ctx,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
const bomFileName = `${export_request.export_name}-${export_request.export_parameters.bom_csv_file_name!}`
|
|
117
|
-
|
|
118
|
-
await uploadBufferToExportFile({
|
|
119
|
-
dev_server_axios,
|
|
120
|
-
file_buffer: csv_buffer,
|
|
121
|
-
file_name: bomFileName,
|
|
122
|
-
export_request_id: export_request.export_request_id,
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (export_request.export_parameters.should_export_soup_json) {
|
|
127
|
-
console.log(kleur.gray(`\n exporting soup...`))
|
|
128
|
-
const soup = await soupify(
|
|
129
|
-
{
|
|
130
|
-
filePath: export_request.example_file_path!,
|
|
131
|
-
exportName: export_request.export_name!,
|
|
132
|
-
},
|
|
133
|
-
ctx,
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
await uploadBufferToExportFile({
|
|
137
|
-
dev_server_axios,
|
|
138
|
-
file_buffer: Buffer.from(JSON.stringify(soup, null, 2), "utf-8"),
|
|
139
|
-
file_name: export_request.export_parameters.soup_json_file_name!,
|
|
140
|
-
export_request_id: export_request.export_request_id,
|
|
141
|
-
})
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (export_request.export_parameters.should_export_kicad_pcb) {
|
|
145
|
-
console.log(kleur.gray(`\n exporting KiCad PCB...`))
|
|
146
|
-
const kicadPcbBuffer = await exportKicadPcbToBuffer(
|
|
147
|
-
{
|
|
148
|
-
example_file_path: export_request.example_file_path!,
|
|
149
|
-
export_name: export_request.export_name!,
|
|
150
|
-
},
|
|
151
|
-
ctx,
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
await uploadBufferToExportFile({
|
|
155
|
-
dev_server_axios,
|
|
156
|
-
file_buffer: kicadPcbBuffer,
|
|
157
|
-
file_name: export_request.export_parameters.kicad_pcb_file_name!,
|
|
158
|
-
export_request_id: export_request.export_request_id,
|
|
159
|
-
})
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import kleur from "kleur"
|
|
2
|
-
import defaultAxios from "axios"
|
|
3
|
-
|
|
4
|
-
export const getDevServerAxios = ({ serverUrl }: { serverUrl: string }) => {
|
|
5
|
-
const devServerAxios = defaultAxios.create({
|
|
6
|
-
baseURL: serverUrl,
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
// https://github.com/oven-sh/bun/issues/267
|
|
10
|
-
devServerAxios.defaults.headers.common["Accept-Encoding"] = "gzip"
|
|
11
|
-
|
|
12
|
-
devServerAxios.interceptors.response.use(
|
|
13
|
-
(res) => res,
|
|
14
|
-
(err) => {
|
|
15
|
-
console.log(
|
|
16
|
-
kleur.red(
|
|
17
|
-
`[ERR] ${err.response?.status} ${err.config.method?.toUpperCase()} ${
|
|
18
|
-
err.config.url
|
|
19
|
-
}\n\n${JSON.stringify(err.response?.data, null, " ")}`
|
|
20
|
-
.replace(/\\n/g, "\n")
|
|
21
|
-
.replace(/\\"/g, '"'),
|
|
22
|
-
),
|
|
23
|
-
)
|
|
24
|
-
console.log(kleur.yellow("[Request Body]:"), err.config.data)
|
|
25
|
-
return Promise.reject(err)
|
|
26
|
-
},
|
|
27
|
-
)
|
|
28
|
-
return devServerAxios
|
|
29
|
-
}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import crypto from "crypto"
|
|
2
|
-
import $ from "dax-sh"
|
|
3
|
-
import fs from "fs"
|
|
4
|
-
import kleur from "kleur"
|
|
5
|
-
import posthog from "cli/lib/posthog"
|
|
6
|
-
import open from "open"
|
|
7
|
-
import * as Path from "path/posix"
|
|
8
|
-
import prompts from "prompts"
|
|
9
|
-
import { z } from "zod"
|
|
10
|
-
import { AppContext } from "../../util/app-context"
|
|
11
|
-
import { initCmd } from "../init"
|
|
12
|
-
import { createOrModifyNpmrc } from "../init/create-or-modify-npmrc"
|
|
13
|
-
import { checkIfInitialized } from "./check-if-initialized"
|
|
14
|
-
import { findAvailablePort } from "./find-available-port"
|
|
15
|
-
import { getDevServerAxios } from "./get-dev-server-axios"
|
|
16
|
-
import { startDevServer } from "./start-dev-server"
|
|
17
|
-
import { startEditEventWatcher } from "./start-edit-event-watcher"
|
|
18
|
-
import { startExportRequestWatcher } from "./start-export-request-watcher"
|
|
19
|
-
import { startFsWatcher } from "./start-fs-watcher"
|
|
20
|
-
import { uploadExamplesFromDirectory } from "./upload-examples-from-directory"
|
|
21
|
-
|
|
22
|
-
export const devCmd = async (ctx: AppContext, args: any) => {
|
|
23
|
-
const params = z
|
|
24
|
-
.object({
|
|
25
|
-
port: z.coerce.number().optional().default(3020),
|
|
26
|
-
core: z.boolean().optional(),
|
|
27
|
-
})
|
|
28
|
-
.parse(args)
|
|
29
|
-
|
|
30
|
-
let { port } = params
|
|
31
|
-
const { cwd } = ctx
|
|
32
|
-
|
|
33
|
-
// Find an available port
|
|
34
|
-
port = await findAvailablePort(port)
|
|
35
|
-
|
|
36
|
-
const projectHash = crypto.createHash("md5").update(cwd).digest("hex")
|
|
37
|
-
|
|
38
|
-
posthog.capture({
|
|
39
|
-
distinctId: projectHash,
|
|
40
|
-
event: "tsci_dev_started",
|
|
41
|
-
properties: {
|
|
42
|
-
port: port,
|
|
43
|
-
},
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
// In the future we should automatically run "tsci init" if the directory
|
|
47
|
-
// isn't properly initialized, for now we're just going to do a spot check
|
|
48
|
-
const isInitialized = await checkIfInitialized(ctx)
|
|
49
|
-
|
|
50
|
-
if (!isInitialized) {
|
|
51
|
-
const { confirmInitialize } = await prompts({
|
|
52
|
-
type: "confirm",
|
|
53
|
-
name: "confirmInitialize",
|
|
54
|
-
message: "Would you like to initialize this project now?",
|
|
55
|
-
initial: true,
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
if (confirmInitialize) {
|
|
59
|
-
return initCmd(ctx, {})
|
|
60
|
-
} else {
|
|
61
|
-
process.exit(1)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
await createOrModifyNpmrc({ quiet: false }, ctx)
|
|
66
|
-
|
|
67
|
-
// Load package.json, install tscircuit if it's not installed. If any other
|
|
68
|
-
// tscircuit dependency like @tscircuit/builder is installed, then don't
|
|
69
|
-
// install anything. If there is nothing in the current directory, ask to
|
|
70
|
-
// instead run "tsci init"
|
|
71
|
-
// TODO
|
|
72
|
-
|
|
73
|
-
// Add .tscircuit to .gitignore if it's not already there
|
|
74
|
-
// TODO
|
|
75
|
-
|
|
76
|
-
// Delete old .tscircuit/dev-server.sqlite
|
|
77
|
-
// unlink(Path.join(cwd, ".tscircuit/dev-server.sqlite")).catch(() => { })
|
|
78
|
-
|
|
79
|
-
console.log(
|
|
80
|
-
kleur.green(
|
|
81
|
-
`\n--------------------------------------------\n\nStarting dev server http://127.0.0.1:${port}\n\n--------------------------------------------\n\n`,
|
|
82
|
-
),
|
|
83
|
-
)
|
|
84
|
-
const serverUrl = `http://127.0.0.1:${port}`
|
|
85
|
-
const devServerAxios = getDevServerAxios({ serverUrl })
|
|
86
|
-
|
|
87
|
-
const server = await startDevServer({ port, devServerAxios })
|
|
88
|
-
|
|
89
|
-
// Reset the database, allows migration to re-run
|
|
90
|
-
await devServerAxios.post("/api/dev_server/reset").catch((e) => {
|
|
91
|
-
console.log("Failed to reset database, continuing anyway...")
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
// Add package name to the package_info table
|
|
95
|
-
const packageJsonPath = Path.resolve(cwd, "package.json")
|
|
96
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"))
|
|
97
|
-
const packageName = packageJson.name
|
|
98
|
-
|
|
99
|
-
console.log(`Adding package info...`)
|
|
100
|
-
await devServerAxios.post(
|
|
101
|
-
"/api/package_info/create",
|
|
102
|
-
{
|
|
103
|
-
package_name: packageName,
|
|
104
|
-
},
|
|
105
|
-
ctx,
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
// Soupify all examples
|
|
109
|
-
console.log(`Loading examples...`)
|
|
110
|
-
await uploadExamplesFromDirectory({ devServerAxios, cwd }, ctx)
|
|
111
|
-
|
|
112
|
-
// Start watchers
|
|
113
|
-
const fs_watcher = await startFsWatcher({ cwd, devServerAxios }, ctx)
|
|
114
|
-
const er_watcher = await startExportRequestWatcher({ devServerAxios }, ctx)
|
|
115
|
-
const ee_watcher = await startEditEventWatcher({ devServerAxios }, ctx)
|
|
116
|
-
|
|
117
|
-
while (true) {
|
|
118
|
-
const { action } = await prompts({
|
|
119
|
-
type: "select",
|
|
120
|
-
name: "action", // Add this line
|
|
121
|
-
message: "Action:",
|
|
122
|
-
choices: [
|
|
123
|
-
{
|
|
124
|
-
title: "Open in Browser",
|
|
125
|
-
value: "open-in-browser",
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
title: "Open Directory in VS Code",
|
|
129
|
-
value: "open-in-vs-code",
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
title: "Stop Server",
|
|
133
|
-
value: "stop",
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
})
|
|
137
|
-
if (action === "open-in-browser") {
|
|
138
|
-
open(serverUrl)
|
|
139
|
-
posthog.capture({
|
|
140
|
-
distinctId: projectHash,
|
|
141
|
-
event: "tsci_dev_open_browser",
|
|
142
|
-
})
|
|
143
|
-
} else if (action === "open-in-vs-code") {
|
|
144
|
-
await $`code ${cwd}`
|
|
145
|
-
posthog.capture({
|
|
146
|
-
distinctId: projectHash,
|
|
147
|
-
event: "tsci_dev_open_vscode",
|
|
148
|
-
})
|
|
149
|
-
} else if (!action || action === "stop") {
|
|
150
|
-
if (server.stop) server.stop()
|
|
151
|
-
if (server.close) server.close()
|
|
152
|
-
fs_watcher.stop()
|
|
153
|
-
er_watcher.stop()
|
|
154
|
-
ee_watcher.stop()
|
|
155
|
-
|
|
156
|
-
posthog.capture({
|
|
157
|
-
distinctId: projectHash,
|
|
158
|
-
event: "tsci_dev_stopped",
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
if (posthog.shutdown) {
|
|
162
|
-
await posthog.shutdown()
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
break
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const inferExportNameFromSource = (sourceContent: string): string => {
|
|
2
|
-
if (sourceContent.includes("export default")) {
|
|
3
|
-
return "default"
|
|
4
|
-
}
|
|
5
|
-
const matches = Array.from(
|
|
6
|
-
sourceContent.matchAll(/export\s+(const|function)\s+([A-Z]\w+)\s*=?/g),
|
|
7
|
-
).map((m) => m[2])
|
|
8
|
-
if (matches.length === 0) {
|
|
9
|
-
throw new Error(`No export detected in "${sourceContent}"`)
|
|
10
|
-
}
|
|
11
|
-
if (matches.length > 1) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
`Multiple exports detected in "${sourceContent}", only single exports currently working`,
|
|
14
|
-
)
|
|
15
|
-
}
|
|
16
|
-
return matches[0]
|
|
17
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios"
|
|
2
|
-
|
|
3
|
-
export const markAllExamplesLoading = async ({
|
|
4
|
-
devServerAxios,
|
|
5
|
-
}: {
|
|
6
|
-
devServerAxios: AxiosInstance
|
|
7
|
-
}) => {
|
|
8
|
-
const examples = await devServerAxios
|
|
9
|
-
.post("/api/dev_package_examples/list")
|
|
10
|
-
.then((r) => r.data.dev_package_examples)
|
|
11
|
-
|
|
12
|
-
for (const example of examples) {
|
|
13
|
-
await devServerAxios.post("/api/dev_package_examples/update", {
|
|
14
|
-
dev_package_example_id: example.dev_package_example_id,
|
|
15
|
-
is_loading: true,
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,62 +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 { inferExportNameFromSource } from "./infer-export-name-from-source"
|
|
7
|
-
import { AppContext } from "cli/lib/util/app-context"
|
|
8
|
-
|
|
9
|
-
export const soupifyAndUploadExampleFile = async (
|
|
10
|
-
{
|
|
11
|
-
examplesDir,
|
|
12
|
-
exampleFileName,
|
|
13
|
-
devServerAxios,
|
|
14
|
-
}: {
|
|
15
|
-
examplesDir: string
|
|
16
|
-
exampleFileName: string
|
|
17
|
-
devServerAxios: AxiosInstance
|
|
18
|
-
},
|
|
19
|
-
ctx: Pick<AppContext, "runtime" | "params">,
|
|
20
|
-
) => {
|
|
21
|
-
try {
|
|
22
|
-
const startTime = Date.now()
|
|
23
|
-
const examplePath = joinPath(examplesDir, exampleFileName)
|
|
24
|
-
const exampleContent = readFileSync(examplePath).toString()
|
|
25
|
-
|
|
26
|
-
const exportName = inferExportNameFromSource(exampleContent)
|
|
27
|
-
|
|
28
|
-
console.log(kleur.gray(`[soupifying] ${exampleFileName}...`))
|
|
29
|
-
const { soup, error } = await soupify(
|
|
30
|
-
{
|
|
31
|
-
filePath: examplePath,
|
|
32
|
-
exportName,
|
|
33
|
-
},
|
|
34
|
-
ctx,
|
|
35
|
-
)
|
|
36
|
-
.then((soup) => ({ soup, error: null }))
|
|
37
|
-
.catch((e) => ({ error: e, soup: undefined }))
|
|
38
|
-
|
|
39
|
-
if (error) {
|
|
40
|
-
console.log(kleur.red(`[ error ] couldn't soupify ${exampleFileName}`))
|
|
41
|
-
console.log(error.toString())
|
|
42
|
-
}
|
|
43
|
-
console.log(kleur.gray(`[uploading ] ${exampleFileName}...`))
|
|
44
|
-
await devServerAxios.post("/api/dev_package_examples/create", {
|
|
45
|
-
tscircuit_soup: soup,
|
|
46
|
-
error: error?.toString() || null,
|
|
47
|
-
file_path: examplePath,
|
|
48
|
-
export_name: exportName,
|
|
49
|
-
is_loading: false,
|
|
50
|
-
})
|
|
51
|
-
const timeTaken = Date.now() - startTime
|
|
52
|
-
console.log(
|
|
53
|
-
kleur.gray(
|
|
54
|
-
`[ done ] [ ${Math.round(timeTaken)
|
|
55
|
-
.toString()
|
|
56
|
-
.padStart(5, " ")}ms ] ${exampleFileName}!`,
|
|
57
|
-
),
|
|
58
|
-
)
|
|
59
|
-
} catch (e: any) {
|
|
60
|
-
console.log(kleur.red(`[ error ] ${e.toString()}`))
|
|
61
|
-
}
|
|
62
|
-
}
|