@tscircuit/cli 0.0.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/.prettierrc +1 -0
- package/README.md +50 -0
- package/build-cli.ts +14 -0
- package/bun.lockb +0 -0
- package/cli.ts +12 -0
- package/dev-server-api/README.md +3 -0
- package/dev-server-api/bun.lockb +0 -0
- package/dev-server-api/edgespec.config.ts +4 -0
- package/dev-server-api/index.ts +1 -0
- package/dev-server-api/package-lock.json +1201 -0
- package/dev-server-api/package.json +24 -0
- package/dev-server-api/routes/api/dev_package_examples/create.ts +43 -0
- package/dev-server-api/routes/api/dev_package_examples/get.ts +37 -0
- package/dev-server-api/routes/api/dev_package_examples/list.ts +29 -0
- package/dev-server-api/routes/api/dev_package_examples/update.ts +31 -0
- package/dev-server-api/routes/api/health.ts +11 -0
- package/dev-server-api/src/db/create-schema.ts +14 -0
- package/dev-server-api/src/db/get-db.ts +78 -0
- package/dev-server-api/src/middlewares/with-db.ts +14 -0
- package/dev-server-api/src/middlewares/with-error-response.ts +24 -0
- package/dev-server-api/src/with-edge-spec.ts +8 -0
- package/dev-server-api/tsconfig.json +28 -0
- package/dev-server-frontend/.eslintrc.cjs +20 -0
- package/dev-server-frontend/README.md +3 -0
- package/dev-server-frontend/bun.lockb +0 -0
- package/dev-server-frontend/components.json +17 -0
- package/dev-server-frontend/index.html +13 -0
- package/dev-server-frontend/package.json +62 -0
- package/dev-server-frontend/postcss.config.js +6 -0
- package/dev-server-frontend/src/App.tsx +22 -0
- package/dev-server-frontend/src/ExampleContentView.tsx +60 -0
- package/dev-server-frontend/src/Header.tsx +53 -0
- package/dev-server-frontend/src/HeaderMenu.tsx +188 -0
- package/dev-server-frontend/src/components/command-k.tsx +62 -0
- package/dev-server-frontend/src/components/global-context-providers.tsx +11 -0
- package/dev-server-frontend/src/components/select-example-search.tsx +137 -0
- package/dev-server-frontend/src/components/ui/alert-dialog.tsx +139 -0
- package/dev-server-frontend/src/components/ui/alert.tsx +59 -0
- package/dev-server-frontend/src/components/ui/breadcrumb.tsx +115 -0
- package/dev-server-frontend/src/components/ui/button.tsx +57 -0
- package/dev-server-frontend/src/components/ui/card.tsx +76 -0
- package/dev-server-frontend/src/components/ui/command.tsx +153 -0
- package/dev-server-frontend/src/components/ui/context-menu.tsx +202 -0
- package/dev-server-frontend/src/components/ui/dialog.tsx +120 -0
- package/dev-server-frontend/src/components/ui/menubar.tsx +238 -0
- package/dev-server-frontend/src/components/ui/navigation-menu.tsx +128 -0
- package/dev-server-frontend/src/components/ui/popover.tsx +31 -0
- package/dev-server-frontend/src/components/ui/select.tsx +162 -0
- package/dev-server-frontend/src/components/ui/tabs.tsx +53 -0
- package/dev-server-frontend/src/components/ui/toggle-group.tsx +59 -0
- package/dev-server-frontend/src/components/ui/toggle.tsx +43 -0
- package/dev-server-frontend/src/components/ui/tooltip.tsx +28 -0
- package/dev-server-frontend/src/hooks/toast-if-api-not-connected.ts +23 -0
- package/dev-server-frontend/src/hooks/use-global-store.ts +42 -0
- package/dev-server-frontend/src/index.css +76 -0
- package/dev-server-frontend/src/lib/utils.ts +6 -0
- package/dev-server-frontend/src/main.tsx +13 -0
- package/dev-server-frontend/src/vite-env.d.ts +1 -0
- package/dev-server-frontend/tailwind.config.js +77 -0
- package/dev-server-frontend/tsconfig.json +26 -0
- package/dev-server-frontend/tsconfig.node.json +13 -0
- package/dev-server-frontend/vite.config.ts +23 -0
- package/dist/cli.js +1326 -0
- package/lib/cmd-fns/auth-login.ts +59 -0
- package/lib/cmd-fns/auth-logout.ts +3 -0
- package/lib/cmd-fns/auth-sessions-create.ts +3 -0
- package/lib/cmd-fns/auth-sessions-get.ts +3 -0
- package/lib/cmd-fns/auth-sessions-list.ts +5 -0
- package/lib/cmd-fns/config-print-config.ts +6 -0
- package/lib/cmd-fns/config-reveal-location.ts +5 -0
- package/lib/cmd-fns/config-set-log-requests.ts +7 -0
- package/lib/cmd-fns/config-set-registry.ts +7 -0
- package/lib/cmd-fns/config-set-session.ts +7 -0
- package/lib/cmd-fns/dev.ts +217 -0
- package/lib/cmd-fns/index.ts +27 -0
- package/lib/cmd-fns/package-examples-create.ts +33 -0
- package/lib/cmd-fns/package-examples-get.ts +20 -0
- package/lib/cmd-fns/package-examples-list.ts +18 -0
- package/lib/cmd-fns/package-files-create.ts +31 -0
- package/lib/cmd-fns/package-files-download.ts +29 -0
- package/lib/cmd-fns/package-files-get.ts +3 -0
- package/lib/cmd-fns/package-files-list.ts +28 -0
- package/lib/cmd-fns/package-files-upload-directory.ts +6 -0
- package/lib/cmd-fns/package-releases-create.ts +35 -0
- package/lib/cmd-fns/package-releases-get.ts +3 -0
- package/lib/cmd-fns/package-releases-list.ts +32 -0
- package/lib/cmd-fns/packages-create.ts +16 -0
- package/lib/cmd-fns/packages-get.ts +16 -0
- package/lib/cmd-fns/packages-list.ts +16 -0
- package/lib/cmd-fns/publish.ts +3 -0
- package/lib/cmd-fns/soupify.ts +27 -0
- package/lib/get-program.ts +191 -0
- package/lib/param-handlers/index.ts +16 -0
- package/lib/param-handlers/interact-for-local-directory.ts +58 -0
- package/lib/param-handlers/interact-for-local-file.ts +59 -0
- package/lib/param-handlers/interact-for-package-example-id.ts +25 -0
- package/lib/param-handlers/interact-for-package-name-with-version.ts +63 -0
- package/lib/param-handlers/interact-for-package-name.ts +45 -0
- package/lib/param-handlers/interact-for-package-release-id.ts +16 -0
- package/lib/param-handlers/param-handler-type.ts +7 -0
- package/lib/soupify.ts +71 -0
- package/lib/util/app-context.ts +14 -0
- package/lib/util/create-context-and-run-program.ts +116 -0
- package/package.json +62 -0
- package/tests/assets/example-project/examples/basic-capacitor.tsx +1 -0
- package/tests/assets/example-project/examples/basic-resistor.tsx +3 -0
- package/tests/assets/example-project/package.json +8 -0
- package/tests/assets/example-project/src/MyCircuit.tsx +3 -0
- package/tests/soupify.test.ts +9 -0
- package/tsconfig.json +109 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { AppContext } from "../util/app-context"
|
|
2
|
+
import delay from "delay"
|
|
3
|
+
|
|
4
|
+
export const authLogin = async (ctx: AppContext, args: any) => {
|
|
5
|
+
const {
|
|
6
|
+
data: { login_page },
|
|
7
|
+
} = await ctx.axios.post("/sessions/login_page/create", {})
|
|
8
|
+
|
|
9
|
+
console.log("Please visit the following URL to log in:")
|
|
10
|
+
console.log(login_page.url)
|
|
11
|
+
|
|
12
|
+
// Wait until we receive confirmation
|
|
13
|
+
while (true) {
|
|
14
|
+
const {
|
|
15
|
+
data: { login_page: new_login_page },
|
|
16
|
+
} = await ctx.axios.post(
|
|
17
|
+
"/sessions/login_page/get",
|
|
18
|
+
{
|
|
19
|
+
login_page_id: login_page.login_page_id,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
headers: {
|
|
23
|
+
Authorization: `Bearer ${login_page.login_page_auth_token}`,
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
if (new_login_page.was_login_successful) {
|
|
29
|
+
console.log("Logged in! Generating token...")
|
|
30
|
+
break
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (new_login_page.is_expired) {
|
|
34
|
+
throw new Error("Login page expired")
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await delay(1000)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
data: { session },
|
|
42
|
+
} = await ctx.axios.post(
|
|
43
|
+
"/sessions/login_page/exchange_for_cli_session",
|
|
44
|
+
{
|
|
45
|
+
login_page_id: login_page.login_page_id,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
headers: {
|
|
49
|
+
Authorization: `Bearer ${login_page.login_page_auth_token}`,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
ctx.profile_config.set("session_token", session.token)
|
|
55
|
+
|
|
56
|
+
// TODO test query
|
|
57
|
+
|
|
58
|
+
console.log("Ready to use!")
|
|
59
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
ctx.profile_config.set("registry_url", params.server)
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { AppContext } from "../util/app-context"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
import kleur from "kleur"
|
|
4
|
+
import { join as joinPath } from "path"
|
|
5
|
+
import prompts from "prompts"
|
|
6
|
+
import open from "open"
|
|
7
|
+
import apiServer from "../../dev-server-api/dist/bundle"
|
|
8
|
+
import frontendVfs from "../../dev-server-frontend/dist/bundle"
|
|
9
|
+
import defaultAxios from "axios"
|
|
10
|
+
import { readdirSync, readFileSync } from "fs"
|
|
11
|
+
import { soupify } from "lib/soupify"
|
|
12
|
+
import EdgeRuntimePrimitives from "@edge-runtime/primitives"
|
|
13
|
+
import mime from "mime-types"
|
|
14
|
+
|
|
15
|
+
export const devCmd = async (ctx: AppContext, args: any) => {
|
|
16
|
+
const params = z
|
|
17
|
+
.object({
|
|
18
|
+
cwd: z.string().optional().default(process.cwd()),
|
|
19
|
+
port: z.coerce.number().optional().default(3020),
|
|
20
|
+
})
|
|
21
|
+
.parse(args)
|
|
22
|
+
|
|
23
|
+
const { cwd, port } = params
|
|
24
|
+
|
|
25
|
+
// Load package.json, install tscircuit if it's not installed. If any other
|
|
26
|
+
// tscircuit dependency like @tscircuit/builder is installed, then don't
|
|
27
|
+
// install anything
|
|
28
|
+
// TODO
|
|
29
|
+
|
|
30
|
+
// Check that examples directory exists, if not create it and put inside
|
|
31
|
+
// a sample file ExampleCircuit.ts
|
|
32
|
+
// TODO
|
|
33
|
+
|
|
34
|
+
// Create .tscircuit directory if it doesn't exist
|
|
35
|
+
// TODO
|
|
36
|
+
|
|
37
|
+
// Add .tscircuit to .gitignore if it's not already there
|
|
38
|
+
// TODO
|
|
39
|
+
|
|
40
|
+
// Delete and recreate .tscircuit/dev-server.db
|
|
41
|
+
|
|
42
|
+
// INSIDE BACKGROUND SERVICE
|
|
43
|
+
// Soupify contents of examples directory, upload to sqlite db
|
|
44
|
+
// TODO
|
|
45
|
+
// Watch and re-soupify on file changes
|
|
46
|
+
// TODO
|
|
47
|
+
|
|
48
|
+
console.log(
|
|
49
|
+
kleur.green(
|
|
50
|
+
`\n--------------------------------------------\n\nStarting dev server http://localhost:${port}\n\n--------------------------------------------\n\n`
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
const serverUrl = `http://localhost:${port}`
|
|
54
|
+
const axios = defaultAxios.create({
|
|
55
|
+
baseURL: serverUrl,
|
|
56
|
+
})
|
|
57
|
+
axios.interceptors.response.use(
|
|
58
|
+
(res) => res,
|
|
59
|
+
(err) => {
|
|
60
|
+
console.log(
|
|
61
|
+
kleur.red(
|
|
62
|
+
`[ERR] ${err.response?.status} ${err.config.method?.toUpperCase()} ${
|
|
63
|
+
err.config.url
|
|
64
|
+
}\n\n${JSON.stringify(err.response?.data, null, " ")}`
|
|
65
|
+
.replace(/\\n/g, "\n")
|
|
66
|
+
.replace(/\\"/g, '"')
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
console.log(kleur.yellow("[Request Body]:"), err.config.data)
|
|
70
|
+
return Promise.reject(err)
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
const requestHandler = async (bunReq: Request) => {
|
|
75
|
+
const url = new URL(bunReq.url)
|
|
76
|
+
const requestType = url.pathname.startsWith("/api")
|
|
77
|
+
? "api"
|
|
78
|
+
: url.pathname.startsWith("/preview")
|
|
79
|
+
? "preview"
|
|
80
|
+
: "other"
|
|
81
|
+
|
|
82
|
+
if (requestType === "api") {
|
|
83
|
+
// We have to shim Bun's Request until they fix the issue where
|
|
84
|
+
// .clone() doesn't clone the body
|
|
85
|
+
// https://github.com/oven-sh/bun/pull/8668
|
|
86
|
+
const req = new EdgeRuntimePrimitives.Request(bunReq.url, {
|
|
87
|
+
headers: bunReq.headers,
|
|
88
|
+
method: bunReq.method,
|
|
89
|
+
body: bunReq.body,
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const response = await apiServer.makeRequest(req, {})
|
|
93
|
+
return response
|
|
94
|
+
} else if (requestType === "preview") {
|
|
95
|
+
let frontendPath = url.pathname.replace("/preview", "")
|
|
96
|
+
if (frontendPath === "/" || frontendPath === "") {
|
|
97
|
+
frontendPath = "index.html"
|
|
98
|
+
}
|
|
99
|
+
frontendPath = frontendPath.replace(/^\//, "")
|
|
100
|
+
|
|
101
|
+
const fileContent: Buffer = (frontendVfs as any)[frontendPath]
|
|
102
|
+
if (!fileContent) {
|
|
103
|
+
return new Response("Not Found", { status: 404 })
|
|
104
|
+
}
|
|
105
|
+
return new Response(
|
|
106
|
+
// Buffer.from(fileContent.toString(), "base64").toString("utf-8"),
|
|
107
|
+
fileContent.toString("utf-8"),
|
|
108
|
+
{
|
|
109
|
+
headers: {
|
|
110
|
+
"Content-Type": mime.lookup(frontendPath) || "text/plain",
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
} else {
|
|
115
|
+
return new Response(null, {
|
|
116
|
+
status: 302,
|
|
117
|
+
headers: {
|
|
118
|
+
Location: "/preview",
|
|
119
|
+
},
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let server: any
|
|
125
|
+
if (typeof Bun !== "undefined") {
|
|
126
|
+
server = Bun.serve({
|
|
127
|
+
fetch: requestHandler,
|
|
128
|
+
development: false,
|
|
129
|
+
port,
|
|
130
|
+
})
|
|
131
|
+
} else {
|
|
132
|
+
// Hono messes up the globals, only import it if we don't have Bun
|
|
133
|
+
const { Hono } = await import("hono")
|
|
134
|
+
const { serve } = await import("@hono/node-server")
|
|
135
|
+
const honoApp = new Hono()
|
|
136
|
+
honoApp.all("/*", (c) => requestHandler(c.req.raw))
|
|
137
|
+
server = serve({
|
|
138
|
+
fetch: honoApp.fetch,
|
|
139
|
+
port,
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
console.log("Running health check against dev server...")
|
|
144
|
+
await axios.get("/api/health")
|
|
145
|
+
|
|
146
|
+
// Soupify all examples
|
|
147
|
+
console.log(`Loading examples...`)
|
|
148
|
+
const examplesDir = joinPath(cwd, "examples")
|
|
149
|
+
const exampleFileNames = readdirSync(examplesDir)
|
|
150
|
+
for (const exampleFileName of exampleFileNames) {
|
|
151
|
+
try {
|
|
152
|
+
const examplePath = joinPath(examplesDir, exampleFileName)
|
|
153
|
+
const exampleContent = readFileSync(examplePath).toString()
|
|
154
|
+
|
|
155
|
+
let exportName = "default"
|
|
156
|
+
|
|
157
|
+
if (!exampleContent.includes("export default")) {
|
|
158
|
+
// try to infer an export if possible
|
|
159
|
+
const matches = Array.from(
|
|
160
|
+
exampleContent.matchAll(
|
|
161
|
+
/export\s+(const|function)\s+([A-Z]\w+)\s*=?/g
|
|
162
|
+
)
|
|
163
|
+
).map((m) => m[2])
|
|
164
|
+
if (matches.length === 0) {
|
|
165
|
+
throw new Error(`No export detected in "${exampleFileName}"`)
|
|
166
|
+
}
|
|
167
|
+
if (matches.length > 1) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`Multiple exports detected in "${exampleFileName}", only single exports currently working`
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
exportName = matches[0]
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
console.log("Soupifying...")
|
|
176
|
+
const soup = await soupify({
|
|
177
|
+
filePath: examplePath,
|
|
178
|
+
exportName,
|
|
179
|
+
})
|
|
180
|
+
console.log(`Soupified ${exampleFileName}!`)
|
|
181
|
+
console.log(`Uploading ${exampleFileName}...`)
|
|
182
|
+
await axios.post("/api/dev_package_examples/create", {
|
|
183
|
+
tscircuit_soup: soup,
|
|
184
|
+
file_path: examplePath,
|
|
185
|
+
export_name: exportName,
|
|
186
|
+
})
|
|
187
|
+
console.log(`Uploaded ${exampleFileName}!`)
|
|
188
|
+
} catch (e: any) {
|
|
189
|
+
console.log(kleur.red(e.toString()))
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
while (true) {
|
|
194
|
+
const { action } = await prompts({
|
|
195
|
+
type: "select",
|
|
196
|
+
name: "action", // Add this line
|
|
197
|
+
message: "Action:",
|
|
198
|
+
choices: [
|
|
199
|
+
{
|
|
200
|
+
title: "Open in Browser",
|
|
201
|
+
value: "open-in-browser",
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
title: "Stop Server",
|
|
205
|
+
value: "stop",
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
})
|
|
209
|
+
if (action === "open-in-browser") {
|
|
210
|
+
open(serverUrl)
|
|
211
|
+
} else if (!action || action === "stop") {
|
|
212
|
+
if (server.stop) server.stop()
|
|
213
|
+
if (server.close) server.close()
|
|
214
|
+
break
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { configRevealLocation } from "./config-reveal-location"
|
|
2
|
+
export { configSetRegistry } from "./config-set-registry"
|
|
3
|
+
export { configSetSession } from "./config-set-session"
|
|
4
|
+
export { configSetLogRequests } from "./config-set-log-requests"
|
|
5
|
+
export { configPrintConfig } from "./config-print-config"
|
|
6
|
+
export { authLogin } from "./auth-login"
|
|
7
|
+
export { authLogout } from "./auth-logout"
|
|
8
|
+
export { authSessionsCreate } from "./auth-sessions-create"
|
|
9
|
+
export { authSessionsList } from "./auth-sessions-list"
|
|
10
|
+
export { authSessionsGet } from "./auth-sessions-get"
|
|
11
|
+
export { packagesList } from "./packages-list"
|
|
12
|
+
export { packagesGet } from "./packages-get"
|
|
13
|
+
export { packagesCreate } from "./packages-create"
|
|
14
|
+
export { packageFilesUploadDirectory } from "./package-files-upload-directory"
|
|
15
|
+
export { packageReleasesList } from "./package-releases-list"
|
|
16
|
+
export { packageReleasesGet } from "./package-releases-get"
|
|
17
|
+
export { packageReleasesCreate } from "./package-releases-create"
|
|
18
|
+
export { packageFilesList } from "./package-files-list"
|
|
19
|
+
export { packageFilesGet } from "./package-files-get"
|
|
20
|
+
export { packageFilesDownload } from "./package-files-download"
|
|
21
|
+
export { packageFilesCreate } from "./package-files-create"
|
|
22
|
+
export { packageExamplesList } from "./package-examples-list"
|
|
23
|
+
export { packageExamplesGet } from "./package-examples-get"
|
|
24
|
+
export { packageExamplesCreate } from "./package-examples-create"
|
|
25
|
+
export { publish } from "./publish"
|
|
26
|
+
export { soupifyCmd as soupify } from "./soupify"
|
|
27
|
+
export { devCmd as dev } from "./dev"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { soupify } from "lib/soupify"
|
|
2
|
+
import { AppContext } from "../util/app-context"
|
|
3
|
+
import { z } from "zod"
|
|
4
|
+
import fs from "fs"
|
|
5
|
+
|
|
6
|
+
export const packageExamplesCreate = async (ctx: AppContext, args: any) => {
|
|
7
|
+
const params = z
|
|
8
|
+
.object({
|
|
9
|
+
packageNameWithVersion: z.string(),
|
|
10
|
+
file: z.string(),
|
|
11
|
+
export: z.string().optional().default("default"),
|
|
12
|
+
})
|
|
13
|
+
.parse(args)
|
|
14
|
+
|
|
15
|
+
const tscircuit_soup = await soupify({
|
|
16
|
+
filePath: params.file,
|
|
17
|
+
exportName: params.export,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const fileContent = await fs.promises.readFile(params.file, "utf8")
|
|
21
|
+
|
|
22
|
+
const package_example = await ctx.axios
|
|
23
|
+
.post("/package_examples/create", {
|
|
24
|
+
package_name_with_version: params.packageNameWithVersion,
|
|
25
|
+
file_path: params.file,
|
|
26
|
+
export_name: params.export,
|
|
27
|
+
source_content: fileContent,
|
|
28
|
+
tscircuit_soup,
|
|
29
|
+
})
|
|
30
|
+
.then((r) => r.data.package_example)
|
|
31
|
+
|
|
32
|
+
console.log(package_example)
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AppContext } from "../util/app-context"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
|
|
4
|
+
export const packageExamplesGet = async (ctx: AppContext, args: any) => {
|
|
5
|
+
const params = z
|
|
6
|
+
.object({
|
|
7
|
+
packageExampleId: z.string().uuid(),
|
|
8
|
+
})
|
|
9
|
+
.parse(args)
|
|
10
|
+
|
|
11
|
+
const { packageExampleId: package_example_id } = params
|
|
12
|
+
|
|
13
|
+
const package_example = await ctx.axios
|
|
14
|
+
.post("/package_examples/get", {
|
|
15
|
+
package_example_id,
|
|
16
|
+
})
|
|
17
|
+
.then((r) => r.data.package_example)
|
|
18
|
+
|
|
19
|
+
console.log(package_example)
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AppContext } from "../util/app-context"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
|
|
4
|
+
export const packageExamplesList = async (ctx: AppContext, args: any) => {
|
|
5
|
+
const params = z
|
|
6
|
+
.object({
|
|
7
|
+
packageNameWithVersion: z.string(),
|
|
8
|
+
})
|
|
9
|
+
.parse(args)
|
|
10
|
+
|
|
11
|
+
const package_examples = await ctx.axios
|
|
12
|
+
.post("/package_examples/list", {
|
|
13
|
+
package_name_with_version: params.packageNameWithVersion,
|
|
14
|
+
})
|
|
15
|
+
.then((r) => r.data.package_examples)
|
|
16
|
+
|
|
17
|
+
console.log(package_examples)
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AppContext } from "../util/app-context"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
import * as fs from "fs/promises"
|
|
4
|
+
import kleur from "kleur"
|
|
5
|
+
|
|
6
|
+
export const packageFilesCreate = async (ctx: AppContext, args: any) => {
|
|
7
|
+
const params = z
|
|
8
|
+
.object({
|
|
9
|
+
file: z.string(),
|
|
10
|
+
packageReleaseId: z.string().optional(),
|
|
11
|
+
packageNameWithVersion: z.string().optional(),
|
|
12
|
+
})
|
|
13
|
+
.parse(args)
|
|
14
|
+
|
|
15
|
+
const { file, packageNameWithVersion, packageReleaseId } = params
|
|
16
|
+
|
|
17
|
+
const fileContent = await fs.readFile(file)
|
|
18
|
+
|
|
19
|
+
const package_file = await ctx.axios
|
|
20
|
+
.post("/package_files/create", {
|
|
21
|
+
file_path: file,
|
|
22
|
+
content_text: fileContent.toString(),
|
|
23
|
+
package_name_with_version: packageNameWithVersion,
|
|
24
|
+
package_release_id: packageReleaseId,
|
|
25
|
+
})
|
|
26
|
+
.then((r) => r.data.package_file)
|
|
27
|
+
|
|
28
|
+
console.log(
|
|
29
|
+
`Package file created ${kleur.gray(package_file.package_file_id)}`
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|