Skip to content

Commit

Permalink
checkpoint, snippet development working
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Dec 15, 2024
1 parent b52f617 commit de15db2
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
19 changes: 18 additions & 1 deletion cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,28 @@ program
.option("-p, --port <number>", "Port to run server on", "3000")
.action(async (file: string, options: { port: string }) => {
const absolutePath = path.resolve(file)
const fileDir = path.dirname(absolutePath)
const port = parseInt(options.port)

// Start the server
await createServer(port)

await fetch(
`http://localhost:${port}/api/files/upsert`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
file_path: "entrypoint.tsx",
text_content: `
import MyCircuit from "./snippet.tsx"
circuit.add(<MyCircuit />)
`,
}),
},
)

// Function to update file content
const updateFile = async (filePath: string) => {
try {
Expand All @@ -35,7 +52,7 @@ program
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
file_path: path.relative(process.cwd(), filePath),
file_path: path.relative(fileDir, filePath),
text_content: content,
}),
},
Expand Down
13 changes: 13 additions & 0 deletions example-dir/snippet.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare module "@tsci/seveibar.red-led" {
export function useRedLed(name: string): any
}

declare module "@tsci/seveibar.push-button" {
export function usePushButton(name: string): any
}

declare module "@tsci/seveibar.smd-usb-c" {
export function useUsbC(name: string): any
}

import "@tscircuit/core"
1 change: 1 addition & 0 deletions example-dir/snippet.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "@tscircuit/core"
import { useRedLed } from "@tsci/seveibar.red-led"
import { usePushButton } from "@tsci/seveibar.push-button"
import { useUsbC } from "@tsci/seveibar.smd-usb-c"
Expand Down
11 changes: 11 additions & 0 deletions example-dir/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module "@tsci/seveibar.red-led" {
export function useRedLed(name: string): any
}

declare module "@tsci/seveibar.push-button" {
export function usePushButton(name: string): any
}

declare module "@tsci/seveibar.smd-usb-c" {
export function useUsbC(name: string): any
}
2 changes: 1 addition & 1 deletion lib/server/createServer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as http from "http"
import { getNodeHandler } from "winterspec/adapters/node"
// @ts-ignore
import winterspecBundle from "@tscircuit/file-server/dist/bundle"
import { getIndex } from "../site/getIndex"

Expand All @@ -8,7 +9,6 @@ export const createServer = async (port: number = 3000) => {

const server = http.createServer(async (req, res) => {
if (req.url === "/") {
console.log("getting index")
const html = await getIndex()
res.writeHead(200, { "Content-Type": "text/html" })
res.end(html)
Expand Down
9 changes: 7 additions & 2 deletions lib/site/getIndex.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
export const getIndex = async () => {
return `<html>
<head>
<script src="https://unpkg.com/@tscircuit/runframe/dist/standalone.js"></script>
</head>
<body>
<div id="root"></div>
<script src="https://cdn.tailwindcss.com"></script>
<div id="root">loading...</div>
<script>
globalThis.process = { env: { NODE_ENV: "production" } }
</script>
<script src="https://cdn.jsdelivr.net/npm/@tscircuit/[email protected]/dist/standalone.min.js"></script>
</body>
</html>`
}
// <script src="http://localhost:8000/standalone.umd.cjs"></script>
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
"main": "dist/lib/index.js",
"type": "module",
"scripts": {
"dev": "bun run cli/main.ts dev ./example-dir/snippet.tsx",
"dev": "bun run ./cli/main.ts dev ./example-dir/snippet.tsx",
"format": "biome format --write .",
"format:check": "biome format ."
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@tscircuit/core": "^0.0.229",
"@types/bun": "latest",
"@types/configstore": "^6.0.2",
"@types/react": "^19.0.1",
"tsup": "^8.3.5"
},
"peerDependencies": {
Expand Down

0 comments on commit de15db2

Please sign in to comment.