@tscircuit/cli 0.1.4 → 0.1.6
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/biome.json +1 -0
- package/bun.lockb +0 -0
- package/cli/dev/DevServer.ts +158 -0
- package/cli/dev/register.ts +9 -82
- package/cli/main.ts +4 -1
- package/dist/main.js +233 -234
- package/lib/dependency-analysis/{installNodeModuleTypes.ts → installNodeModuleTypesForSnippet.ts} +1 -1
- package/lib/file-server/FileServerEvent.ts +7 -0
- package/lib/file-server/FileServerRoutes.ts +38 -0
- package/lib/index.ts +1 -1
- package/lib/server/{createServer.ts → createHttpServer.ts} +3 -3
- package/package.json +10 -5
- package/tests/fixtures/get-test-fixture.ts +25 -0
- package/tests/test1-dev-server-basic.test.ts +40 -0
- package/tsconfig.json +2 -1
package/lib/dependency-analysis/{installNodeModuleTypes.ts → installNodeModuleTypesForSnippet.ts}
RENAMED
|
@@ -8,7 +8,7 @@ interface SnippetApiResponse {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export async function
|
|
11
|
+
export async function installNodeModuleTypesForSnippet(snippetPath: string) {
|
|
12
12
|
const content = fs.readFileSync(snippetPath, "utf-8")
|
|
13
13
|
const sourceFile = ts.createSourceFile(
|
|
14
14
|
snippetPath,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface FileServerRoutes {
|
|
2
|
+
"api/files/get": {
|
|
3
|
+
GET: {
|
|
4
|
+
searchParams: {
|
|
5
|
+
file_path: string
|
|
6
|
+
}
|
|
7
|
+
responseJson: {
|
|
8
|
+
file: {
|
|
9
|
+
file_id: string
|
|
10
|
+
file_path: string
|
|
11
|
+
text_content: string
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
"api/files/upsert": {
|
|
17
|
+
POST: {
|
|
18
|
+
requestJson: {
|
|
19
|
+
file_path: string
|
|
20
|
+
text_content: string
|
|
21
|
+
initiator?: "filesystem_change"
|
|
22
|
+
}
|
|
23
|
+
responseJson: {
|
|
24
|
+
file: {
|
|
25
|
+
file_id: string
|
|
26
|
+
file_path: string
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
"api/files/list": {
|
|
32
|
+
GET: {
|
|
33
|
+
responseJson: {
|
|
34
|
+
file_list: { file_id: string; file_path: string }[]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/lib/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createHttpServer } from "./server/createHttpServer"
|
|
2
2
|
export { getLocalFileDependencies } from "./dependency-analysis/getLocalFileDependencies"
|
|
@@ -8,7 +8,7 @@ import pkg from "../../package.json"
|
|
|
8
8
|
import winterspecBundle from "@tscircuit/file-server/dist/bundle.js"
|
|
9
9
|
import { getIndex } from "../site/getIndex"
|
|
10
10
|
|
|
11
|
-
export const
|
|
11
|
+
export const createHttpServer = async (port = 3000) => {
|
|
12
12
|
const fileServerHandler = getNodeHandler(winterspecBundle as any, {})
|
|
13
13
|
|
|
14
14
|
const server = http.createServer(async (req, res) => {
|
|
@@ -58,10 +58,10 @@ export const createServer = async (port: number = 3000) => {
|
|
|
58
58
|
res.end("Not found")
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
return new Promise<
|
|
61
|
+
return new Promise<{ server: http.Server }>((resolve) => {
|
|
62
62
|
server.listen(port, () => {
|
|
63
63
|
console.log(`Server running at http://localhost:${port}`)
|
|
64
|
-
resolve()
|
|
64
|
+
resolve({ server })
|
|
65
65
|
})
|
|
66
66
|
})
|
|
67
67
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tscircuit/cli",
|
|
3
3
|
"main": "dist/main.js",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.6",
|
|
6
6
|
"bin": {
|
|
7
7
|
"tsci": "./dist/main.js"
|
|
8
8
|
},
|
|
@@ -17,16 +17,20 @@
|
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@biomejs/biome": "^1.9.4",
|
|
19
19
|
"@tscircuit/core": "^0.0.249",
|
|
20
|
-
"@types/bun": "
|
|
20
|
+
"@types/bun": "^1.1.15",
|
|
21
21
|
"@types/configstore": "^6.0.2",
|
|
22
22
|
"@types/react": "^19.0.1",
|
|
23
|
-
"
|
|
23
|
+
"@types/semver": "^7.5.8",
|
|
24
|
+
"get-port": "^7.1.0",
|
|
25
|
+
"tempy": "^3.1.0",
|
|
26
|
+
"tsup": "^8.3.5",
|
|
27
|
+
"typed-ky": "^0.0.4"
|
|
24
28
|
},
|
|
25
29
|
"peerDependencies": {
|
|
26
30
|
"typescript": "^5.0.0"
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
|
-
"@tscircuit/file-server": "^0.0.
|
|
33
|
+
"@tscircuit/file-server": "^0.0.13",
|
|
30
34
|
"@tscircuit/runframe": "^0.0.47",
|
|
31
35
|
"chokidar": "^4.0.1",
|
|
32
36
|
"commander": "^12.1.0",
|
|
@@ -34,6 +38,7 @@
|
|
|
34
38
|
"cosmiconfig": "^9.0.0",
|
|
35
39
|
"delay": "^6.0.0",
|
|
36
40
|
"ky": "^1.7.4",
|
|
37
|
-
"perfect-cli": "^1.0.20"
|
|
41
|
+
"perfect-cli": "^1.0.20",
|
|
42
|
+
"semver": "^7.6.3"
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as tempy from "tempy"
|
|
2
|
+
import getPort from "get-port"
|
|
3
|
+
|
|
4
|
+
interface Params {
|
|
5
|
+
vfs?: Record<string, string>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const getTestFixture = async (params: Params) => {
|
|
9
|
+
// Create temp directory
|
|
10
|
+
const tempDirPath = await tempy.temporaryDirectory()
|
|
11
|
+
const devServerPort = await getPort()
|
|
12
|
+
|
|
13
|
+
// Write virtual filesystem files
|
|
14
|
+
if (params.vfs) {
|
|
15
|
+
for (const [filePath, content] of Object.entries(params.vfs)) {
|
|
16
|
+
await Bun.write(`${tempDirPath}/${filePath}`, content)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
tempDirPath,
|
|
22
|
+
devServerPort,
|
|
23
|
+
devServerUrl: `http://localhost:${devServerPort}`,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { test, expect, afterEach } from "bun:test"
|
|
2
|
+
import { DevServer } from "cli/dev/DevServer"
|
|
3
|
+
import { getTestFixture } from "tests/fixtures/get-test-fixture"
|
|
4
|
+
|
|
5
|
+
test("test1 basic dev server filesystem watching", async () => {
|
|
6
|
+
const { tempDirPath, devServerPort, devServerUrl } = await getTestFixture({
|
|
7
|
+
vfs: {
|
|
8
|
+
"snippet.tsx": `
|
|
9
|
+
export const MyCircuit = () => (
|
|
10
|
+
<board width="10mm" height="10mm">
|
|
11
|
+
<chip name="U1" footprint="soic8" />
|
|
12
|
+
</board>
|
|
13
|
+
)
|
|
14
|
+
`,
|
|
15
|
+
"manual-edits.json": "{}",
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const devServer = new DevServer({
|
|
20
|
+
port: devServerPort,
|
|
21
|
+
componentFilePath: `${tempDirPath}/snippet.tsx`,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
await devServer.start()
|
|
25
|
+
await devServer.addEntrypoint()
|
|
26
|
+
|
|
27
|
+
const { file_list } = await devServer.fsKy.get("api/files/list").json()
|
|
28
|
+
|
|
29
|
+
expect(file_list.map((f) => f.file_path).sort()).toMatchInlineSnapshot(`
|
|
30
|
+
[
|
|
31
|
+
"entrypoint.tsx",
|
|
32
|
+
"manual-edits.json",
|
|
33
|
+
"snippet.tsx",
|
|
34
|
+
]
|
|
35
|
+
`)
|
|
36
|
+
|
|
37
|
+
afterEach(async () => {
|
|
38
|
+
await devServer.stop()
|
|
39
|
+
})
|
|
40
|
+
})
|