Skip to content

Commit 147fff0

Browse files
committed
feat(devtools): add devtools
1 parent 2641cb4 commit 147fff0

File tree

16 files changed

+297
-1
lines changed

16 files changed

+297
-1
lines changed

pnpm-lock.yaml

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# RivetKit DevTools
2+
3+
4+
## Contributing
5+
6+
To contribute to the RivetKit DevTools package, please follow these steps:
7+
8+
1. Set up assets server for the `dist` folder:
9+
```bash
10+
pnpm dlx serve dist
11+
```
12+
13+
2. Set your `CUSTOM_RIVETKIT_DEVTOOLS_URL` environment variable to point to the assets server (default is `http://localhost:3000`):
14+
```bash
15+
export CUSTOM_RIVETKIT_DEVTOOLS_URL=http://localhost:5000
16+
```
17+
18+
This will ensure that the RivetKit will use local devtool assets instead of fetching them from the CDN.
19+
20+
3. In another terminal, run the development build:
21+
```bash
22+
pnpm dev
23+
```
24+
25+
or run the production build:
26+
```bash
27+
pnpm build
28+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@rivetkit/devtools",
3+
"private": true,
4+
"version": "2.0.24-rc.1",
5+
"description": "RivetKit DevTools - A set of development tools for RivetKit",
6+
"license": "Apache-2.0",
7+
"keywords": [
8+
"rivetkit"
9+
],
10+
"sideEffects": [
11+
"./dist/chunk-*.js",
12+
"./dist/chunk-*.cjs"
13+
],
14+
"files": [
15+
"dist",
16+
"package.json"
17+
],
18+
"exports": {
19+
".": {
20+
"import": {
21+
"types": "./dist/mod.d.mts",
22+
"default": "./dist/mod.mjs"
23+
},
24+
"require": {
25+
"types": "./dist/mod.d.ts",
26+
"default": "./dist/mod.js"
27+
}
28+
}
29+
},
30+
"scripts": {
31+
"build": "tsup src/mod.ts",
32+
"check-types": "tsc --noEmit"
33+
},
34+
"devDependencies": {
35+
"tsup": "^8.4.0",
36+
"typescript": "^5.5.2",
37+
"rivetkit": "workspace:*"
38+
},
39+
"stableVersion": "0.8.0"
40+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module "*.css" {
2+
const content: string;
3+
export default content;
4+
}
5+
6+
declare module "*.svg" {
7+
const content: string;
8+
export default content;
9+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import svg from "./icon.svg";
2+
import styles from "./styles.css";
3+
4+
declare global {
5+
interface Window {
6+
_rivetkit_devtools_configs?: Array<
7+
Parameters<typeof import("rivetkit/client")["createClient"]>[0]
8+
>;
9+
}
10+
}
11+
12+
const root = document.createElement("div");
13+
14+
root.id = "rivetkit-devtools";
15+
const shadow = root.attachShadow({ mode: "open" });
16+
17+
const img = document.createElement("img");
18+
img.src = svg;
19+
20+
const btn = document.createElement("button");
21+
btn.appendChild(img);
22+
23+
const style = document.createElement("style");
24+
style.textContent = styles;
25+
shadow.appendChild(style);
26+
shadow.appendChild(btn);
27+
28+
btn.addEventListener("click", () => {
29+
const config = window._rivetkit_devtools_configs?.[0];
30+
if (!config || typeof config !== "object") {
31+
console.error("RivetKit Devtools: No client config found");
32+
return;
33+
}
34+
const url = new URL("https://inspect.rivet.dev/");
35+
if (!config.endpoint) {
36+
console.error("RivetKit Devtools: No endpoint found in client config");
37+
return;
38+
}
39+
url.searchParams.set("u", config.endpoint);
40+
if (config.token) {
41+
url.searchParams.set("t", config.token);
42+
}
43+
if (config.namespace) {
44+
url.searchParams.set("ns", config.namespace);
45+
}
46+
if (config.runnerName) {
47+
url.searchParams.set("r", config.runnerName);
48+
}
49+
window.open(url.toString(), "_blank");
50+
});
51+
52+
document.body.appendChild(root);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
:host {
2+
all: initial;
3+
position: fixed;
4+
bottom: 12px;
5+
right: 12px;
6+
width: 48px;
7+
}
8+
9+
button {
10+
all: unset;
11+
width: 48px;
12+
height: 48px;
13+
display: block;
14+
cursor: pointer;
15+
}
16+
17+
img {
18+
width: 100%;
19+
height: 100%;
20+
object-fit: contain;
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"useDefineForClassFields": true,
5+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
6+
"module": "ESNext",
7+
"skipLibCheck": true,
8+
9+
/* Bundler mode */
10+
"moduleResolution": "bundler",
11+
"allowImportingTsExtensions": true,
12+
"resolveJsonModule": true,
13+
"isolatedModules": true,
14+
"noEmit": true,
15+
"jsx": "react-jsx",
16+
17+
/* Linting */
18+
"strict": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"noFallthroughCasesInSwitch": true
22+
},
23+
"include": ["src", "lib"]
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "tsup";
2+
import defaultConfig from "../../../tsup.base.ts";
3+
4+
export default defineConfig({
5+
...defaultConfig,
6+
loader: {
7+
".svg": "dataurl",
8+
".css": "text",
9+
},
10+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"extends": ["//"],
4+
"tasks": {
5+
"build": {
6+
"inputs": [
7+
"src/**",
8+
"tsconfig.json",
9+
"tsup.config.ts",
10+
"package.json"
11+
],
12+
"outputs": ["dist/**"]
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)