@istmx/ui 0.1.11 → 0.1.13
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/LICENSE +21 -21
- package/README.md +533 -463
- package/bin/istmx.mjs +481 -314
- package/package.json +27 -27
- package/registry/accordion.tsx +186 -0
- package/registry/ai-chat-block/ai-chat-block.tsx +456 -460
- package/registry/ai-chat-block/ai-chat-input.tsx +694 -694
- package/registry/ai-chat-block/attachment.tsx +466 -466
- package/registry/ai-chat-block/chat-code-block.tsx +50 -50
- package/registry/ai-chat-block/chat-composer.tsx +51 -51
- package/registry/ai-chat-block/chat-logo.tsx +18 -18
- package/registry/ai-chat-block/chat-message.tsx +161 -161
- package/registry/ai-chat-block/chat-sidebar.tsx +273 -273
- package/registry/ai-chat-block/chat-user-avatar.tsx +9 -9
- package/registry/ai-chat-block/code-highlighter.tsx +342 -357
- package/registry/ai-chat-block/default-attachments.tsx +42 -42
- package/registry/ai-chat-block/index.ts +30 -30
- package/registry/ai-chat-block/message-content.tsx +287 -287
- package/registry/ai-chat-block/message-list.tsx +93 -93
- package/registry/ai-chat-block/send-button.tsx +102 -102
- package/registry/ai-chat-block/types.ts +70 -71
- package/registry/ai-chat-block/utils.ts +6 -6
- package/registry/ai-chat-block/voice-button.tsx +66 -66
- package/registry/alert-dialog.tsx +229 -0
- package/registry/alert.tsx +188 -0
- package/registry/animated-text.tsx +228 -225
- package/registry/aspect-ratio.tsx +32 -0
- package/registry/avatar-group.tsx +66 -0
- package/registry/avatar.tsx +121 -0
- package/registry/badge.tsx +52 -0
- package/registry/bento-grid.tsx +438 -433
- package/registry/button.tsx +156 -237
- package/registry/carousel.tsx +184 -0
- package/registry/dock-navigation.tsx +200 -198
- package/registry/drift-canvas.tsx +383 -0
- package/registry/drift-wall.tsx +361 -0
- package/registry/flex-carousel.tsx +1430 -0
- package/registry/guided-gallery.tsx +1506 -0
- package/registry/image-accordion.tsx +306 -302
- package/registry/image-trail.tsx +126 -121
- package/registry/infinite-image-canvas.tsx +268 -263
- package/registry/input-otp.tsx +332 -0
- package/registry/list-card.tsx +130 -0
- package/registry/mobile-menu-dock.tsx +216 -211
- package/registry/morph-slider.tsx +756 -0
- package/registry/pixel-cat.tsx +972 -1020
- package/registry/scroll-canvas-cards.tsx +643 -0
- package/registry/scroll-parallax-hero.tsx +566 -565
- package/registry/scroll-story-cards.tsx +443 -438
- package/registry/slider.tsx +163 -0
- package/registry/spotlight-grid.tsx +226 -0
- package/registry/streaming-text.tsx +269 -278
- package/registry/text-reveal.tsx +311 -307
- package/registry/user-avatar.tsx +99 -0
- package/registry/utils.ts +6 -6
package/bin/istmx.mjs
CHANGED
|
@@ -1,314 +1,481 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { spawnSync } from 'node:child_process'
|
|
4
|
-
import { constants, existsSync } from 'node:fs'
|
|
5
|
-
import { access, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
'
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
)
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
)
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from 'node:child_process'
|
|
4
|
+
import { constants, existsSync } from 'node:fs'
|
|
5
|
+
import { access, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
|
|
6
|
+
import { createInterface } from 'node:readline/promises'
|
|
7
|
+
import path from 'node:path'
|
|
8
|
+
import { fileURLToPath } from 'node:url'
|
|
9
|
+
|
|
10
|
+
const VERSION = '0.1.13'
|
|
11
|
+
const COMPONENTS = {
|
|
12
|
+
button: { fileName: 'button.tsx' },
|
|
13
|
+
accordion: {
|
|
14
|
+
fileName: 'accordion.tsx',
|
|
15
|
+
dependencies: ['@tabler/icons-react'],
|
|
16
|
+
},
|
|
17
|
+
alert: {
|
|
18
|
+
fileName: 'alert.tsx',
|
|
19
|
+
dependencies: ['@tabler/icons-react'],
|
|
20
|
+
},
|
|
21
|
+
'alert-dialog': {
|
|
22
|
+
fileName: 'alert-dialog.tsx',
|
|
23
|
+
dependencies: ['@tabler/icons-react'],
|
|
24
|
+
},
|
|
25
|
+
'aspect-ratio': { fileName: 'aspect-ratio.tsx' },
|
|
26
|
+
avatar: { fileName: 'avatar.tsx' },
|
|
27
|
+
'avatar-group': { fileName: 'avatar-group.tsx' },
|
|
28
|
+
badge: { fileName: 'badge.tsx' },
|
|
29
|
+
carousel: {
|
|
30
|
+
fileName: 'carousel.tsx',
|
|
31
|
+
dependencies: ['@tabler/icons-react'],
|
|
32
|
+
},
|
|
33
|
+
'input-otp': {
|
|
34
|
+
fileName: 'input-otp.tsx',
|
|
35
|
+
dependencies: ['input-otp'],
|
|
36
|
+
},
|
|
37
|
+
'list-card': {
|
|
38
|
+
fileName: 'list-card.tsx',
|
|
39
|
+
dependencies: ['@tabler/icons-react'],
|
|
40
|
+
},
|
|
41
|
+
slider: { fileName: 'slider.tsx' },
|
|
42
|
+
'spotlight-grid': { fileName: 'spotlight-grid.tsx' },
|
|
43
|
+
'user-avatar': { fileName: 'user-avatar.tsx' },
|
|
44
|
+
'animated-text': { fileName: 'animated-text.tsx' },
|
|
45
|
+
'text-reveal': { fileName: 'text-reveal.tsx' },
|
|
46
|
+
'streaming-text': { fileName: 'streaming-text.tsx' },
|
|
47
|
+
'infinite-image-canvas': { fileName: 'infinite-image-canvas.tsx' },
|
|
48
|
+
'image-trail': { fileName: 'image-trail.tsx' },
|
|
49
|
+
'image-accordion': { fileName: 'image-accordion.tsx' },
|
|
50
|
+
'guided-gallery': {
|
|
51
|
+
fileName: 'guided-gallery.tsx',
|
|
52
|
+
dependencies: ['ogl', 'torph'],
|
|
53
|
+
},
|
|
54
|
+
'dock-navigation': {
|
|
55
|
+
fileName: 'dock-navigation.tsx',
|
|
56
|
+
dependencies: ['@tabler/icons-react'],
|
|
57
|
+
},
|
|
58
|
+
'mobile-menu-dock': {
|
|
59
|
+
fileName: 'mobile-menu-dock.tsx',
|
|
60
|
+
dependencies: ['@tabler/icons-react'],
|
|
61
|
+
},
|
|
62
|
+
'scroll-story-cards': {
|
|
63
|
+
fileName: 'scroll-story-cards.tsx',
|
|
64
|
+
dependencies: ['@tabler/icons-react'],
|
|
65
|
+
},
|
|
66
|
+
'pixel-cat': { fileName: 'pixel-cat.tsx' },
|
|
67
|
+
'bento-grid': {
|
|
68
|
+
fileName: 'bento-grid.tsx',
|
|
69
|
+
dependencies: ['@tabler/icons-react'],
|
|
70
|
+
},
|
|
71
|
+
'scroll-parallax-hero': { fileName: 'scroll-parallax-hero.tsx' },
|
|
72
|
+
'scroll-canvas-cards': {
|
|
73
|
+
fileName: 'scroll-canvas-cards.tsx',
|
|
74
|
+
dependencies: ['gsap', '@gsap/react'],
|
|
75
|
+
},
|
|
76
|
+
'drift-canvas': { fileName: 'drift-canvas.tsx' },
|
|
77
|
+
'drift-wall': { fileName: 'drift-wall.tsx' },
|
|
78
|
+
'flex-carousel': {
|
|
79
|
+
fileName: 'flex-carousel.tsx',
|
|
80
|
+
dependencies: ['@tabler/icons-react'],
|
|
81
|
+
},
|
|
82
|
+
'morph-slider': {
|
|
83
|
+
fileName: 'morph-slider.tsx',
|
|
84
|
+
dependencies: ['@tabler/icons-react'],
|
|
85
|
+
},
|
|
86
|
+
'ai-chat-block': {
|
|
87
|
+
directory: 'ai-chat-block',
|
|
88
|
+
dependencies: ['@tabler/icons-react'],
|
|
89
|
+
utility: false,
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
const DEPENDENCIES = ['motion', 'clsx', 'tailwind-merge']
|
|
93
|
+
const COMMANDS = {
|
|
94
|
+
npm: ['install'],
|
|
95
|
+
pnpm: ['add'],
|
|
96
|
+
yarn: ['add'],
|
|
97
|
+
bun: ['add'],
|
|
98
|
+
}
|
|
99
|
+
const CURRENT_DIRECTORY = process.cwd()
|
|
100
|
+
const PACKAGE_DIRECTORY = path.resolve(
|
|
101
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
102
|
+
'..',
|
|
103
|
+
)
|
|
104
|
+
const REGISTRY_DIRECTORY = path.join(PACKAGE_DIRECTORY, 'registry')
|
|
105
|
+
const USE_COLOR = Boolean(process.stdout.isTTY && !process.env.NO_COLOR)
|
|
106
|
+
|
|
107
|
+
const color = (code, value) =>
|
|
108
|
+
USE_COLOR ? `\u001B[${code}m${value}\u001B[0m` : value
|
|
109
|
+
const cyan = (value) => color('36;1', value)
|
|
110
|
+
const muted = (value) => color('2', value)
|
|
111
|
+
const green = (value) => color('32;1', value)
|
|
112
|
+
const red = (value) => color('31;1', value)
|
|
113
|
+
|
|
114
|
+
function printHeader() {
|
|
115
|
+
console.log(`\n${cyan('┌')} ${cyan('ISTMX UI')} ${muted(`v${VERSION}`)}`)
|
|
116
|
+
console.log(`${cyan('│')} ${muted('Editable components for your codebase')}`)
|
|
117
|
+
console.log(`${cyan('└')}${muted('─'.repeat(42))}\n`)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function printStep(label) {
|
|
121
|
+
console.log(`${cyan('◇')} ${label}`)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function printSuccess(label) {
|
|
125
|
+
console.log(`${green('✔')} ${label}`)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function printHelp() {
|
|
129
|
+
printHeader()
|
|
130
|
+
console.log(`Usage:
|
|
131
|
+
|
|
132
|
+
istmx add <component> [--no-install] [--overwrite]
|
|
133
|
+
istmx --help
|
|
134
|
+
istmx --version
|
|
135
|
+
|
|
136
|
+
Options:
|
|
137
|
+
--no-install Write component files without installing dependencies
|
|
138
|
+
--overwrite Replace component files that already exist
|
|
139
|
+
|
|
140
|
+
Components:
|
|
141
|
+
${Object.keys(COMPONENTS)
|
|
142
|
+
.map((name) => ` ${name}`)
|
|
143
|
+
.join('\n')}`)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function detectPackageManager(projectPackage) {
|
|
147
|
+
const userAgent = process.env.npm_config_user_agent ?? ''
|
|
148
|
+
const managerFromUserAgent = userAgent.match(/^(npm|pnpm|yarn|bun)\//)?.[1]
|
|
149
|
+
|
|
150
|
+
if (managerFromUserAgent) return managerFromUserAgent
|
|
151
|
+
|
|
152
|
+
const managerFromPackage =
|
|
153
|
+
typeof projectPackage.packageManager === 'string'
|
|
154
|
+
? projectPackage.packageManager.match(/^(npm|pnpm|yarn|bun)@/)?.[1]
|
|
155
|
+
: undefined
|
|
156
|
+
|
|
157
|
+
if (managerFromPackage) return managerFromPackage
|
|
158
|
+
|
|
159
|
+
const lockfiles = [
|
|
160
|
+
['pnpm-lock.yaml', 'pnpm'],
|
|
161
|
+
['yarn.lock', 'yarn'],
|
|
162
|
+
['bun.lock', 'bun'],
|
|
163
|
+
['bun.lockb', 'bun'],
|
|
164
|
+
['package-lock.json', 'npm'],
|
|
165
|
+
]
|
|
166
|
+
|
|
167
|
+
for (const [lockfile, manager] of lockfiles) {
|
|
168
|
+
if (existsSync(path.join(CURRENT_DIRECTORY, lockfile))) return manager
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return 'npm'
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function readProjectPackage() {
|
|
175
|
+
const packagePath = path.join(CURRENT_DIRECTORY, 'package.json')
|
|
176
|
+
try {
|
|
177
|
+
const content = await readFile(packagePath, 'utf8')
|
|
178
|
+
return JSON.parse(content)
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error instanceof SyntaxError) {
|
|
181
|
+
throw new Error('Could not parse the project package.json.')
|
|
182
|
+
}
|
|
183
|
+
throw new Error('Run `istmx add` from a project folder with package.json.')
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function installedDependencies(projectPackage) {
|
|
188
|
+
return {
|
|
189
|
+
...projectPackage.dependencies,
|
|
190
|
+
...projectPackage.devDependencies,
|
|
191
|
+
...projectPackage.optionalDependencies,
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function dependencyCommand(manager, dependencies) {
|
|
196
|
+
return [manager, ...COMMANDS[manager], ...dependencies]
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function writeRegistryFile(sourceName, targetPath, overwrite) {
|
|
200
|
+
const content = await readFile(
|
|
201
|
+
path.join(REGISTRY_DIRECTORY, sourceName),
|
|
202
|
+
'utf8',
|
|
203
|
+
)
|
|
204
|
+
await mkdir(path.dirname(targetPath), { recursive: true })
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
await access(targetPath, constants.F_OK)
|
|
208
|
+
if (!overwrite) {
|
|
209
|
+
console.log(
|
|
210
|
+
`${muted('·')} Kept existing ${path.relative(CURRENT_DIRECTORY, targetPath)}`,
|
|
211
|
+
)
|
|
212
|
+
return false
|
|
213
|
+
}
|
|
214
|
+
} catch {}
|
|
215
|
+
|
|
216
|
+
await writeFile(targetPath, content, 'utf8')
|
|
217
|
+
printSuccess(`Added ${path.relative(CURRENT_DIRECTORY, targetPath)}`)
|
|
218
|
+
return true
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function writeRegistryDirectory(sourceName, targetPath, overwrite) {
|
|
222
|
+
const sourcePath = path.join(REGISTRY_DIRECTORY, sourceName)
|
|
223
|
+
const files = await readdir(sourcePath, { withFileTypes: true })
|
|
224
|
+
for (const entry of files) {
|
|
225
|
+
if (!entry.isFile()) continue
|
|
226
|
+
await writeRegistryFile(
|
|
227
|
+
path.join(sourceName, entry.name),
|
|
228
|
+
path.join(targetPath, entry.name),
|
|
229
|
+
overwrite,
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function installDependencies(manager, dependencies) {
|
|
235
|
+
if (dependencies.length === 0) {
|
|
236
|
+
printSuccess('Dependencies are already present.')
|
|
237
|
+
return true
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const [command, ...args] = dependencyCommand(manager, dependencies)
|
|
241
|
+
printStep(`Installing dependencies with ${manager}`)
|
|
242
|
+
console.log(` ${muted(dependencies.join(' · '))}`)
|
|
243
|
+
const result = spawnSync(command, args, {
|
|
244
|
+
cwd: CURRENT_DIRECTORY,
|
|
245
|
+
stdio: 'inherit',
|
|
246
|
+
shell: process.platform === 'win32',
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
if (result.status === 0) {
|
|
250
|
+
printSuccess('Dependencies installed.')
|
|
251
|
+
return true
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return false
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function addComponent(component, options) {
|
|
258
|
+
const definition = COMPONENTS[component]
|
|
259
|
+
if (!definition) {
|
|
260
|
+
throw new Error(
|
|
261
|
+
`Unknown component "${component}". Available components: ${Object.keys(COMPONENTS).join(', ')}. Run istmx --help to see available components.`,
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
const componentDependencies = [
|
|
265
|
+
...new Set([...DEPENDENCIES, ...(definition.dependencies ?? [])]),
|
|
266
|
+
]
|
|
267
|
+
|
|
268
|
+
const projectPackage = await readProjectPackage()
|
|
269
|
+
const manager = detectPackageManager(projectPackage)
|
|
270
|
+
printHeader()
|
|
271
|
+
console.log(
|
|
272
|
+
`${muted('Adding')} ${cyan(component)} ${muted('to your project')}\n`,
|
|
273
|
+
)
|
|
274
|
+
printStep('Writing editable source files')
|
|
275
|
+
const componentPath = definition.directory
|
|
276
|
+
? path.join(
|
|
277
|
+
CURRENT_DIRECTORY,
|
|
278
|
+
'components',
|
|
279
|
+
definition.targetDirectory ?? component,
|
|
280
|
+
)
|
|
281
|
+
: path.join(CURRENT_DIRECTORY, 'components', 'ui', definition.fileName)
|
|
282
|
+
const utilityPath = path.join(CURRENT_DIRECTORY, 'lib', 'utils.ts')
|
|
283
|
+
|
|
284
|
+
if (definition.utility !== false) {
|
|
285
|
+
await writeRegistryFile('utils.ts', utilityPath, options.overwrite)
|
|
286
|
+
}
|
|
287
|
+
if (definition.directory) {
|
|
288
|
+
await writeRegistryDirectory(
|
|
289
|
+
definition.directory,
|
|
290
|
+
componentPath,
|
|
291
|
+
options.overwrite,
|
|
292
|
+
)
|
|
293
|
+
} else {
|
|
294
|
+
await writeRegistryFile(
|
|
295
|
+
definition.fileName,
|
|
296
|
+
componentPath,
|
|
297
|
+
options.overwrite,
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (options.noInstall) {
|
|
302
|
+
const missing = componentDependencies.filter(
|
|
303
|
+
(dependency) => !installedDependencies(projectPackage)[dependency],
|
|
304
|
+
)
|
|
305
|
+
if (missing.length > 0) {
|
|
306
|
+
printStep('Install the required dependencies manually')
|
|
307
|
+
console.log(` ${cyan(dependencyCommand(manager, missing).join(' '))}`)
|
|
308
|
+
}
|
|
309
|
+
printSuccess('Source files are ready.')
|
|
310
|
+
return
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const installed = installedDependencies(projectPackage)
|
|
314
|
+
const missingDependencies = componentDependencies.filter(
|
|
315
|
+
(dependency) => !installed[dependency],
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
if (!installDependencies(manager, missingDependencies)) {
|
|
319
|
+
throw new Error(
|
|
320
|
+
`Dependency installation failed. Run ${dependencyCommand(manager, missingDependencies).join(' ')} and try again.`,
|
|
321
|
+
)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
console.log(`\n${green('Done!')} ${component} is ready to edit.`)
|
|
325
|
+
console.log(
|
|
326
|
+
` ${muted('Import from')} ${cyan(definition.importPath ?? (definition.directory ? `@/components/${definition.targetDirectory ?? component}` : `@/components/ui/${component}`))}`,
|
|
327
|
+
)
|
|
328
|
+
console.log(
|
|
329
|
+
` ${muted('Dependencies')} ${cyan(componentDependencies.join(', '))}\n`,
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async function handleMcpCommand(subCommand = 'connect', args = []) {
|
|
334
|
+
if (
|
|
335
|
+
subCommand === '--help' ||
|
|
336
|
+
subCommand === '-h' ||
|
|
337
|
+
subCommand === 'help' ||
|
|
338
|
+
args.includes('--help') ||
|
|
339
|
+
args.includes('-h')
|
|
340
|
+
) {
|
|
341
|
+
console.log(`\nUsage: istmx mcp connect [options]
|
|
342
|
+
|
|
343
|
+
Connect ISTMX UI MCP server to OpenCode and Cursor.
|
|
344
|
+
|
|
345
|
+
Options:
|
|
346
|
+
--token=<token|email> Your MCP token or registered IstmX email
|
|
347
|
+
--help, -h Show help for mcp command\n`)
|
|
348
|
+
return
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
printHeader()
|
|
352
|
+
printStep('Connecting ISTMX UI MCP Server...')
|
|
353
|
+
|
|
354
|
+
let token = null
|
|
355
|
+
for (const arg of [subCommand, ...args]) {
|
|
356
|
+
if (arg.startsWith('--token=')) {
|
|
357
|
+
token = arg.replace('--token=', '').trim()
|
|
358
|
+
} else if (arg !== 'connect' && !arg.startsWith('--') && !token) {
|
|
359
|
+
token = arg.trim()
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (!token) {
|
|
364
|
+
const authUrl = 'https://istmx-ui.vercel.app/profile?cli_auth=true'
|
|
365
|
+
printStep(`Opening authentication in browser: ${cyan(authUrl)}`)
|
|
366
|
+
try {
|
|
367
|
+
if (process.platform === 'win32') {
|
|
368
|
+
spawnSync('cmd', ['/c', 'start', '""', authUrl])
|
|
369
|
+
} else if (process.platform === 'darwin') {
|
|
370
|
+
spawnSync('open', [authUrl])
|
|
371
|
+
} else {
|
|
372
|
+
spawnSync('xdg-open', [authUrl])
|
|
373
|
+
}
|
|
374
|
+
} catch {}
|
|
375
|
+
|
|
376
|
+
const rl = createInterface({
|
|
377
|
+
input: process.stdin,
|
|
378
|
+
output: process.stdout,
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
const answer = await rl.question(
|
|
382
|
+
`\nEnter your MCP token or registered IstmX email: `,
|
|
383
|
+
)
|
|
384
|
+
rl.close()
|
|
385
|
+
token = answer.trim()
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (!token) {
|
|
389
|
+
throw new Error('Authentication cancelled: No token or email provided.')
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const sseUrl = `https://istmx-ui.vercel.app/api/mcp?token=${encodeURIComponent(token)}`
|
|
393
|
+
|
|
394
|
+
const opencodeFile = path.join(CURRENT_DIRECTORY, 'opencode.jsonc')
|
|
395
|
+
const opencodeJsonFile = path.join(CURRENT_DIRECTORY, 'opencode.json')
|
|
396
|
+
const targetOpencode = existsSync(opencodeJsonFile) ? opencodeJsonFile : opencodeFile
|
|
397
|
+
|
|
398
|
+
let opencodeConfig = {
|
|
399
|
+
$schema: 'https://opencode.ai/config.json',
|
|
400
|
+
mcp: {},
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (existsSync(targetOpencode)) {
|
|
404
|
+
try {
|
|
405
|
+
const existing = await readFile(targetOpencode, 'utf8')
|
|
406
|
+
opencodeConfig = JSON.parse(existing)
|
|
407
|
+
} catch {}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (!opencodeConfig.mcp) opencodeConfig.mcp = {}
|
|
411
|
+
opencodeConfig.mcp['istmx-ui'] = {
|
|
412
|
+
type: 'remote',
|
|
413
|
+
url: sseUrl,
|
|
414
|
+
enabled: true,
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
await writeFile(targetOpencode, JSON.stringify(opencodeConfig, null, 2) + '\n', 'utf8')
|
|
418
|
+
printSuccess(`Configured OpenCode: ${path.basename(targetOpencode)}`)
|
|
419
|
+
|
|
420
|
+
const cursorDir = path.join(CURRENT_DIRECTORY, '.cursor')
|
|
421
|
+
const cursorFile = path.join(cursorDir, 'mcp.json')
|
|
422
|
+
let cursorConfig = { mcpServers: {} }
|
|
423
|
+
|
|
424
|
+
if (!existsSync(cursorDir)) {
|
|
425
|
+
await mkdir(cursorDir, { recursive: true })
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (existsSync(cursorFile)) {
|
|
429
|
+
try {
|
|
430
|
+
const existingCursor = await readFile(cursorFile, 'utf8')
|
|
431
|
+
cursorConfig = JSON.parse(existingCursor)
|
|
432
|
+
} catch {}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (!cursorConfig.mcpServers) cursorConfig.mcpServers = {}
|
|
436
|
+
cursorConfig.mcpServers['istmx-ui'] = { url: sseUrl }
|
|
437
|
+
|
|
438
|
+
await writeFile(cursorFile, JSON.stringify(cursorConfig, null, 2) + '\n', 'utf8')
|
|
439
|
+
printSuccess(`Configured Cursor: .cursor/mcp.json`)
|
|
440
|
+
|
|
441
|
+
console.log(`\n${green('Done!')} MCP Server is connected and active.`)
|
|
442
|
+
console.log(` ${muted('Target URL')} ${cyan(sseUrl)}`)
|
|
443
|
+
console.log(` ${muted('Ready to use in OpenCode and Cursor.')}\n`)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const [command, ...argumentsList] = process.argv.slice(2)
|
|
447
|
+
const component = argumentsList
|
|
448
|
+
.filter((argument) => !argument.startsWith('--'))
|
|
449
|
+
.join('-')
|
|
450
|
+
.toLowerCase()
|
|
451
|
+
const options = {
|
|
452
|
+
noInstall: argumentsList.includes('--no-install'),
|
|
453
|
+
overwrite: argumentsList.includes('--overwrite'),
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (command === '--help' || command === '-h' || !command) {
|
|
457
|
+
printHelp()
|
|
458
|
+
} else if (command === '--version' || command === '-v') {
|
|
459
|
+
console.log(VERSION)
|
|
460
|
+
} else if (command === 'add') {
|
|
461
|
+
if (!component || component.startsWith('--')) {
|
|
462
|
+
console.error('Choose a component name. Run `istmx --help` to see options.')
|
|
463
|
+
process.exitCode = 1
|
|
464
|
+
} else {
|
|
465
|
+
addComponent(component, options).catch((error) => {
|
|
466
|
+
console.error(`\n${red('✖')} ${error.message}`)
|
|
467
|
+
process.exitCode = 1
|
|
468
|
+
})
|
|
469
|
+
}
|
|
470
|
+
} else if (command === 'mcp') {
|
|
471
|
+
const subCommand = argumentsList[0] || 'connect'
|
|
472
|
+
handleMcpCommand(subCommand, argumentsList.slice(1)).catch((error) => {
|
|
473
|
+
console.error(`\n${red('✖')} ${error.message}`)
|
|
474
|
+
process.exitCode = 1
|
|
475
|
+
})
|
|
476
|
+
} else {
|
|
477
|
+
console.error(
|
|
478
|
+
`${red('✖')} Unknown command "${command}". Run istmx --help for usage.`,
|
|
479
|
+
)
|
|
480
|
+
process.exitCode = 1
|
|
481
|
+
}
|