@blankways/ui 0.0.0-stage → 0.2.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 +246 -2
- package/dist/cli/cli.options.d.ts +5 -0
- package/dist/cli/cli.options.js +73 -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 +33 -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 +48 -0
- package/dist/commands/add.command.d.ts +4 -0
- package/dist/commands/add.command.js +49 -0
- package/dist/commands/dev.command.d.ts +3 -0
- package/dist/commands/dev.command.js +76 -0
- package/dist/commands/doctor.command.d.ts +3 -0
- package/dist/commands/doctor.command.js +103 -0
- package/dist/commands/index.d.ts +9 -0
- package/dist/commands/index.js +9 -0
- package/dist/commands/init.command.d.ts +2 -0
- package/dist/commands/init.command.js +43 -0
- package/dist/commands/install.command.d.ts +2 -0
- package/dist/commands/install.command.js +36 -0
- package/dist/commands/list.command.d.ts +2 -0
- package/dist/commands/list.command.js +59 -0
- package/dist/commands/meta.command.d.ts +1 -0
- package/dist/commands/meta.command.js +19 -0
- package/dist/commands/registry.command.d.ts +2 -0
- package/dist/commands/registry.command.js +69 -0
- package/dist/commands/styles.command.d.ts +5 -0
- package/dist/commands/styles.command.js +44 -0
- package/dist/config/config.helpers.d.ts +10 -0
- package/dist/config/config.helpers.js +116 -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 +20 -0
- package/dist/constants/cli.constants.js +20 -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/barrels.check.d.ts +1 -0
- package/dist/doctor/checks/barrels.check.js +60 -0
- package/dist/doctor/checks/contracts.check.d.ts +1 -0
- package/dist/doctor/checks/contracts.check.js +45 -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 +60 -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 +10 -0
- package/dist/doctor/checks/index.js +10 -0
- package/dist/doctor/checks/motion.check.d.ts +1 -0
- package/dist/doctor/checks/motion.check.js +66 -0
- package/dist/doctor/checks/namespaces.check.d.ts +1 -0
- package/dist/doctor/checks/namespaces.check.js +76 -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 +42 -0
- package/dist/doctor/doctor.helpers.d.ts +6 -0
- package/dist/doctor/doctor.helpers.js +43 -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 +31 -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 +6 -0
- package/dist/helpers/args.helpers.js +84 -0
- package/dist/helpers/barrels.helpers.d.ts +15 -0
- package/dist/helpers/barrels.helpers.js +157 -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 +12 -0
- package/dist/index.js +11 -0
- package/dist/registry/index.d.ts +3 -0
- package/dist/registry/index.js +3 -0
- package/dist/registry/lockfile.d.ts +18 -0
- package/dist/registry/lockfile.js +32 -0
- package/dist/registry/registry.helpers.d.ts +12 -0
- package/dist/registry/registry.helpers.js +242 -0
- package/dist/registry/registry.providers.d.ts +13 -0
- package/dist/registry/registry.providers.js +159 -0
- package/dist/registry/registry.service.d.ts +14 -0
- package/dist/registry/registry.service.js +126 -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 +70 -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 +68 -0
- package/dist/types/registry.types.js +3 -0
- package/dist/ui-api/index.d.ts +16 -0
- package/dist/ui-api/index.js +30 -0
- package/dist/ui-api/ui-api.d.ts +18 -0
- package/dist/ui-api/ui-api.js +194 -0
- package/package.json +37 -3
- package/styles.css +16 -0
package/README.md
CHANGED
|
@@ -1,3 +1,247 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @blankways/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
API build-time y CLI para **componer registries externos** dentro de `ui/`. El paquete no incluye componentes, no trae un runtime propio, no importa React y no tiene registry integrado. Cada proveedor publica sus entradas en su propio paquete y `@blankways/ui` solo las descubre, valida, copia y sincroniza.
|
|
4
|
+
|
|
5
|
+
El resultado en el proyecto consumidor es siempre el mismo:
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
ui/
|
|
9
|
+
components/<uiRegistryId>/...
|
|
10
|
+
themes/<uiRegistryId>/...
|
|
11
|
+
runtimes/<uiRegistryId>/...
|
|
12
|
+
themes/index.css # generado
|
|
13
|
+
runtimes/index.ts # generado
|
|
14
|
+
ui.lock.json # commiteado
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`@blankways/ui/styles.css` es la base inmutable: se importa desde `ui/themes/index.css`, nunca se copia a `ui/`. No existen `ui/styles/` ni `ui/internals/` globales.
|
|
18
|
+
|
|
19
|
+
## Instalación
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add -D @blankways/ui
|
|
23
|
+
pnpm exec ui init --framework react --registry @blankways/react-registry
|
|
24
|
+
pnpm exec ui install
|
|
25
|
+
pnpm exec ui doctor
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`init` crea `components.json`, materializa **todo** (`exposure: "full"`) y escribe `ui.lock.json`. `install` repite ese workflow de forma idempotente. `ui/` puede borrarse y regenerarse; el lockfile debe commitearse.
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"componentsDir": "ui",
|
|
33
|
+
"framework": "react",
|
|
34
|
+
"overwrite": false,
|
|
35
|
+
"registries": ["@blankways/react-registry"],
|
|
36
|
+
"exposure": "incremental",
|
|
37
|
+
"entries": ["bw:brand-logo", "bw:container", "bw:cursor-glow", "bw:reveal"],
|
|
38
|
+
"themeOrder": ["bw", "acme"]
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- `exposure: "full"` (por defecto) instala cada entrada visible de cada registry; `entries` se ignora.
|
|
43
|
+
- `exposure: "incremental"` instala solo `entries`, más su clausura de `requires`. Esa lista es la fuente de verdad para `ui install --frozen` en CI.
|
|
44
|
+
- `add` y `ensure()` siguen pudiendo pedir entradas concretas por encima de la config.
|
|
45
|
+
- `themeOrder` fija el orden CSS entre peers; dentro de cada peer el orden es determinista.
|
|
46
|
+
|
|
47
|
+
## Workflow
|
|
48
|
+
|
|
49
|
+
Toda escritura pasa por la misma secuencia; no se escribe nada antes de validar:
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
DISCOVER → RESOLVE → VALIDATE → PLAN → APPLY → SYNC → VERIFY
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`planActions` compara la entrada con el lockfile: archivo ausente → `add`, lockfile coincidente → `update`, modificación local → `keep`. La decisión es reproducible y `--dry-run` muestra el plan sin tocar disco.
|
|
56
|
+
|
|
57
|
+
## API build-time
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import {
|
|
61
|
+
ensure, // entradas concretas + clausura de requires
|
|
62
|
+
ensureAll, // composición completa
|
|
63
|
+
install, // operación general (selectors, exposure, frozen…)
|
|
64
|
+
status, // lockfile actual
|
|
65
|
+
sync, // solo regenera barrels
|
|
66
|
+
validate // solo valida contratos
|
|
67
|
+
} from '@blankways/ui'
|
|
68
|
+
|
|
69
|
+
await ensureAll({ cwd: process.cwd() })
|
|
70
|
+
await ensure(['acme:button'], { cwd: process.cwd() })
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Ninguna de estas funciones arranca código en el browser. Todas reciben una raíz de proyecto y son seguras en un script de build o en CI:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pnpm exec ui install --frozen
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`--frozen` falla si cambiaron las entradas, las revisiones o `exposure`, sin reescribir el lockfile.
|
|
80
|
+
|
|
81
|
+
## Contrato de un registry
|
|
82
|
+
|
|
83
|
+
`package.json` del proveedor:
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"name": "@mi-org/acme-ui",
|
|
88
|
+
"version": "1.0.0",
|
|
89
|
+
"uiRegistry": "ui",
|
|
90
|
+
"uiRegistryId": "acme",
|
|
91
|
+
"uiRequires": ["@blankways/ui@^0.2.0-alpha.1"],
|
|
92
|
+
"uiDevRegistries": ["../mi-state-runtime"],
|
|
93
|
+
"exports": { "./package.json": "./package.json" }
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| Campo | Significado |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `uiRegistry` | Directorio de entradas, relativo al root del paquete (`"."` o `true` para el root). |
|
|
100
|
+
| `uiRegistryId` | Slug en minúsculas que namespacea todos los targets. Debe ser único entre los registries configurados. |
|
|
101
|
+
| `uiRequires` | Requisitos de `@blankways/ui`; información, no una dependencia que el CLI imponga. |
|
|
102
|
+
| `uiDevRegistries` | Peers usados **solo al desarrollar** el registry. Nunca se escriben en el proyecto del consumidor. |
|
|
103
|
+
|
|
104
|
+
`component.json` de una entrada:
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"name": "button",
|
|
109
|
+
"kind": "component",
|
|
110
|
+
"requires": ["acme:cn", "acme:theme", "bw:state-runtime"],
|
|
111
|
+
"themes": ["dawn", "midnight"],
|
|
112
|
+
"revision": 2,
|
|
113
|
+
"peers": ["react"],
|
|
114
|
+
"files": [
|
|
115
|
+
{ "source": "Button.tsx", "target": "components/acme/button/Button.tsx" },
|
|
116
|
+
{ "source": "button.css", "target": "components/acme/button/button.css" },
|
|
117
|
+
{ "source": "runtime.ts", "target": "runtimes/acme/button.ts" }
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
| Campo | Regla |
|
|
123
|
+
|---|---|
|
|
124
|
+
| `requires` | Entradas calificadas `id:entrada` de **cualquier** registry. Es la única forma segura de interoperar entre paquetes. |
|
|
125
|
+
| `dependencies` | Compatibilidad hacia atrás: entradas del mismo registry. |
|
|
126
|
+
| `themes` | Nombres arbitrarios por peer. No hay `light`, `dark` ni `system` especiales. |
|
|
127
|
+
| `revision` | Cambia cuando el proveedor publica una versión incompatible; `--frozen` lo detecta. |
|
|
128
|
+
| `files[].target` | Debe empezar por `components/<id>/`, `themes/<id>/` o `runtimes/<id>/`. |
|
|
129
|
+
|
|
130
|
+
Los nombres calificados usan `uiRegistryId` (`acme:button`). El specifier del paquete también funciona (`@mi-org/acme-ui:button`). El nombre simple solo se acepta si es único; si dos peers tienen `button`, el CLI exige el calificado. Las dependencias sin calificar resuelven primero dentro del mismo peer.
|
|
131
|
+
|
|
132
|
+
Los archivos se copian **tal cual** a la ruta `target`; por eso los imports relativos se escriben para la estructura final, no para la carpeta de origen del paquete (ver [`docs/registry-guide.md`](./docs/registry-guide.md)).
|
|
133
|
+
|
|
134
|
+
## Entorno dev: dependencias de UI
|
|
135
|
+
|
|
136
|
+
Un registry que interopera con otro necesita ese peer para desarrollarse, pero **no debe imponérselo** a quien lo consume. `ui dev` monta una app desechable donde los `uiDevRegistries` hacen de peers locales:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# desde la raíz del paquete @mi-org/acme-ui
|
|
140
|
+
pnpm exec ui dev # genera .ui-dev/
|
|
141
|
+
pnpm exec ui dev --app ../playground
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
La app generada declara como registries el propio paquete (`..`) y los `uiDevRegistries` resueltos, con `exposure: "full"`. Después se pueden editar sus archivos, ejecutar `ui doctor` y probar imports reales como si la app fuera un proyecto consumidor. El `package.json` publicado sigue declarando solo `uiDevRegistries`; el consumidor aporta su propio paquete con el mismo `uiRegistryId`.
|
|
145
|
+
|
|
146
|
+
Ejemplo en este repositorio (dogfooding):
|
|
147
|
+
|
|
148
|
+
```text
|
|
149
|
+
.ignore/workspace/packages/acme-ui # uiDevRegistries: ["../bw-runtime"]
|
|
150
|
+
.ignore/workspace/packages/bw-runtime
|
|
151
|
+
.ignore/workspace/packages/bw-alt # mismo id "bw", otro proveedor
|
|
152
|
+
.ignore/workspace/app # consume bw-runtime
|
|
153
|
+
.ignore/workspace/app-alt # consume bw-alt sin tocar acme-ui
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`acme:button` importa `runtimes/bw` en ambos casos; en `app` obtiene el runtime propio y en `app-alt` obtiene el del consumidor. Ese es el punto: la interoperabilidad se resuelve por `uiRegistryId` + `requires` en tiempo de build, no por una dependencia publicada.
|
|
157
|
+
|
|
158
|
+
## Barrels y estilos
|
|
159
|
+
|
|
160
|
+
`sync` se ejecuta automáticamente después de cada instalación:
|
|
161
|
+
|
|
162
|
+
```css
|
|
163
|
+
/* ui/themes/index.css */
|
|
164
|
+
@import '@blankways/ui/styles.css';
|
|
165
|
+
@import './acme/dawn.css';
|
|
166
|
+
@import './bw/tokens.css';
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Se añade `@import './ui/themes/index.css';` al CSS global detectado, justo después de `@import "tailwindcss";`. También se generan `ui/runtimes/<id>/index.ts` y `ui/runtimes/index.ts`. `ui styles link` queda como alias obsoleto de `sync`.
|
|
170
|
+
|
|
171
|
+
## Doctor
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
pnpm exec ui doctor
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Checks incluidos: `contracts` (ids únicos, targets por namespace y `requires` conocidos), `namespaces` (imports cruzados declarados), `barrels`, `imports`, `icons`, `themes`, `entries`, `peers` y `motion`. Un `error` termina con exit code 1.
|
|
178
|
+
|
|
179
|
+
Los checks son plug-ins:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { registerDoctorCheck } from '@blankways/ui'
|
|
183
|
+
|
|
184
|
+
registerDoctorCheck({
|
|
185
|
+
id: 'mi-regla',
|
|
186
|
+
async run({ componentsDir }) {
|
|
187
|
+
return { summary: 'checked', problems: [] }
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
El contexto incluye `cwd`, `componentsDir`, `displayDir`, `files`, `sourceFiles`, `framework`, `registries`, `globalCss`, `items`, `providers` y `lock`.
|
|
193
|
+
|
|
194
|
+
## Extensión del CLI
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { registerCliCommand, listRegistryItems } from '@blankways/ui'
|
|
198
|
+
|
|
199
|
+
registerCliCommand({
|
|
200
|
+
name: 'mis-icons',
|
|
201
|
+
description: 'Lista los iconos disponibles',
|
|
202
|
+
order: 60,
|
|
203
|
+
run: async context => {
|
|
204
|
+
const items = await listRegistryItems({
|
|
205
|
+
cwd: context.cwd,
|
|
206
|
+
registries: context.registries
|
|
207
|
+
})
|
|
208
|
+
console.log(items.filter(item => item.kind === 'icon').map(item => item.name).join('\n'))
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Importar el paquete root no registra los comandos integrados: el bin lo hace. `listRegistryItems()` sin opciones devuelve `[]` porque no hay registry integrado.
|
|
214
|
+
|
|
215
|
+
## Opciones
|
|
216
|
+
|
|
217
|
+
- `--cwd <path>`: raíz del proyecto.
|
|
218
|
+
- `--components-dir <path>`: sobrescribe `componentsDir`.
|
|
219
|
+
- `--registry <paquete[,paquete...]>`: sobrescribe los registries en una ejecución.
|
|
220
|
+
- `--framework <name>` / `--variant`: framework para `init`.
|
|
221
|
+
- `--global-css <path>`: CSS global donde conectar el barrel.
|
|
222
|
+
- `--exposure <full|incremental>`: modo de materialización.
|
|
223
|
+
- `--frozen`: exige que el lockfile esté al día (`install`).
|
|
224
|
+
- `--app <path>`: directorio de la app de `ui dev`.
|
|
225
|
+
- `--force`, `--dry-run`, `--all`, `--no-deps`, `--install-peers`.
|
|
226
|
+
|
|
227
|
+
## Playground local
|
|
228
|
+
|
|
229
|
+
`.ignore/workspace/dev-app` es una app Vite + React que consume `@blankways/react-registry` mediante `@blankways/ui` (dependencias `file:`). Sirve para probar la composición real con HMR:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
cd .ignore/workspace/dev-app
|
|
233
|
+
pnpm install
|
|
234
|
+
pnpm exec ui install --global-css src/demo.css
|
|
235
|
+
pnpm dev # http://localhost:4173
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Desarrollo
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
pnpm install
|
|
242
|
+
pnpm typecheck # tsc + validación del registry local (delega en su validador)
|
|
243
|
+
pnpm test # vitest (contrato de API, registry y doctor)
|
|
244
|
+
pnpm build # solo source/ → dist/
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
El registry ya no vive en la root: `@blankways/react-registry` es un paquete autocontenido cuya copia de desarrollo está en `.ignore/workspace/packages/react-registry` (ignorada por git). Se puede mover entero a otro workspace: se valida con `pnpm validate` dentro del paquete y `pnpm pack` lo valida antes de publicar. `pnpm typecheck` delega en ese validador si el fixture está presente (`BLANKWAYS_REGISTRY_DIR=<ruta>` para otra copia) y lo omite si no existe. `pnpm build` compila solo `source/`; la publicación de `@blankways/ui` contiene `dist/` y `styles.css`. La guía de autoría está en [`docs/registry-guide.md`](./docs/registry-guide.md).
|
|
@@ -0,0 +1,73 @@
|
|
|
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: '--registry <package[,package...]>',
|
|
24
|
+
description: 'Registry packages to use (overrides components.json)'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
flag: '--force',
|
|
28
|
+
description: 'Overwrite existing files or components.json'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
flag: '--dry-run',
|
|
32
|
+
description: 'Show what would change without writing files'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
flag: '--all',
|
|
36
|
+
description: 'Add every entry (combine with --kind to narrow it)'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
flag: '--no-deps',
|
|
40
|
+
description: 'Do not copy registry dependencies'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
flag: '--no-import',
|
|
44
|
+
description: 'Do not link styles after add (deprecated)'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
flag: '--frozen',
|
|
48
|
+
description: 'Fail if ui.lock.json does not match the configured registries'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
flag: '--exposure <full|incremental>',
|
|
52
|
+
description: 'Override the default full materialization'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
flag: '--install-peers',
|
|
56
|
+
description: 'Allow install to add declared peer packages'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
flag: '--app <path>',
|
|
60
|
+
description: 'Dev app directory for "ui dev" (default .ui-dev)'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
flag: '-h, --help',
|
|
64
|
+
description: 'Show this help'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
flag: '-v, --version',
|
|
68
|
+
description: 'Show the CLI version'
|
|
69
|
+
}
|
|
70
|
+
];
|
|
71
|
+
export function getCliOptions() {
|
|
72
|
+
return [...CLI_OPTIONS];
|
|
73
|
+
}
|
|
@@ -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,33 @@
|
|
|
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
|
+
registries?: string[];
|
|
10
|
+
names: string[];
|
|
11
|
+
flags: Record<string, FlagValue>;
|
|
12
|
+
force: boolean;
|
|
13
|
+
dryRun: boolean;
|
|
14
|
+
all: boolean;
|
|
15
|
+
noDeps: boolean;
|
|
16
|
+
noImport: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type CliCommand = {
|
|
19
|
+
name: string;
|
|
20
|
+
aliases?: string[];
|
|
21
|
+
description: string;
|
|
22
|
+
usage?: string;
|
|
23
|
+
order?: number;
|
|
24
|
+
examples?: string[];
|
|
25
|
+
hidden?: boolean;
|
|
26
|
+
run(context: CliContext): Promise<void> | void;
|
|
27
|
+
};
|
|
28
|
+
export type CliRegistry = {
|
|
29
|
+
register(command: CliCommand): void;
|
|
30
|
+
list(): readonly CliCommand[];
|
|
31
|
+
resolve(name: string): CliCommand | null;
|
|
32
|
+
clear(): void;
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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, getStringListFlag, 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
|
+
registries: getStringListFlag(args.flags, 'registry'),
|
|
34
|
+
names: args.names,
|
|
35
|
+
flags: args.flags,
|
|
36
|
+
force: isFlagEnabled(args.flags, 'force'),
|
|
37
|
+
dryRun: isFlagEnabled(args.flags, 'dryRun'),
|
|
38
|
+
all: isFlagEnabled(args.flags, 'all'),
|
|
39
|
+
noDeps: isFlagEnabled(args.flags, 'noDeps'),
|
|
40
|
+
noImport: isFlagEnabled(args.flags, 'noImport')
|
|
41
|
+
};
|
|
42
|
+
await command.run(context);
|
|
43
|
+
}
|
|
44
|
+
main().catch(error => {
|
|
45
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
46
|
+
console.error(`${CLI_NAME}: ${message}`);
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AddOptions } from '../types/config.types.js';
|
|
2
|
+
import { type InstallResult } from '../ui-api/index.js';
|
|
3
|
+
export declare function printInstallResult(result: InstallResult, dryRun: boolean): void;
|
|
4
|
+
export declare function addCommand(options: AddOptions): Promise<void>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { registerCliCommand } from '../cli/cli.registry.js';
|
|
2
|
+
import { CLI_NAME } from '../constants/index.js';
|
|
3
|
+
import { CliError } from '../errors/index.js';
|
|
4
|
+
import { install } from '../ui-api/index.js';
|
|
5
|
+
export function printInstallResult(result, dryRun) {
|
|
6
|
+
const label = (items, verb) => {
|
|
7
|
+
if (items.length === 0)
|
|
8
|
+
return;
|
|
9
|
+
console.log(`\n${verb}: ${items.join(', ')}`);
|
|
10
|
+
};
|
|
11
|
+
if (dryRun) {
|
|
12
|
+
label(result.planned, 'Would add');
|
|
13
|
+
console.log(`\nDry run: ${result.planned.length} file(s) would be copied.`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
label(result.added, 'Added');
|
|
17
|
+
label(result.updated, 'Updated');
|
|
18
|
+
label(result.kept, 'Kept locally modified');
|
|
19
|
+
label(result.barrels, 'Regenerated');
|
|
20
|
+
console.log(`\nDone: ${result.entries.length} entries installed.`);
|
|
21
|
+
}
|
|
22
|
+
export async function addCommand(options) {
|
|
23
|
+
if (!options.names?.length && !options.all) {
|
|
24
|
+
throw new CliError('No entries specified. Use <entry...> or --all.');
|
|
25
|
+
}
|
|
26
|
+
const result = await install({
|
|
27
|
+
cwd: options.cwd,
|
|
28
|
+
componentsDir: options.componentsDir,
|
|
29
|
+
registries: options.registries,
|
|
30
|
+
selectors: options.names,
|
|
31
|
+
exposure: options.all ? 'full' : 'incremental',
|
|
32
|
+
force: options.force,
|
|
33
|
+
dryRun: options.dryRun,
|
|
34
|
+
globalCss: options.globalCss
|
|
35
|
+
});
|
|
36
|
+
printInstallResult(result, Boolean(options.dryRun));
|
|
37
|
+
}
|
|
38
|
+
registerCliCommand({
|
|
39
|
+
name: 'add',
|
|
40
|
+
description: 'Install registry entries and their requires, then regenerate barrels',
|
|
41
|
+
usage: 'add <entry...> [options]',
|
|
42
|
+
order: 20,
|
|
43
|
+
examples: [
|
|
44
|
+
`${CLI_NAME} add acme:button`,
|
|
45
|
+
`${CLI_NAME} add --all`,
|
|
46
|
+
`${CLI_NAME} add acme:button --dry-run`
|
|
47
|
+
],
|
|
48
|
+
run: context => addCommand(context)
|
|
49
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
3
|
+
import { registerCliCommand } from '../cli/cli.registry.js';
|
|
4
|
+
import { CLI_NAME, UI_DEV_REGISTRIES_FIELD, UI_REGISTRY_FIELD } from '../constants/index.js';
|
|
5
|
+
import { CliError } from '../errors/index.js';
|
|
6
|
+
import { getStringFlag } from '../helpers/index.js';
|
|
7
|
+
import { install } from '../ui-api/index.js';
|
|
8
|
+
async function isFile(path) {
|
|
9
|
+
try {
|
|
10
|
+
return (await stat(path)).isFile();
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function readStringArray(value, field) {
|
|
17
|
+
if (value === undefined)
|
|
18
|
+
return [];
|
|
19
|
+
if (!Array.isArray(value) || value.some(entry => typeof entry !== 'string')) {
|
|
20
|
+
throw new CliError(`package.json: "${field}" must be an array of strings.`);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
/** Mounts a throwaway app where dev-only registries stand in for peers. */
|
|
25
|
+
export async function devCommand(context) {
|
|
26
|
+
const packageRoot = context.cwd ? resolve(context.cwd) : process.cwd();
|
|
27
|
+
const manifestPath = join(packageRoot, 'package.json');
|
|
28
|
+
if (!(await isFile(manifestPath))) {
|
|
29
|
+
throw new CliError(`package.json not found at ${packageRoot}.`);
|
|
30
|
+
}
|
|
31
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
32
|
+
if (manifest[UI_REGISTRY_FIELD] === undefined) {
|
|
33
|
+
throw new CliError(`package.json at ${packageRoot} does not declare "${UI_REGISTRY_FIELD}".`);
|
|
34
|
+
}
|
|
35
|
+
const appDir = resolve(packageRoot, getStringFlag(context.flags, 'app') ?? '.ui-dev');
|
|
36
|
+
const devRegistries = readStringArray(manifest[UI_DEV_REGISTRIES_FIELD], UI_DEV_REGISTRIES_FIELD).map(specifier => specifier.startsWith('.') || isAbsolute(specifier)
|
|
37
|
+
? resolve(packageRoot, specifier)
|
|
38
|
+
: specifier);
|
|
39
|
+
const self = relative(appDir, packageRoot) || '.';
|
|
40
|
+
const selfSpecifier = self.startsWith('.') ? self : `./${self}`;
|
|
41
|
+
const registries = Array.from(new Set([selfSpecifier, ...devRegistries]));
|
|
42
|
+
await mkdir(appDir, { recursive: true });
|
|
43
|
+
await writeFile(join(appDir, 'components.json'), `${JSON.stringify({
|
|
44
|
+
componentsDir: 'ui',
|
|
45
|
+
framework: context.framework ?? 'react',
|
|
46
|
+
overwrite: true,
|
|
47
|
+
registries,
|
|
48
|
+
exposure: 'full'
|
|
49
|
+
}, null, 2)}\n`, 'utf8');
|
|
50
|
+
const packagePath = join(appDir, 'package.json');
|
|
51
|
+
if (!(await isFile(packagePath))) {
|
|
52
|
+
await writeFile(packagePath, `${JSON.stringify({
|
|
53
|
+
name: '@blankways/ui-dev-app',
|
|
54
|
+
private: true,
|
|
55
|
+
type: 'module',
|
|
56
|
+
dependencies: { react: '^19.0.0' }
|
|
57
|
+
}, null, 2)}\n`, 'utf8');
|
|
58
|
+
}
|
|
59
|
+
const globalCss = join(appDir, 'src', 'app', 'globals.css');
|
|
60
|
+
await mkdir(join(globalCss, '..'), { recursive: true });
|
|
61
|
+
if (!(await isFile(globalCss))) {
|
|
62
|
+
await writeFile(globalCss, '@import "tailwindcss";\n', 'utf8');
|
|
63
|
+
}
|
|
64
|
+
const result = await install({ cwd: appDir, force: true, globalCss: 'src/app/globals.css' });
|
|
65
|
+
console.log(`${CLI_NAME} dev app: ${appDir}`);
|
|
66
|
+
console.log(`Registries: ${registries.join(', ')}`);
|
|
67
|
+
console.log(`Added ${result.added.length} file(s), ${result.entries.length} entries.`);
|
|
68
|
+
}
|
|
69
|
+
registerCliCommand({
|
|
70
|
+
name: 'dev',
|
|
71
|
+
description: 'Create a local dev app using uiDevRegistries without publishing them',
|
|
72
|
+
usage: 'dev [--app <path>]',
|
|
73
|
+
order: 12,
|
|
74
|
+
examples: [`${CLI_NAME} dev`, `${CLI_NAME} dev --app ../playground`],
|
|
75
|
+
run: context => devCommand(context)
|
|
76
|
+
});
|