@solidrt/cli 0.0.3 → 0.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "type": "module",
@@ -19,12 +19,12 @@
19
19
  "qrcode-generator": "^2.0.4"
20
20
  },
21
21
  "optionalDependencies": {
22
- "@solidrt/darwin-arm64": "0.0.3",
23
- "@solidrt/linux-x64-gnu": "0.0.3",
24
- "@solidrt/win32-x64-msvc": "0.0.3"
22
+ "@solidrt/darwin-arm64": "0.0.5",
23
+ "@solidrt/linux-x64-gnu": "0.0.5",
24
+ "@solidrt/win32-x64-msvc": "0.0.5"
25
25
  },
26
26
  "peerDependencies": {
27
- "@solidrt/core": "0.0.3",
27
+ "@solidrt/core": "0.0.5",
28
28
  "typescript": "^5"
29
29
  },
30
30
  "devDependencies": {
package/src/args.ts CHANGED
@@ -9,6 +9,10 @@ export let { values, positionals } = parseArgs({
9
9
  client: { type: "boolean", default: false },
10
10
  server: { type: "boolean", default: false },
11
11
  cache: { type: "boolean", default: false },
12
+ proxy: { type: "boolean", default: false },
13
+ fps: { type: "string" },
14
+ duration: { type: "string" },
15
+ size: { type: "string" },
12
16
  },
13
17
  allowPositionals: true,
14
18
  })
@@ -19,18 +23,30 @@ export let isTsx = source?.endsWith(".tsx")
19
23
  export let isPrebuilt = source?.endsWith(".srt.js") || source?.endsWith(".srt.bin")
20
24
 
21
25
  export function printUsage() {
22
- console.error(`Usage: srt <build|run> [options] [entry.tsx]
26
+ console.error(`Usage: srt <command> [options] [file]
23
27
 
24
28
  Commands:
25
- run [file.tsx] Start dev server + client (no file = embedded default)
26
- run --client Start dev client only (connects to WS server)
27
- run --server [file] Start dev server only, no client
29
+ run [file.tsx] Start dev server + local solidrt-go client
30
+ run --client Start solidrt-go client only
31
+ run --server [file.tsx] Start dev server only
32
+ build <file.tsx> Bundle
33
+ record <file.tsx> Capture frames for video generation
28
34
 
29
- Options:
35
+ run options:
36
+ --client Run client only
37
+ --server Run server only
38
+ --cache Enable HTTP cache
39
+ --proxy Tell connected clients to route file/dir/fetch through the dev server
40
+ --size <WxH> Window size (default: 1280x720)
41
+
42
+ build options:
30
43
  -m, --minify Minify the output
31
- -c, --compile Compile to bytecode (build only)
32
- -o, --output <name> Bundle filename (build only)
33
- --stdout Write bundle to stdout (build only)
34
- --cache Enable HTTP cache for fetch traffic; entries are
35
- kept in .srt-cache/. Delete that folder to reset.`)
44
+ -c, --compile Compile to bytecode
45
+ -o, --output <name> Output filename
46
+ --stdout Write bundle to stdout
47
+
48
+ record options:
49
+ --fps <N> Frames per second (default: 60)
50
+ --duration <N> Duration in seconds (default: 1)
51
+ --size <WxH> Frame size (default: 1280x720)`)
36
52
  }
package/src/client.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DEV_HOST, DEV_PORT, state, print, requireBinary } from "./util"
2
+ import { values } from "./args"
2
3
 
