Skip to content

Commit fde2ca6

Browse files
committed
chore: temporarily replace react-ink with gum
At the time of writing, ink does not work with React 19
1 parent e1df3cc commit fde2ca6

File tree

4 files changed

+86
-48
lines changed

4 files changed

+86
-48
lines changed

packages/jokul/create-vite-server.mjs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import react from "@vitejs/plugin-react-swc";
2+
import { resolve } from "node:path";
3+
import { createServer } from "vite";
4+
import { copyJklFonts, setupDev } from "../../utils/vite/index.mjs";
5+
6+
async function createViteServer(componentName, customLogger) {
7+
const componentPath = resolve(
8+
process.argv[1],
9+
"..",
10+
"src",
11+
"components",
12+
componentName,
13+
"documentation",
14+
);
15+
16+
return await createServer({
17+
mode: "development",
18+
configFile: false,
19+
plugins: [
20+
react(),
21+
copyJklFonts(resolve(componentPath, "public", "fonts")),
22+
setupDev(componentPath),
23+
],
24+
resolve: {
25+
alias: {
26+
"doc-utils": resolve(
27+
process.argv[1],
28+
"..",
29+
"..",
30+
"..",
31+
"utils",
32+
"dev-example",
33+
),
34+
},
35+
},
36+
root: componentPath,
37+
server: {
38+
port: 3000,
39+
},
40+
customLogger,
41+
});
42+
}
43+
44+
export { createViteServer };
45+
46+
const componentName = process.argv[2];
47+
48+
// If a command line argument for a component is provided, start the dev-server
49+
if (componentName) {
50+
const server = await createViteServer(componentName);
51+
await server.listen();
52+
}

packages/jokul/dev-server.mjs

+13-47
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import react from "@vitejs/plugin-react-swc";
21
import { Box, Text, render, useApp, useInput } from "ink";
32
import SelectInput from "ink-select-input";
4-
import { resolve } from "node:path";
5-
import { fileURLToPath } from "node:url";
63
import React, { useEffect, useMemo, useRef, useState } from "react";
74
import glob from "tiny-glob";
8-
import { createServer } from "vite";
9-
import { copyJklFonts, setupDev } from "../../utils/vite/index.mjs";
5+
import { createViteServer } from "./create-vite-server.mjs";
106

117
export default function App() {
128
const [components, setComponents] = useState([]);
@@ -52,17 +48,7 @@ export default function App() {
5248

5349
useEffect(() => {
5450
glob("**/documentation/Example.tsx").then((result) => {
55-
setComponents(
56-
result.map((file) => {
57-
return {
58-
label: file.split("/")[2],
59-
value: resolve(
60-
fileURLToPath(new URL(file, import.meta.url)),
61-
"..",
62-
),
63-
};
64-
}),
65-
);
51+
setComponents(result.map((file) => file.split("/")[2]));
6652
});
6753
}, []);
6854

@@ -86,33 +72,9 @@ export default function App() {
8672
});
8773

8874
const handleSelect = async (component) => {
89-
setSelectedComponent(component);
75+
setSelectedComponent(component.label);
9076

91-
server.current = await createServer({
92-
mode: "development",
93-
configFile: false,
94-
plugins: [
95-
react(),
96-
copyJklFonts(resolve(component.value, "public", "fonts")),
97-
setupDev(component.value),
98-
],
99-
resolve: {
100-
alias: {
101-
"doc-utils": resolve(
102-
fileURLToPath(new URL(".", import.meta.url)),
103-
"..",
104-
"..",
105-
"utils",
106-
"dev-example",
107-
),
108-
},
109-
},
110-
root: component.value,
111-
server: {
112-
port: 3000,
113-
},
114-
customLogger,
115-
});
77+
server.current = await createViteServer(component.label, customLogger);
11678
await server.current.listen();
11779
};
11880

@@ -123,9 +85,13 @@ export default function App() {
12385
<Text>Choose a component from the list below</Text>
12486
<Text>Filter: {filterString}</Text>
12587
<SelectInput
126-
items={components.filter((component) =>
127-
component.label.startsWith(filterString),
128-
)}
88+
items={components
89+
.filter((component) =>
90+
component.startsWith(filterString),
91+
)
92+
.map((component) => ({
93+
label: component,
94+
}))}
12995
onSelect={handleSelect}
13096
/>
13197
</Box>
@@ -134,8 +100,8 @@ export default function App() {
134100
<Box flexDirection="column" gap={1}>
135101
<Text>
136102
Dev-server for component{" "}
137-
<Text color="green">{selectedComponent.label}</Text>{" "}
138-
started on port 3000
103+
<Text color="green">{selectedComponent}</Text> started
104+
on port 3000
139105
</Text>
140106
<Text>Use 'q' to exit to main menu</Text>
141107
</Box>

packages/jokul/dev.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#! /bin/sh
2+
3+
GUM_PATH=$(command -v gum)
4+
5+
if [ "$GUM_PATH" = "" ]
6+
then
7+
echo "gum is not installed"
8+
echo "see https://github.com/charmbracelet/gum?tab=readme-ov-file#installation"
9+
exit 1
10+
fi
11+
12+
COMPONENT=$(find src/components/* -iname documentation -type d | cut -d "/" -f 3 | gum filter)
13+
14+
if [ "$COMPONENT" = "" ]
15+
then
16+
exit 1
17+
fi
18+
19+
node create-vite-server.mjs $COMPONENT

packages/jokul/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@
543543
"scripts": {
544544
"generate:tokens": "node tokens.build.mjs",
545545
"build": "pnpm run /compile:*/",
546-
"dev": "babel --out-dir=. dev-server.mjs && node dev-server.js",
546+
"dev": "sh ./dev.sh",
547+
"dev-server": "babel --out-dir=. dev-server.mjs && node dev-server.js",
547548
"compile:style": "node build-styles.mjs",
548549
"compile:scripts": "vite build --config vite.build.config.mjs",
549550
"test": "vitest --config vite.test.config.mjs"

0 commit comments

Comments
 (0)