@istmx/ui 0.1.12 → 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.
Files changed (55) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +533 -469
  3. package/bin/istmx.mjs +481 -318
  4. package/package.json +27 -27
  5. package/registry/accordion.tsx +186 -0
  6. package/registry/ai-chat-block/ai-chat-block.tsx +456 -460
  7. package/registry/ai-chat-block/ai-chat-input.tsx +694 -694
  8. package/registry/ai-chat-block/attachment.tsx +466 -466
  9. package/registry/ai-chat-block/chat-code-block.tsx +50 -50
  10. package/registry/ai-chat-block/chat-composer.tsx +51 -51
  11. package/registry/ai-chat-block/chat-logo.tsx +18 -18
  12. package/registry/ai-chat-block/chat-message.tsx +161 -161
  13. package/registry/ai-chat-block/chat-sidebar.tsx +273 -273
  14. package/registry/ai-chat-block/chat-user-avatar.tsx +9 -9
  15. package/registry/ai-chat-block/code-highlighter.tsx +342 -357
  16. package/registry/ai-chat-block/default-attachments.tsx +42 -42
  17. package/registry/ai-chat-block/index.ts +30 -30
  18. package/registry/ai-chat-block/message-content.tsx +287 -287
  19. package/registry/ai-chat-block/message-list.tsx +93 -93
  20. package/registry/ai-chat-block/send-button.tsx +102 -102
  21. package/registry/ai-chat-block/types.ts +70 -71
  22. package/registry/ai-chat-block/utils.ts +6 -6
  23. package/registry/ai-chat-block/voice-button.tsx +66 -66
  24. package/registry/alert-dialog.tsx +229 -0
  25. package/registry/alert.tsx +188 -0
  26. package/registry/animated-text.tsx +228 -225
  27. package/registry/aspect-ratio.tsx +32 -0
  28. package/registry/avatar-group.tsx +66 -0
  29. package/registry/avatar.tsx +121 -0
  30. package/registry/badge.tsx +52 -0
  31. package/registry/bento-grid.tsx +438 -433
  32. package/registry/button.tsx +156 -237
  33. package/registry/carousel.tsx +184 -0
  34. package/registry/dock-navigation.tsx +200 -198
  35. package/registry/drift-canvas.tsx +383 -0
  36. package/registry/drift-wall.tsx +361 -0
  37. package/registry/flex-carousel.tsx +1430 -0
  38. package/registry/guided-gallery.tsx +1506 -0
  39. package/registry/image-accordion.tsx +306 -302
  40. package/registry/image-trail.tsx +126 -121
  41. package/registry/infinite-image-canvas.tsx +268 -263
  42. package/registry/input-otp.tsx +332 -0
  43. package/registry/list-card.tsx +130 -0
  44. package/registry/mobile-menu-dock.tsx +216 -211
  45. package/registry/morph-slider.tsx +756 -0
  46. package/registry/pixel-cat.tsx +972 -1020
  47. package/registry/scroll-canvas-cards.tsx +643 -640
  48. package/registry/scroll-parallax-hero.tsx +566 -565
  49. package/registry/scroll-story-cards.tsx +443 -438
  50. package/registry/slider.tsx +163 -0
  51. package/registry/spotlight-grid.tsx +226 -0
  52. package/registry/streaming-text.tsx +269 -278
  53. package/registry/text-reveal.tsx +311 -307
  54. package/registry/user-avatar.tsx +99 -0
  55. package/registry/utils.ts +6 -6
