@blankways/ui 0.0.0-stage → 0.1.0-alpha.1
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/README.md +228 -2
- package/dist/cli/cli.options.d.ts +5 -0
- package/dist/cli/cli.options.js +53 -0
- package/dist/cli/cli.registry.d.ts +6 -0
- package/dist/cli/cli.registry.js +37 -0
- package/dist/cli/cli.types.d.ts +32 -0
- package/dist/cli/cli.types.js +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +47 -0
- package/dist/commands/add.command.d.ts +2 -0
- package/dist/commands/add.command.js +101 -0
- package/dist/commands/doctor.command.d.ts +3 -0
- package/dist/commands/doctor.command.js +92 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.js +6 -0
- package/dist/commands/init.command.d.ts +2 -0
- package/dist/commands/init.command.js +38 -0
- package/dist/commands/list.command.d.ts +2 -0
- package/dist/commands/list.command.js +54 -0
- package/dist/commands/meta.command.d.ts +1 -0
- package/dist/commands/meta.command.js +19 -0
- package/dist/commands/styles.command.d.ts +6 -0
- package/dist/commands/styles.command.js +68 -0
- package/dist/config/config.helpers.d.ts +7 -0
- package/dist/config/config.helpers.js +63 -0
- package/dist/config/framework.helpers.d.ts +3 -0
- package/dist/config/framework.helpers.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/constants/cli.constants.d.ts +9 -0
- package/dist/constants/cli.constants.js +15 -0
- package/dist/constants/framework.constants.d.ts +3 -0
- package/dist/constants/framework.constants.js +2 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +2 -0
- package/dist/doctor/checks/entries.check.d.ts +1 -0
- package/dist/doctor/checks/entries.check.js +21 -0
- package/dist/doctor/checks/icons.check.d.ts +1 -0
- package/dist/doctor/checks/icons.check.js +55 -0
- package/dist/doctor/checks/imports.check.d.ts +1 -0
- package/dist/doctor/checks/imports.check.js +45 -0
- package/dist/doctor/checks/index.d.ts +7 -0
- package/dist/doctor/checks/index.js +7 -0
- package/dist/doctor/checks/motion.check.d.ts +1 -0
- package/dist/doctor/checks/motion.check.js +66 -0
- package/dist/doctor/checks/peers.check.d.ts +1 -0
- package/dist/doctor/checks/peers.check.js +55 -0
- package/dist/doctor/checks/styles.check.d.ts +1 -0
- package/dist/doctor/checks/styles.check.js +45 -0
- package/dist/doctor/checks/themes.check.d.ts +1 -0
- package/dist/doctor/checks/themes.check.js +64 -0
- package/dist/doctor/doctor.helpers.d.ts +6 -0
- package/dist/doctor/doctor.helpers.js +39 -0
- package/dist/doctor/doctor.registry.d.ts +10 -0
- package/dist/doctor/doctor.registry.js +24 -0
- package/dist/doctor/doctor.types.d.ts +27 -0
- package/dist/doctor/doctor.types.js +1 -0
- package/dist/doctor/index.d.ts +3 -0
- package/dist/doctor/index.js +3 -0
- package/dist/errors/cli-error.d.ts +3 -0
- package/dist/errors/cli-error.js +6 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/helpers/args.helpers.d.ts +4 -0
- package/dist/helpers/args.helpers.js +75 -0
- package/dist/helpers/help.helpers.d.ts +1 -0
- package/dist/helpers/help.helpers.js +30 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +5 -0
- package/dist/helpers/package.helpers.d.ts +2 -0
- package/dist/helpers/package.helpers.js +12 -0
- package/dist/helpers/path.helpers.d.ts +3 -0
- package/dist/helpers/path.helpers.js +15 -0
- package/dist/helpers/styles.helpers.d.ts +21 -0
- package/dist/helpers/styles.helpers.js +164 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/index.js +1 -0
- package/dist/registry/registry.helpers.d.ts +22 -0
- package/dist/registry/registry.helpers.js +328 -0
- package/dist/registry-data/README.md +71 -0
- package/dist/registry-data/avatar/Avatar.tsx +64 -0
- package/dist/registry-data/avatar/component.json +30 -0
- package/dist/registry-data/avatar/index.ts +1 -0
- package/dist/registry-data/badge/Badge.tsx +76 -0
- package/dist/registry-data/badge/component.json +30 -0
- package/dist/registry-data/badge/index.ts +1 -0
- package/dist/registry-data/brand-logo/BrandLogo.tsx +24 -0
- package/dist/registry-data/brand-logo/component.json +26 -0
- package/dist/registry-data/brand-logo/index.ts +1 -0
- package/dist/registry-data/button/Button.tsx +76 -0
- package/dist/registry-data/button/component.json +33 -0
- package/dist/registry-data/button/index.ts +1 -0
- package/dist/registry-data/button-link/ButtonLink.tsx +83 -0
- package/dist/registry-data/button-link/component.json +33 -0
- package/dist/registry-data/button-link/index.ts +5 -0
- package/dist/registry-data/button-styles/component.json +19 -0
- package/dist/registry-data/button-styles/index.ts +45 -0
- package/dist/registry-data/cn/cn.ts +6 -0
- package/dist/registry-data/cn/component.json +16 -0
- package/dist/registry-data/confirm-dialog/ConfirmDialog.tsx +134 -0
- package/dist/registry-data/confirm-dialog/component.json +34 -0
- package/dist/registry-data/confirm-dialog/index.ts +1 -0
- package/dist/registry-data/container/Container.tsx +22 -0
- package/dist/registry-data/container/component.json +28 -0
- package/dist/registry-data/container/index.ts +1 -0
- package/dist/registry-data/cursor-glow/CursorGlow.tsx +29 -0
- package/dist/registry-data/cursor-glow/component.json +28 -0
- package/dist/registry-data/cursor-glow/index.ts +1 -0
- package/dist/registry-data/dropdown-menu/DropdownMenu.tsx +157 -0
- package/dist/registry-data/dropdown-menu/component.json +34 -0
- package/dist/registry-data/dropdown-menu/index.ts +5 -0
- package/dist/registry-data/empty-state/EmptyState.tsx +92 -0
- package/dist/registry-data/empty-state/component.json +30 -0
- package/dist/registry-data/empty-state/index.ts +5 -0
- package/dist/registry-data/eyebrow/Eyebrow.tsx +68 -0
- package/dist/registry-data/eyebrow/component.json +30 -0
- package/dist/registry-data/eyebrow/index.ts +1 -0
- package/dist/registry-data/field-styles/component.json +19 -0
- package/dist/registry-data/field-styles/index.ts +42 -0
- package/dist/registry-data/form-dialog/FormDialog.tsx +128 -0
- package/dist/registry-data/form-dialog/component.json +34 -0
- package/dist/registry-data/form-dialog/index.ts +1 -0
- package/dist/registry-data/icons/component.json +22 -0
- package/dist/registry-data/icons/index.ts +21 -0
- package/dist/registry-data/icons-form/component.json +17 -0
- package/dist/registry-data/icons-form/index.ts +1 -0
- package/dist/registry-data/icons-sidebar/component.json +17 -0
- package/dist/registry-data/icons-sidebar/index.ts +1 -0
- package/dist/registry-data/icons-theme/component.json +17 -0
- package/dist/registry-data/icons-theme/index.ts +1 -0
- package/dist/registry-data/icons-toast/component.json +17 -0
- package/dist/registry-data/icons-toast/index.ts +1 -0
- package/dist/registry-data/info-dialog/InfoDialog.tsx +119 -0
- package/dist/registry-data/info-dialog/component.json +36 -0
- package/dist/registry-data/info-dialog/index.ts +1 -0
- package/dist/registry-data/input/Input.tsx +96 -0
- package/dist/registry-data/input/component.json +33 -0
- package/dist/registry-data/input/index.ts +1 -0
- package/dist/registry-data/multi-combobox/MultiCombobox.tsx +205 -0
- package/dist/registry-data/multi-combobox/component.json +35 -0
- package/dist/registry-data/multi-combobox/index.ts +5 -0
- package/dist/registry-data/remote-provider/RemoteProvider.tsx +8 -0
- package/dist/registry-data/remote-provider/component.json +25 -0
- package/dist/registry-data/remote-provider/index.ts +3 -0
- package/dist/registry-data/reveal/Reveal.tsx +22 -0
- package/dist/registry-data/reveal/component.json +30 -0
- package/dist/registry-data/reveal/index.ts +1 -0
- package/dist/registry-data/section/Section.tsx +80 -0
- package/dist/registry-data/section/component.json +30 -0
- package/dist/registry-data/section/index.ts +1 -0
- package/dist/registry-data/section-heading/SectionHeading.tsx +105 -0
- package/dist/registry-data/section-heading/component.json +32 -0
- package/dist/registry-data/section-heading/index.ts +1 -0
- package/dist/registry-data/select/Select.tsx +197 -0
- package/dist/registry-data/select/component.json +34 -0
- package/dist/registry-data/select/index.ts +1 -0
- package/dist/registry-data/sidebar/Sidebar.tsx +432 -0
- package/dist/registry-data/sidebar/SidebarCollapsible.tsx +77 -0
- package/dist/registry-data/sidebar/SidebarParts.tsx +373 -0
- package/dist/registry-data/sidebar/component.json +47 -0
- package/dist/registry-data/sidebar/index.ts +4 -0
- package/dist/registry-data/sidebar/useSidebar.ts +29 -0
- package/dist/registry-data/styles-base/component.json +19 -0
- package/dist/registry-data/styles-base/index.css +67 -0
- package/dist/registry-data/styles-components/component.json +19 -0
- package/dist/registry-data/styles-components/index.css +30 -0
- package/dist/registry-data/styles-motion/component.json +20 -0
- package/dist/registry-data/styles-motion/index.css +381 -0
- package/dist/registry-data/styles-tokens/component.json +17 -0
- package/dist/registry-data/styles-tokens/index.css +77 -0
- package/dist/registry-data/styles-utilities/component.json +19 -0
- package/dist/registry-data/styles-utilities/index.css +29 -0
- package/dist/registry-data/switch/Switch.tsx +91 -0
- package/dist/registry-data/switch/component.json +34 -0
- package/dist/registry-data/switch/index.ts +1 -0
- package/dist/registry-data/tabs/Tabs.tsx +226 -0
- package/dist/registry-data/tabs/component.json +32 -0
- package/dist/registry-data/tabs/index.ts +1 -0
- package/dist/registry-data/textarea/Textarea.tsx +94 -0
- package/dist/registry-data/textarea/component.json +33 -0
- package/dist/registry-data/textarea/index.ts +1 -0
- package/dist/registry-data/theme-core/component.json +17 -0
- package/dist/registry-data/theme-core/theme.ts +84 -0
- package/dist/registry-data/theme-dark/component.json +19 -0
- package/dist/registry-data/theme-dark/index.ts +7 -0
- package/dist/registry-data/theme-light/component.json +19 -0
- package/dist/registry-data/theme-light/index.ts +7 -0
- package/dist/registry-data/theme-provider/ThemeContext.tsx +177 -0
- package/dist/registry-data/theme-provider/component.json +30 -0
- package/dist/registry-data/theme-provider/index.ts +2 -0
- package/dist/registry-data/theme-selector/ThemeSelector.tsx +269 -0
- package/dist/registry-data/theme-selector/component.json +35 -0
- package/dist/registry-data/theme-selector/selector.ts +1 -0
- package/dist/registry-data/theme-system/component.json +19 -0
- package/dist/registry-data/theme-system/index.ts +7 -0
- package/dist/registry-data/theme-toggle/ThemeToggle.tsx +71 -0
- package/dist/registry-data/theme-toggle/component.json +31 -0
- package/dist/registry-data/theme-toggle/toggle.ts +1 -0
- package/dist/registry-data/toast/Toast.tsx +260 -0
- package/dist/registry-data/toast/ToastTypeIcon.tsx +83 -0
- package/dist/registry-data/toast/component.json +43 -0
- package/dist/registry-data/toast/index.ts +3 -0
- package/dist/registry-data/toast/useToast.ts +47 -0
- package/dist/types/cli.types.d.ts +6 -0
- package/dist/types/cli.types.js +1 -0
- package/dist/types/config.types.d.ts +41 -0
- package/dist/types/config.types.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/registry.types.d.ts +37 -0
- package/dist/types/registry.types.js +1 -0
- package/package.json +35 -3
package/README.md
CHANGED
|
@@ -1,3 +1,229 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @blankways/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
CLI que copia componentes de UI abiertos, iconos, themes y estilos desde el registro incluido en el paquete directamente a tu proyecto. No necesita servidor: los archivos viajan dentro del paquete y pasan a ser tuyos.
|
|
4
|
+
|
|
5
|
+
El CLI es independiente de React: no lo importa ni lo necesita para compilarse o ejecutarse. El registro contiene plantillas React que se copian al proyecto de destino; la alternativa se selecciona durante `init`.
|
|
6
|
+
|
|
7
|
+
## Uso
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add -D @blankways/ui
|
|
11
|
+
|
|
12
|
+
pnpm exec ui init --framework react
|
|
13
|
+
pnpm exec ui add button input
|
|
14
|
+
pnpm exec ui add theme-provider theme-toggle theme-selector
|
|
15
|
+
pnpm exec ui add icons-toast toast
|
|
16
|
+
pnpm exec ui add styles-tokens styles-base styles-components styles-utilities
|
|
17
|
+
pnpm exec ui styles link
|
|
18
|
+
pnpm exec ui doctor
|
|
19
|
+
pnpm exec ui list
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
El bin es `ui`.
|
|
23
|
+
|
|
24
|
+
`init` escribe el framework elegido en `components.json`. Las entradas del registro están etiquetadas con ese framework, así que `add`, `list` y `doctor` solo ven las alternativas instalables para el proyecto:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"componentsDir": "ui",
|
|
29
|
+
"framework": "react",
|
|
30
|
+
"overwrite": false
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Alternativas disponibles: `react`. `--variant` es un alias de `--framework`.
|
|
35
|
+
|
|
36
|
+
`add` resuelve dependencias del registry automáticamente, por ejemplo `button` instala `ui/components/button/Button.tsx`, `ui/styles/button-styles.ts` y el helper interno `ui/internals/cn.ts`. Cuando agregas entradas `style`, además genera `ui/styles/index.css` y conecta su import en el CSS global del proyecto.
|
|
37
|
+
|
|
38
|
+
`styles link` hace esa conexión cuando quieras repetirla, y `doctor` valida imports relativos, iconos, themes, estilos y peers instalados.
|
|
39
|
+
|
|
40
|
+
## Registro
|
|
41
|
+
|
|
42
|
+
El registro está agrupado por tipo y cada entrada puede instalarse por separado:
|
|
43
|
+
|
|
44
|
+
| Tipo | Entradas de ejemplo |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `component` | `button`, `input`, `select`, `tabs`, `toast`, `sidebar` |
|
|
47
|
+
| `icon` | `icons`, `icons-theme`, `icons-form`, `icons-sidebar`, `icons-toast` |
|
|
48
|
+
| `theme` | `theme-core`, `theme-provider`, `theme-light`, `theme-dark`, `theme-system`, `theme-toggle`, `theme-selector` |
|
|
49
|
+
| `style` | `styles-tokens`, `styles-base`, `styles-components`, `styles-utilities` |
|
|
50
|
+
| `utility` | `button-styles`, `field-styles` |
|
|
51
|
+
|
|
52
|
+
Los themes son strings. `light` y `dark` se registran automáticamente, pero puedes añadir otros:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
<ThemeProvider themes={['light', 'dark', 'sepia']}>
|
|
56
|
+
<App />
|
|
57
|
+
</ThemeProvider>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`system` es una preferencia que se resuelve a uno de los themes registrados.
|
|
61
|
+
|
|
62
|
+
Lista todo o filtra:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm exec ui list
|
|
66
|
+
pnpm exec ui list --kind icon
|
|
67
|
+
pnpm exec ui list --kind theme
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Opciones:
|
|
71
|
+
|
|
72
|
+
- `--cwd <path>`: raíz del proyecto.
|
|
73
|
+
- `--components-dir <path>`: sobrescribe `componentsDir`.
|
|
74
|
+
- `--framework <name>`: alternativa de UI para `init` (ahora mismo `react`; alias: `--variant`).
|
|
75
|
+
- `--global-css <path>`: CSS global donde se conecta `ui/styles/index.css` (se detecta solo si se omite).
|
|
76
|
+
- `--kind <kind>`: filtra `list` o `add` por tipo.
|
|
77
|
+
- `--force`: sobrescribe archivos existentes o `components.json`.
|
|
78
|
+
- `--dry-run`: muestra qué se copiaría sin escribir.
|
|
79
|
+
- `--all`: agrega todas las entradas (combina con `--kind`).
|
|
80
|
+
- `--no-deps`: no copia dependencias del registry.
|
|
81
|
+
- `--no-import`: no conecta los estilos después de `add`.
|
|
82
|
+
|
|
83
|
+
Después de `add`, el CLI indica los paquetes peer necesarios para las plantillas copiadas (declarados en cada `component.json` y verificados por `doctor`). Estos paquetes no son dependencias del CLI:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pnpm add react react-dom @blankways/state @blankways/state-react@0.1.0-alpha.1 lucide-react tailwindcss
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Estilos
|
|
90
|
+
|
|
91
|
+
`add styles-*` y `styles link` generan un barrel ordenado:
|
|
92
|
+
|
|
93
|
+
```css
|
|
94
|
+
/* ui/styles/index.css */
|
|
95
|
+
@import './tokens.css';
|
|
96
|
+
@import './base.css';
|
|
97
|
+
@import './components.css';
|
|
98
|
+
@import './utilities.css';
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
y añaden al CSS global una línea como:
|
|
102
|
+
|
|
103
|
+
```css
|
|
104
|
+
@import './ui/styles/index.css';
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Se inserta justo después de `@import "tailwindcss";`. Si no hay un CSS global reconocido, el CLI lo indica y puedes pasar `--global-css src/app/globals.css`.
|
|
108
|
+
|
|
109
|
+
## Doctor
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pnpm exec ui doctor
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```text
|
|
116
|
+
ui doctor
|
|
117
|
+
|
|
118
|
+
OK imports: 42 resolved
|
|
119
|
+
OK icons: 8 imports checked
|
|
120
|
+
OK themes: 2 found (light, dark)
|
|
121
|
+
OK entries: 12 detected
|
|
122
|
+
OK peers: 6/6 installed
|
|
123
|
+
|
|
124
|
+
Everything looks good.
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`doctor` avisa de imports relativos rotos, iconos no exportados, themes sin bloque CSS, falta de `ui/styles/index.css` o de su import, y peers ausentes en `package.json`. Los errores devuelven exit code 1; los avisos no.
|
|
128
|
+
|
|
129
|
+
Los checks son plug-ins. `doctor` solo orquesta el registro y cada área declara el suyo en `source/doctor/checks/`. Puedes añadir uno propio:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { registerDoctorCheck } from '@blankways/ui'
|
|
133
|
+
|
|
134
|
+
registerDoctorCheck({
|
|
135
|
+
id: 'mi-regla',
|
|
136
|
+
async run({ componentsDir }) {
|
|
137
|
+
return {
|
|
138
|
+
summary: 'checked',
|
|
139
|
+
problems: []
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`run` recibe el contexto (`cwd`, `componentsDir`, `files`, `sourceFiles`, `globalCss`), devuelve `{ summary, problems }` o `null` para omitir el check. Un problema con `level: 'error'` hace que `doctor` termine con exit code 1.
|
|
146
|
+
|
|
147
|
+
## Operaciones conectadas
|
|
148
|
+
|
|
149
|
+
Los comandos tampoco viven en un `switch`: cada operación se registra con `registerCliCommand` en `source/commands/` y el CLI los descubre. La ayuda y las opciones también se generan desde el registro.
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import {
|
|
153
|
+
registerCliCommand,
|
|
154
|
+
registerDoctorCheck,
|
|
155
|
+
listRegistryItems
|
|
156
|
+
} from '@blankways/ui'
|
|
157
|
+
|
|
158
|
+
registerCliCommand({
|
|
159
|
+
name: 'mis-icons',
|
|
160
|
+
description: 'Lista los iconos disponibles',
|
|
161
|
+
order: 60,
|
|
162
|
+
run: async () => {
|
|
163
|
+
const items = await listRegistryItems()
|
|
164
|
+
console.log(items.filter(item => item.kind === 'icon').map(item => item.name).join('\n'))
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
registerDoctorCheck({
|
|
169
|
+
id: 'mis-icons',
|
|
170
|
+
run: () => ({ summary: 'checked', problems: [] })
|
|
171
|
+
})
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`run` recibe un `CliContext` con `cwd`, `componentsDir`, `globalCss`, `kind`, `names`, `flags`, `force`, `dryRun`, `all`, `noDeps` y `noImport`.
|
|
175
|
+
|
|
176
|
+
Los datos vienen de dos lados:
|
|
177
|
+
|
|
178
|
+
- **Internos**: los manifiestos `registry/*/component.json` y sus archivos fuente.
|
|
179
|
+
- **Expuestos**: el API público del paquete (`listRegistryItems`, `registerCliCommand`, `registerDoctorCheck`, `getCliOptions`, etc.).
|
|
180
|
+
|
|
181
|
+
Así una operación nueva no necesita tocar el CLI: se conecta al registro de comandos, puede registrar sus checks en `doctor` y consume los mismos datos que las operaciones incluidas.
|
|
182
|
+
|
|
183
|
+
## Configuración
|
|
184
|
+
|
|
185
|
+
`init` crea `components.json` con el framework seleccionado:
|
|
186
|
+
|
|
187
|
+
```json
|
|
188
|
+
{
|
|
189
|
+
"componentsDir": "ui",
|
|
190
|
+
"framework": "react",
|
|
191
|
+
"overwrite": false
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Layout de archivos
|
|
196
|
+
|
|
197
|
+
Los archivos se copian a `ui/` con rutas normalizadas. Los componentes viven dentro de `ui/components/`, mientras que iconos, themes, estilos y helpers internos conservan sus carpetas propias:
|
|
198
|
+
|
|
199
|
+
```text
|
|
200
|
+
ui/
|
|
201
|
+
components/button/Button.tsx
|
|
202
|
+
components/button/index.ts
|
|
203
|
+
components/sidebar/Sidebar.tsx
|
|
204
|
+
icons/index.ts
|
|
205
|
+
icons/theme.ts
|
|
206
|
+
styles/tokens.css
|
|
207
|
+
styles/button-styles.ts
|
|
208
|
+
styles/field-styles.ts
|
|
209
|
+
themes/theme.ts
|
|
210
|
+
themes/ThemeContext.tsx
|
|
211
|
+
internals/cn.ts
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Cada entrada define `target` en su `component.json`, así que las rutas son estables aunque el nombre de entrada sea distinto (por ejemplo `icons-theme` → `ui/icons/theme.ts`). Los imports relativos de los componentes ya apuntan a esta estructura (por ejemplo `../../internals/cn.js` desde `ui/components/button/`).
|
|
215
|
+
|
|
216
|
+
`cn` es una entrada interna (`hidden: true`): no aparece en `list`, no se puede pedir con `add` y se instala automáticamente como dependencia en `ui/internals/cn.ts`. Los helpers `button-styles` y `field-styles` viven en `ui/styles/`.
|
|
217
|
+
|
|
218
|
+
## Desarrollo
|
|
219
|
+
|
|
220
|
+
Este es un proyecto independiente, con su propio `package.json` y toolchain:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
pnpm install
|
|
224
|
+
pnpm typecheck
|
|
225
|
+
pnpm test
|
|
226
|
+
pnpm build
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`typecheck` comprueba `source/` con `tsc` y valida el registro sin compilar las plantillas React (manifiestos, rutas, dependencias e imports relativos). El build copia `registry/` dentro de `dist/registry-data/`, así que la publicación solo necesita `files: ["dist"]` y el CLI sigue encontrando las entradas. npm siempre incluye además `package.json` y `README.md`, que no se pueden excluir.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const CLI_OPTIONS = [
|
|
2
|
+
{
|
|
3
|
+
flag: '--cwd <path>',
|
|
4
|
+
description: 'Project root (defaults to the current directory)'
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
flag: '--components-dir <path>',
|
|
8
|
+
description: 'Override the configured root (default ui from components.json)'
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
flag: '--global-css <path>',
|
|
12
|
+
description: 'Global stylesheet to connect (auto-detected when omitted)'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
flag: '--framework <name>',
|
|
16
|
+
description: 'UI framework for init (currently: react; alias: --variant)'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
flag: '--kind <kind>',
|
|
20
|
+
description: 'Filter by: component, icon, theme, style, utility'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
flag: '--force',
|
|
24
|
+
description: 'Overwrite existing files or components.json'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
flag: '--dry-run',
|
|
28
|
+
description: 'Show what would change without writing files'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
flag: '--all',
|
|
32
|
+
description: 'Add every entry (combine with --kind to narrow it)'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
flag: '--no-deps',
|
|
36
|
+
description: 'Do not copy registry dependencies'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
flag: '--no-import',
|
|
40
|
+
description: 'Do not link styles after add'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
flag: '-h, --help',
|
|
44
|
+
description: 'Show this help'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
flag: '-v, --version',
|
|
48
|
+
description: 'Show the CLI version'
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
export function getCliOptions() {
|
|
52
|
+
return [...CLI_OPTIONS];
|
|
53
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CliCommand, CliRegistry } from './cli.types.js';
|
|
2
|
+
export declare function createCliRegistry(): CliRegistry;
|
|
3
|
+
export declare const cliRegistry: CliRegistry;
|
|
4
|
+
export declare function registerCliCommand(command: CliCommand): void;
|
|
5
|
+
export declare function getCliCommands(): readonly CliCommand[];
|
|
6
|
+
export declare function resolveCliCommand(name: string): CliCommand | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function createCliRegistry() {
|
|
2
|
+
const commands = [];
|
|
3
|
+
function names(command) {
|
|
4
|
+
return [command.name, ...(command.aliases ?? [])];
|
|
5
|
+
}
|
|
6
|
+
function assertAvailable(command) {
|
|
7
|
+
const taken = names(command).filter(name => commands.some(existing => names(existing).includes(name)));
|
|
8
|
+
if (taken.length > 0) {
|
|
9
|
+
throw new Error(`CLI command "${taken.join(', ')}" is already registered.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
register(command) {
|
|
14
|
+
assertAvailable(command);
|
|
15
|
+
commands.push(command);
|
|
16
|
+
},
|
|
17
|
+
list() {
|
|
18
|
+
return [...commands];
|
|
19
|
+
},
|
|
20
|
+
resolve(name) {
|
|
21
|
+
return commands.find(command => names(command).includes(name)) ?? null;
|
|
22
|
+
},
|
|
23
|
+
clear() {
|
|
24
|
+
commands.length = 0;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export const cliRegistry = createCliRegistry();
|
|
29
|
+
export function registerCliCommand(command) {
|
|
30
|
+
cliRegistry.register(command);
|
|
31
|
+
}
|
|
32
|
+
export function getCliCommands() {
|
|
33
|
+
return cliRegistry.list();
|
|
34
|
+
}
|
|
35
|
+
export function resolveCliCommand(name) {
|
|
36
|
+
return cliRegistry.resolve(name);
|
|
37
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { FlagValue } from '../types/cli.types.js';
|
|
2
|
+
export type CliContext = {
|
|
3
|
+
cwd?: string;
|
|
4
|
+
componentsDir?: string;
|
|
5
|
+
globalCss?: string;
|
|
6
|
+
kind?: string;
|
|
7
|
+
framework?: string;
|
|
8
|
+
variant?: string;
|
|
9
|
+
names: string[];
|
|
10
|
+
flags: Record<string, FlagValue>;
|
|
11
|
+
force: boolean;
|
|
12
|
+
dryRun: boolean;
|
|
13
|
+
all: boolean;
|
|
14
|
+
noDeps: boolean;
|
|
15
|
+
noImport: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type CliCommand = {
|
|
18
|
+
name: string;
|
|
19
|
+
aliases?: string[];
|
|
20
|
+
description: string;
|
|
21
|
+
usage?: string;
|
|
22
|
+
order?: number;
|
|
23
|
+
examples?: string[];
|
|
24
|
+
hidden?: boolean;
|
|
25
|
+
run(context: CliContext): Promise<void> | void;
|
|
26
|
+
};
|
|
27
|
+
export type CliRegistry = {
|
|
28
|
+
register(command: CliCommand): void;
|
|
29
|
+
list(): readonly CliCommand[];
|
|
30
|
+
resolve(name: string): CliCommand | null;
|
|
31
|
+
clear(): void;
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import './commands/index.js';
|
|
3
|
+
import { resolveCliCommand } from './cli/cli.registry.js';
|
|
4
|
+
import { CLI_NAME } from './constants/index.js';
|
|
5
|
+
import { CliError } from './errors/index.js';
|
|
6
|
+
import { getStringFlag, isFlagEnabled, parseArgs, printHelp } from './helpers/index.js';
|
|
7
|
+
import { getPackageVersion } from './helpers/package.helpers.js';
|
|
8
|
+
async function main() {
|
|
9
|
+
const args = parseArgs(process.argv.slice(2));
|
|
10
|
+
if (isFlagEnabled(args.flags, 'help')) {
|
|
11
|
+
printHelp();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (isFlagEnabled(args.flags, 'version')) {
|
|
15
|
+
console.log(await getPackageVersion());
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!args.command) {
|
|
19
|
+
printHelp();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const command = resolveCliCommand(args.command);
|
|
23
|
+
if (!command) {
|
|
24
|
+
throw new CliError(`Unknown command "${args.command}". Run "${CLI_NAME} --help".`);
|
|
25
|
+
}
|
|
26
|
+
const context = {
|
|
27
|
+
cwd: getStringFlag(args.flags, 'cwd'),
|
|
28
|
+
componentsDir: getStringFlag(args.flags, 'componentsDir'),
|
|
29
|
+
globalCss: getStringFlag(args.flags, 'globalCss'),
|
|
30
|
+
kind: getStringFlag(args.flags, 'kind'),
|
|
31
|
+
framework: getStringFlag(args.flags, 'framework'),
|
|
32
|
+
variant: getStringFlag(args.flags, 'variant'),
|
|
33
|
+
names: args.names,
|
|
34
|
+
flags: args.flags,
|
|
35
|
+
force: isFlagEnabled(args.flags, 'force'),
|
|
36
|
+
dryRun: isFlagEnabled(args.flags, 'dryRun'),
|
|
37
|
+
all: isFlagEnabled(args.flags, 'all'),
|
|
38
|
+
noDeps: isFlagEnabled(args.flags, 'noDeps'),
|
|
39
|
+
noImport: isFlagEnabled(args.flags, 'noImport')
|
|
40
|
+
};
|
|
41
|
+
await command.run(context);
|
|
42
|
+
}
|
|
43
|
+
main().catch(error => {
|
|
44
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
45
|
+
console.error(`${CLI_NAME}: ${message}`);
|
|
46
|
+
process.exitCode = 1;
|
|
47
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { mkdir } from 'node:fs/promises';
|
|
2
|
+
import { basename, resolve } from 'node:path';
|
|
3
|
+
import { registerCliCommand } from '../cli/cli.registry.js';
|
|
4
|
+
import { readConfig, resolveComponentsDir } from '../config/index.js';
|
|
5
|
+
import { CLI_NAME } from '../constants/index.js';
|
|
6
|
+
import { CliError } from '../errors/index.js';
|
|
7
|
+
import { toDisplayPath } from '../helpers/path.helpers.js';
|
|
8
|
+
import { syncStyles } from '../helpers/styles.helpers.js';
|
|
9
|
+
import { copyRegistryItem, listRegistryItems, resolveSelectedComponents } from '../registry/index.js';
|
|
10
|
+
import { printStylesSync } from './styles.command.js';
|
|
11
|
+
export async function addCommand(options) {
|
|
12
|
+
const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
|
|
13
|
+
const config = await readConfig(cwd);
|
|
14
|
+
if (!config) {
|
|
15
|
+
throw new CliError(`components.json not found. Run "${CLI_NAME} init" first.`);
|
|
16
|
+
}
|
|
17
|
+
const componentsDir = resolveComponentsDir(cwd, config, options.componentsDir);
|
|
18
|
+
const items = await resolveSelectedComponents(options.names, Boolean(options.all), {
|
|
19
|
+
kind: options.kind,
|
|
20
|
+
framework: config.framework,
|
|
21
|
+
noDeps: options.noDeps
|
|
22
|
+
});
|
|
23
|
+
const force = Boolean(options.force || config.overwrite);
|
|
24
|
+
const dryRun = Boolean(options.dryRun);
|
|
25
|
+
if (!dryRun)
|
|
26
|
+
await mkdir(componentsDir, { recursive: true });
|
|
27
|
+
let copied = 0;
|
|
28
|
+
let skipped = 0;
|
|
29
|
+
let planned = 0;
|
|
30
|
+
for (const item of items) {
|
|
31
|
+
const result = await copyRegistryItem(item, componentsDir, { cwd, force, dryRun });
|
|
32
|
+
copied += result.copied.length;
|
|
33
|
+
skipped += result.skipped.length;
|
|
34
|
+
planned += result.planned.length;
|
|
35
|
+
const label = item.requested
|
|
36
|
+
? dryRun
|
|
37
|
+
? 'Would add'
|
|
38
|
+
: 'Added'
|
|
39
|
+
: dryRun
|
|
40
|
+
? 'Would add dependency'
|
|
41
|
+
: 'Added dependency';
|
|
42
|
+
const files = [...result.copied, ...result.skipped, ...result.planned];
|
|
43
|
+
if (files.length > 0)
|
|
44
|
+
console.log(`${label} ${item.name}: ${files.join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
const plannedStyles = items
|
|
47
|
+
.filter(item => item.kind === 'style')
|
|
48
|
+
.flatMap(item => item.files.map(file => basename(file.target)));
|
|
49
|
+
const linkStyles = async () => {
|
|
50
|
+
if (options.noImport || plannedStyles.length === 0)
|
|
51
|
+
return;
|
|
52
|
+
const result = await syncStyles({
|
|
53
|
+
cwd,
|
|
54
|
+
componentsDir,
|
|
55
|
+
globalCss: options.globalCss,
|
|
56
|
+
dryRun,
|
|
57
|
+
plannedStyles
|
|
58
|
+
});
|
|
59
|
+
printStylesSync(result, cwd, dryRun);
|
|
60
|
+
};
|
|
61
|
+
if (dryRun) {
|
|
62
|
+
console.log(`\nDry run: ${planned} file(s) would be copied.`);
|
|
63
|
+
await linkStyles();
|
|
64
|
+
await printEducation(items, config.framework);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (copied === 0 && skipped === 0) {
|
|
68
|
+
console.log('No files were copied.');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log(`\nDone: ${copied} copied, ${skipped} skipped → ${toDisplayPath(cwd, componentsDir)}/`);
|
|
72
|
+
await linkStyles();
|
|
73
|
+
await printEducation(items, config.framework);
|
|
74
|
+
}
|
|
75
|
+
async function printEducation(items, framework) {
|
|
76
|
+
const peers = Array.from(new Set(items.flatMap(item => item.peers)));
|
|
77
|
+
if (peers.length > 0) {
|
|
78
|
+
console.log(`\nPeer packages: ${peers.join(', ')}`);
|
|
79
|
+
console.log(`Install them with: pnpm add ${peers.join(' ')}`);
|
|
80
|
+
}
|
|
81
|
+
const installed = new Set(items.map(item => item.name));
|
|
82
|
+
const available = new Set((await listRegistryItems({ framework }))
|
|
83
|
+
.filter(item => !item.hidden)
|
|
84
|
+
.map(item => item.name));
|
|
85
|
+
const suggestions = Array.from(new Set(items.flatMap(item => item.suggestions))).filter(name => available.has(name) && !installed.has(name));
|
|
86
|
+
if (suggestions.length > 0) {
|
|
87
|
+
console.log(`\nRecommended styles: pnpm exec ${CLI_NAME} add ${suggestions.join(' ')}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
registerCliCommand({
|
|
91
|
+
name: 'add',
|
|
92
|
+
description: 'Copy registry entries, link styles and show peers',
|
|
93
|
+
usage: 'add <entry...> [options]',
|
|
94
|
+
order: 20,
|
|
95
|
+
examples: [
|
|
96
|
+
`${CLI_NAME} add button input`,
|
|
97
|
+
`${CLI_NAME} add styles-tokens styles-base styles-motion`,
|
|
98
|
+
`${CLI_NAME} add button --dry-run`
|
|
99
|
+
],
|
|
100
|
+
run: context => addCommand(context)
|
|
101
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { readdir } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { registerCliCommand } from '../cli/cli.registry.js';
|
|
4
|
+
import { readConfig, resolveComponentsDir } from '../config/index.js';
|
|
5
|
+
import { CLI_NAME } from '../constants/index.js';
|
|
6
|
+
import { CliError } from '../errors/index.js';
|
|
7
|
+
import { toDisplayPath } from '../helpers/path.helpers.js';
|
|
8
|
+
import '../doctor/index.js';
|
|
9
|
+
import { getDoctorChecks } from '../doctor/doctor.registry.js';
|
|
10
|
+
async function walkFiles(directory) {
|
|
11
|
+
const files = [];
|
|
12
|
+
let entries;
|
|
13
|
+
try {
|
|
14
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return files;
|
|
18
|
+
}
|
|
19
|
+
for (const entry of entries) {
|
|
20
|
+
const fullPath = join(directory, entry.name);
|
|
21
|
+
if (entry.isDirectory()) {
|
|
22
|
+
files.push(...(await walkFiles(fullPath)));
|
|
23
|
+
}
|
|
24
|
+
else if (entry.isFile()) {
|
|
25
|
+
files.push(fullPath);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return files;
|
|
29
|
+
}
|
|
30
|
+
function status(level) {
|
|
31
|
+
if (level === 'error')
|
|
32
|
+
return 'ERROR';
|
|
33
|
+
return level === 'warn' ? 'WARN ' : 'OK ';
|
|
34
|
+
}
|
|
35
|
+
function reportLevel(problems) {
|
|
36
|
+
if (!problems || problems.length === 0)
|
|
37
|
+
return 'ok';
|
|
38
|
+
return problems.some(problem => problem.level === 'error') ? 'error' : 'warn';
|
|
39
|
+
}
|
|
40
|
+
export async function doctorCommand(options = {}) {
|
|
41
|
+
const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
|
|
42
|
+
const config = await readConfig(cwd);
|
|
43
|
+
if (!config) {
|
|
44
|
+
throw new CliError(`components.json not found. Run "${CLI_NAME} init" first.`);
|
|
45
|
+
}
|
|
46
|
+
const componentsDir = resolveComponentsDir(cwd, config, options.componentsDir);
|
|
47
|
+
const files = await walkFiles(componentsDir);
|
|
48
|
+
const reports = [];
|
|
49
|
+
for (const check of getDoctorChecks()) {
|
|
50
|
+
const result = await check.run({
|
|
51
|
+
cwd,
|
|
52
|
+
componentsDir,
|
|
53
|
+
displayDir: toDisplayPath(cwd, componentsDir),
|
|
54
|
+
files,
|
|
55
|
+
sourceFiles: files.filter(file => /\.tsx?$/.test(file)),
|
|
56
|
+
framework: config.framework,
|
|
57
|
+
globalCss: options.globalCss
|
|
58
|
+
});
|
|
59
|
+
if (result)
|
|
60
|
+
reports.push({ id: check.id, result });
|
|
61
|
+
}
|
|
62
|
+
console.log(`${CLI_NAME} doctor\n`);
|
|
63
|
+
for (const report of reports) {
|
|
64
|
+
if (!report.result.summary)
|
|
65
|
+
continue;
|
|
66
|
+
console.log(`${status(reportLevel(report.result.problems))} ${report.id}: ${report.result.summary}`);
|
|
67
|
+
}
|
|
68
|
+
const problems = reports.flatMap(report => (report.result.problems ?? []).map(problem => ({ area: report.id, problem })));
|
|
69
|
+
if (problems.length === 0) {
|
|
70
|
+
console.log('\nEverything looks good.');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
console.log('');
|
|
74
|
+
for (const { area, problem } of problems) {
|
|
75
|
+
console.log(`${status(problem.level)} ${area}: ${problem.message}`);
|
|
76
|
+
}
|
|
77
|
+
if (problems.some(({ problem }) => problem.level === 'error')) {
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
registerCliCommand({
|
|
82
|
+
name: 'doctor',
|
|
83
|
+
description: 'Check imports, icons, themes, styles and peer packages',
|
|
84
|
+
usage: 'doctor [options]',
|
|
85
|
+
order: 40,
|
|
86
|
+
examples: [`${CLI_NAME} doctor`],
|
|
87
|
+
run: context => doctorCommand({
|
|
88
|
+
cwd: context.cwd,
|
|
89
|
+
componentsDir: context.componentsDir,
|
|
90
|
+
globalCss: context.globalCss
|
|
91
|
+
})
|
|
92
|
+
});
|