3
4
  function pipeAbovePrompt(stream: ReadableStream<Uint8Array>, out: NodeJS.WriteStream) {
4
5
  let reader = stream.getReader()
@@ -15,7 +16,9 @@ function pipeAbovePrompt(stream: ReadableStream<Uint8Array>, out: NodeJS.WriteSt
15
16
 
16
17
  export function spawnClient() {
17
18
  let runner = requireBinary("solidrt-go")
18
- state.child = Bun.spawn([runner], {
19
+ let args: string[] = []
20
+ if (values.size) args.push("--size", values.size)
21
+ state.child = Bun.spawn([runner, ...args], {
19
22
  //TODO implement dev server connection
20
23
  // state.child = Bun.spawn([runner, "--dev-server", `${DEV_HOST}:${DEV_PORT}`], {
21
24
  stdio: ["ignore", "pipe", "pipe"],
package/src/main.ts CHANGED
@@ -10,11 +10,12 @@
10
10
  // srt build examples/hello.tsx - bundle TSX to .srt.js
11
11
  // srt build -c examples/hello.tsx - bundle TSX to .srt.js + compile to .srt.bin
12
12
  // srt build examples/hello.srt.js - compile .srt.js to .srt.bin
13
+ // srt record examples/hello.tsx - bundle TSX and run with frame capture
13
14
 
14
15
  import pkg from "../package.json"
15
16
  import { values, command, source, isTsx, isPrebuilt, printUsage } from "./args"
16
17
  import { state, requireBinary, run, shutdown } from "./util"
17
- import { bundle, runBuildCommand } from "./build"
18
+ import { bundle, bundleTo, runBuildCommand } from "./build"
18
19
  import { startServer } from "./server"
19
20
  import { spawnClient } from "./client"
20
21
  import { startRepl } from "./repl"
@@ -24,7 +25,7 @@ import { resolve, dirname } from "path"
24
25
 
25
26
  // -- Validate args --
26
27
 
27
- if (!command || (command !== "build" && command !== "run")) {
28
+ if (!command || (command !== "build" && command !== "run" && command !== "record")) {
28
29
  printUsage()
29
30
  process.exit(1)
30
31
  }
@@ -34,17 +35,37 @@ if (command === "build" && (!source || (!isTsx && !isPrebuilt))) {
34
35
  process.exit(1)
35
36
  }
36
37
 
38
+ if (command === "record" && (!source || !isTsx)) {
39
+ console.error("Usage: srt record <entry.tsx>")
40
+ process.exit(1)
41
+ }
42
+
37
43
  // -- Build command --
38
44
 
39
45
  if (command === "build") {
40
46
  await runBuildCommand()
41
47
  }
42
48
 
49
+ // -- Record command --
50
+
51
+ if (command === "record") {
52
+ let jsOutfile = source!.replace(/\.tsx$/, "") + ".srt.js"
53
+ await bundleTo(jsOutfile)
54
+ let runner = requireBinary("solidrt-go")
55
+ let recordArgs = ["--record", resolve(jsOutfile)]
56
+ if (values.fps) recordArgs.push("--fps", values.fps)
57
+ if (values.duration) recordArgs.push("--duration", values.duration)
58
+ if (values.size) recordArgs.push("--size", values.size)
59
+ let exit = await run(runner, recordArgs)
60
+ process.exit(exit)
61
+ }
62
+
43
63
  // -- Run command --
44
64
 
45
65
  if (values.client) {
46
66
  let runner = requireBinary("solidrt-go")
47
- let args = []
67
+ let args: string[] = []
68
+ if (values.size) args.push("--size", values.size)
48
69
  //TODO add dev server connection
49
70
  // if (source) args.push("--dev-server", source)
50
71
  let exit = await run(runner, args)
@@ -57,7 +78,7 @@ state.sourceDir = source ? dirname(resolve(source)) : process.cwd()
57
78
 
58
79
  if (values.cache) {
59
80
  cache.initCache({ dir: process.cwd() })
60
- console.log("[cli] HTTP cache enabled (.srt-cache/)")
81
+ console.log("[cli] HTTP cache enabled")
61
82
  }
62
83
 
63
84
  startServer()
package/src/repl.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createInterface } from "node:readline"
2
2
  import { resolve, dirname } from "path"
3
3
  import { readdirSync } from "node:fs"
4
- import { state, print, printErr, broadcastStop, shutdown } from "./util"
4
+ import { state, print, printErr, broadcastStop, buildReload, shutdown } from "./util"
5
5
  import { bundle } from "./build"
6
6
  import { startWatcher, stopWatcher } from "./watcher"
7
7
 
@@ -37,7 +37,7 @@ async function cmdReload(args: string) {
37
37
  state.currentCode = await output.text()
38
38
  }
39
39
  }
40
- let msg = JSON.stringify({ type: "reload", code: state.currentCode })
40
+ let msg = buildReload({ code: state.currentCode })
41
41
  if (!args) {
42
42
  for (let ws of state.clients.keys()) ws.send(msg)
43
43
  print("[cli] Sent reload to all clients")
@@ -86,8 +86,8 @@ async function cmdLoad(file: string) {
86
86
  state.currentCode = await Bun.file(path).text()
87
87
  } else if (file.endsWith(".srt.bin")) {
88
88
  let bytes = await Bun.file(path).arrayBuffer()
89
- let msg = { type: "reload", bytecode: Buffer.from(bytes).toString("base64") }
90
- for (let ws of state.clients.keys()) ws.send(JSON.stringify(msg))
89
+ let msg = buildReload({ bytecode: Buffer.from(bytes).toString("base64") })
90
+ for (let ws of state.clients.keys()) ws.send(msg)
91
91
  print(`[cli] Loaded ${file} (bytecode, ${bytes.byteLength} bytes)`)
92
92
  return
93
93
  } else {
@@ -97,8 +97,9 @@ async function cmdLoad(file: string) {
97
97
  state.source = path
98
98
  state.sourceDir = dirname(path)
99
99
  startWatcher()
100
+ let reloadMsg = buildReload({ code: state.currentCode })
100
101
  for (let ws of state.clients.keys()) {
101
- ws.send(JSON.stringify({ type: "reload", code: state.currentCode }))
102
+ ws.send(reloadMsg)
102
103
  }
103
104
  print(`[cli] Loaded ${file}`)
104
105
  }
package/src/server.ts CHANGED
@@ -3,7 +3,7 @@ import { stat as fsStat, readdir } from "node:fs/promises"
3
3
  import { networkInterfaces } from "node:os"
4
4
  import { createSocket } from "node:dgram"
5
5
  import qrcode from "qrcode-generator"
6
- import { DEV_HOST, DEV_PORT, state, print } from "./util"
6
+ import { DEV_HOST, DEV_PORT, state, print, buildReload } from "./util"
7
7
  import * as cache from "./cache"
8
8
 
9
9
  function headersToObject(h: Headers): Record<string, string> {
@@ -142,7 +142,7 @@ export function startServer() {
142
142
  state.clients.set(ws, { platform: "unknown", version: "unknown" })
143
143
  print(`[cli] Client connected ${ws.remoteAddress}`)
144
144
  if (state.currentCode) {
145
- ws.send(JSON.stringify({ type: "reload", code: state.currentCode }))
145
+ ws.send(buildReload({ code: state.currentCode }))
146
146
  }
147
147
  },
148
148
  close(ws) {
package/src/util.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { resolveBinary } from "./native"
2
+ import { values } from "./args"
2
3
  import type { Interface as ReadlineInterface } from "node:readline"
3
4
  import type { Server as BunServer } from "bun"
4
5
 
@@ -41,6 +42,10 @@ export function printErr(...args: any[]) {
41
42
  state.rl?.prompt(true)
42
43
  }
43
44
 
45
+ export function buildReload(payload: { code?: string | null; bytecode?: string }) {
46
+ return JSON.stringify({ type: "reload", proxy: values.proxy, ...payload })
47
+ }
48
+
44
49
  export function broadcastStop() {
45
50
  for (let ws of state.clients.keys()) {
46
51
  ws.send(JSON.stringify({ type: "stop" }))
package/src/watcher.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { watch } from "node:fs"
2
2
  import { resolve, dirname } from "path"
3
- import { state, print, printErr } from "./util"
3
+ import { state, print, printErr, buildReload } from "./util"
4
4
  import { bundle } from "./build"
5
5
 
6
6
  let currentWatcher: ReturnType<typeof watch> | null = null
@@ -32,8 +32,9 @@ export function startWatcher() {
32
32
  for (let output of result.outputs) {
33
33
  state.currentCode = await output.text()
34
34
  }
35
+ let msg = buildReload({ code: state.currentCode })
35
36
  for (let ws of state.clients.keys()) {
36
- ws.send(JSON.stringify({ type: "reload", code: state.currentCode }))
37
+ ws.send(msg)
37
38
  }
38
39
  })
39
40
  }