package/bin/istmx.mjs CHANGED
@@ -1,318 +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 path from 'node:path'
7
- import { fileURLToPath } from 'node:url'
8
-
9
- const VERSION = '0.1.12'
10
- const COMPONENTS = {
11
- button: { fileName: 'button.tsx' },
12
- 'animated-text': { fileName: 'animated-text.tsx' },
13
- 'text-reveal': { fileName: 'text-reveal.tsx' },
14
- 'streaming-text': { fileName: 'streaming-text.tsx' },
15
- 'infinite-image-canvas': { fileName: 'infinite-image-canvas.tsx' },
16
- 'image-trail': { fileName: 'image-trail.tsx' },
17
- 'image-accordion': { fileName: 'image-accordion.tsx' },
18
- 'dock-navigation': {
19
- fileName: 'dock-navigation.tsx',
20
- dependencies: ['@tabler/icons-react'],
21
- },
22
- 'mobile-menu-dock': {
23
- fileName: 'mobile-menu-dock.tsx',
24
- dependencies: ['@tabler/icons-react'],
25
- },
26
- 'scroll-story-cards': {
27
- fileName: 'scroll-story-cards.tsx',
28
- dependencies: ['@tabler/icons-react'],
29
- },
30
- 'pixel-cat': { fileName: 'pixel-cat.tsx' },
31
- 'bento-grid': {
32
- fileName: 'bento-grid.tsx',
33
- dependencies: ['@tabler/icons-react'],
34
- },
35
- 'scroll-parallax-hero': { fileName: 'scroll-parallax-hero.tsx' },
36
- 'scroll-canvas-cards': {
37
- fileName: 'scroll-canvas-cards.tsx',
38
- dependencies: ['gsap', '@gsap/react'],
39
- },
40
- 'ai-chat-block': {
41
- directory: 'ai-chat-block',
42
- dependencies: ['@tabler/icons-react'],
43
- utility: false,
44
- },
45
- }
46
- const DEPENDENCIES = ['motion', 'clsx', 'tailwind-merge']
47
- const COMMANDS = {
48
- npm: ['install'],
49
- pnpm: ['add'],
50
- yarn: ['add'],
51
- bun: ['add'],
52
- }
53
- const CURRENT_DIRECTORY = process.cwd()
54
- const PACKAGE_DIRECTORY = path.resolve(
55
- path.dirname(fileURLToPath(import.meta.url)),
56
- '..',
57
- )
58
- const REGISTRY_DIRECTORY = path.join(PACKAGE_DIRECTORY, 'registry')
59
- const USE_COLOR = Boolean(process.stdout.isTTY && !process.env.NO_COLOR)
60
-
61
- const color = (code, value) =>
62
- USE_COLOR ? `\u001B[${code}m${value}\u001B[0m` : value
63
- const cyan = (value) => color('36;1', value)
64
- const muted = (value) => color('2', value)
65
- const green = (value) => color('32;1', value)
66
- const red = (value) => color('31;1', value)
67
-
68
- function printHeader() {
69
- console.log(`\n${cyan('┌')} ${cyan('ISTMX UI')} ${muted(`v${VERSION}`)}`)
70
- console.log(`${cyan('│')} ${muted('Editable components for your codebase')}`)
71
- console.log(`${cyan('└')}${muted('─'.repeat(42))}\n`)
72
- }
73
-
74
- function printStep(label) {
75
- console.log(`${cyan('◇')} ${label}`)
76
- }
77
-
78
- function printSuccess(label) {
79
- console.log(`${green('✔')} ${label}`)
80
- }
81
-
82
- function printHelp() {
83
- printHeader()
84
- console.log(`Usage:
85
-
86
- istmx add <component> [--no-install] [--overwrite]
87
- istmx --help
88
- istmx --version
89
-
90
- Options:
91
- --no-install Write component files without installing dependencies
92
- --overwrite Replace component files that already exist
93
-
94
- Components:
95
- ${Object.keys(COMPONENTS)
96
- .map((name) => ` ${name}`)
97
- .join('\n')}`)
98
- }
99
-
100
- function detectPackageManager(projectPackage) {
101
- const userAgent = process.env.npm_config_user_agent ?? ''
102
- const managerFromUserAgent = userAgent.match(/^(npm|pnpm|yarn|bun)\//)?.[1]
103
-
104
- if (managerFromUserAgent) return managerFromUserAgent
105
-
106
- const managerFromPackage =
107
- typeof projectPackage.packageManager === 'string'
108
- ? projectPackage.packageManager.match(/^(npm|pnpm|yarn|bun)@/)?.[1]
109
- : undefined
110
-
111
- if (managerFromPackage) return managerFromPackage
112
-
113
- const lockfiles = [
114
- ['pnpm-lock.yaml', 'pnpm'],
115
- ['yarn.lock', 'yarn'],
116
- ['bun.lock', 'bun'],
117
- ['bun.lockb', 'bun'],
118
- ['package-lock.json', 'npm'],
119
- ]
120
-
121
- for (const [lockfile, manager] of lockfiles) {
122
- if (existsSync(path.join(CURRENT_DIRECTORY, lockfile))) return manager
123
- }
124
-
125
- return 'npm'
126
- }
127
-
128
- async function readProjectPackage() {
129
- const packagePath = path.join(CURRENT_DIRECTORY, 'package.json')
130
- try {
131
- const content = await readFile(packagePath, 'utf8')
132
- return JSON.parse(content)
133
- } catch (error) {
134
- if (error instanceof SyntaxError) {
135
- throw new Error('Could not parse the project package.json.')
136
- }
137
- throw new Error('Run `istmx add` from a project folder with package.json.')
138
- }
139
- }
140
-
141
- function installedDependencies(projectPackage) {
142
- return {
143
- ...projectPackage.dependencies,
144
- ...projectPackage.devDependencies,
145
- ...projectPackage.optionalDependencies,
146
- }
147
- }
148
-
149
- function dependencyCommand(manager, dependencies) {
150
- return [manager, ...COMMANDS[manager], ...dependencies]
151
- }
152
-
153
- async function writeRegistryFile(sourceName, targetPath, overwrite) {
154
- const content = await readFile(
155
- path.join(REGISTRY_DIRECTORY, sourceName),
156
- 'utf8',
157
- )
158
- await mkdir(path.dirname(targetPath), { recursive: true })
159
-
160
- try {
161
- await access(targetPath, constants.F_OK)
162
- if (!overwrite) {
163
- console.log(
164
- `${muted('·')} Kept existing ${path.relative(CURRENT_DIRECTORY, targetPath)}`,
165
- )
166
- return false
167
- }
168
- } catch {
169
- // Target file does not exist yet.
170
- }
171
-
172
- await writeFile(targetPath, content, 'utf8')
173
- printSuccess(`Added ${path.relative(CURRENT_DIRECTORY, targetPath)}`)
174
- return true
175
- }
176
-
177
- async function writeRegistryDirectory(sourceName, targetPath, overwrite) {
178
- const sourcePath = path.join(REGISTRY_DIRECTORY, sourceName)
179
- const files = await readdir(sourcePath, { withFileTypes: true })
180
- for (const entry of files) {
181
- if (!entry.isFile()) continue
182
- await writeRegistryFile(
183
- path.join(sourceName, entry.name),
184
- path.join(targetPath, entry.name),
185
- overwrite,
186
- )
187
- }
188
- }
189
-
190
- function installDependencies(manager, dependencies) {
191
- if (dependencies.length === 0) {
192
- printSuccess('Dependencies are already present.')
193
- return true
194
- }
195
-
196
- const [command, ...args] = dependencyCommand(manager, dependencies)
197
- printStep(`Installing dependencies with ${manager}`)
198
- console.log(` ${muted(dependencies.join(' · '))}`)
199
- const result = spawnSync(command, args, {
200
- cwd: CURRENT_DIRECTORY,
201
- stdio: 'inherit',
202
- shell: process.platform === 'win32',
203
- })
204
-
205
- if (result.status === 0) {
206
- printSuccess('Dependencies installed.')
207
- return true
208
- }
209
-
210
- return false
211
- }
212
-
213
- async function addComponent(component, options) {
214
- const definition = COMPONENTS[component]
215
- if (!definition) {
216
- throw new Error(
217
- `Unknown component "${component}". Available components: ${Object.keys(COMPONENTS).join(', ')}. Run istmx --help to see available components.`,
218
- )
219
- }
220
- const componentDependencies = [
221
- ...new Set([...DEPENDENCIES, ...(definition.dependencies ?? [])]),
222
- ]
223
-
224
- const projectPackage = await readProjectPackage()
225
- const manager = detectPackageManager(projectPackage)
226
- printHeader()
227
- console.log(
228
- `${muted('Adding')} ${cyan(component)} ${muted('to your project')}\n`,
229
- )
230
- printStep('Writing editable source files')
231
- const componentPath = definition.directory
232
- ? path.join(
233
- CURRENT_DIRECTORY,
234
- 'components',
235
- definition.targetDirectory ?? component,
236
- )
237
- : path.join(CURRENT_DIRECTORY, 'components', 'ui', definition.fileName)
238
- const utilityPath = path.join(CURRENT_DIRECTORY, 'lib', 'utils.ts')
239
-
240
- if (definition.utility !== false) {
241
- await writeRegistryFile('utils.ts', utilityPath, options.overwrite)
242
- }
243
- if (definition.directory) {
244
- await writeRegistryDirectory(
245
- definition.directory,
246
- componentPath,
247
- options.overwrite,
248
- )
249
- } else {
250
- await writeRegistryFile(
251
- definition.fileName,
252
- componentPath,
253
- options.overwrite,
254
- )
255
- }
256
-
257
- if (options.noInstall) {
258
- const missing = componentDependencies.filter(
259
- (dependency) => !installedDependencies(projectPackage)[dependency],
260
- )
261
- if (missing.length > 0) {
262
- printStep('Install the required dependencies manually')
263
- console.log(` ${cyan(dependencyCommand(manager, missing).join(' '))}`)
264
- }
265
- printSuccess('Source files are ready.')
266
- return
267
- }
268
-
269
- const installed = installedDependencies(projectPackage)
270
- const missingDependencies = componentDependencies.filter(
271
- (dependency) => !installed[dependency],
272
- )
273
-
274
- if (!installDependencies(manager, missingDependencies)) {
275
- throw new Error(
276
- `Dependency installation failed. Run ${dependencyCommand(manager, missingDependencies).join(' ')} and try again.`,
277
- )
278
- }
279
-
280
- console.log(`\n${green('Done!')} ${component} is ready to edit.`)
281
- console.log(
282
- ` ${muted('Import from')} ${cyan(definition.importPath ?? (definition.directory ? `@/components/${definition.targetDirectory ?? component}` : `@/components/ui/${component}`))}`,
283
- )
284
- console.log(
285
- ` ${muted('Dependencies')} ${cyan(componentDependencies.join(', '))}\n`,
286
- )
287
- }
288
-
289
- const [command, ...argumentsList] = process.argv.slice(2)
290
- const component = argumentsList
291
- .filter((argument) => !argument.startsWith('--'))
292
- .join('-')
293
- .toLowerCase()
294
- const options = {
295
- noInstall: argumentsList.includes('--no-install'),
296
- overwrite: argumentsList.includes('--overwrite'),
297
- }
298
-
299
- if (command === '--help' || command === '-h' || !command) {
300
- printHelp()
301
- } else if (command === '--version' || command === '-v') {
302
- console.log(VERSION)
303
- } else if (command === 'add') {
304
- if (!component || component.startsWith('--')) {
305
- console.error('Choose a component name. Run `istmx --help` to see options.')
306
- process.exitCode = 1
307
- } else {
308
- addComponent(component, options).catch((error) => {
309
- console.error(`\n${red('✖')} ${error.message}`)
310
- process.exitCode = 1
311
- })
312
- }
313
- } else {
314
- console.error(
315
- `${red('✖')} Unknown command "${command}". Run istmx --help for usage.`,
316
- )
317
- process.exitCode = 1
318
- }
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
+ }