openuispec 0.1.5 → 0.1.7
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/cli/init.ts +136 -0
- package/package.json +1 -1
package/cli/init.ts
CHANGED
|
@@ -118,6 +118,121 @@ api:
|
|
|
118
118
|
`;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
function specReadmeTemplate(name: string, targets: string[]): string {
|
|
122
|
+
const targetList = targets.join(", ");
|
|
123
|
+
return `# ${name} — OpenUISpec
|
|
124
|
+
|
|
125
|
+
This directory contains the **OpenUISpec** semantic UI specification for **${name}**.
|
|
126
|
+
|
|
127
|
+
OpenUISpec is a YAML-based format that describes your app's UI semantically — tokens, screens, flows, and platform overrides. AI reads the spec and generates native code (SwiftUI, Compose, React). The spec is the single source of truth across all platforms.
|
|
128
|
+
|
|
129
|
+
## Directory structure
|
|
130
|
+
|
|
131
|
+
| Directory | Contents |
|
|
132
|
+
|-----------|----------|
|
|
133
|
+
| \`tokens/\` | Design tokens — colors, typography, spacing, elevation, motion, icons, themes |
|
|
134
|
+
| \`screens/\` | Screen definitions — one YAML file per screen |
|
|
135
|
+
| \`flows/\` | Navigation flows — multi-step user journeys |
|
|
136
|
+
| \`contracts/\` | Component contracts — custom UI component definitions (\`x_\` prefixed) |
|
|
137
|
+
| \`platform/\` | Platform overrides — per-target (iOS, Android, Web) behaviors |
|
|
138
|
+
| \`locales/\` | Localization — i18n strings (JSON, ICU MessageFormat) |
|
|
139
|
+
|
|
140
|
+
## Getting started
|
|
141
|
+
|
|
142
|
+
**Start here:** read \`openuispec.yaml\` — it's the root manifest that defines the project structure, data model, API endpoints, and generation targets.
|
|
143
|
+
|
|
144
|
+
### New project (no existing UI code)
|
|
145
|
+
|
|
146
|
+
1. Define your data model and API endpoints in \`openuispec.yaml\`
|
|
147
|
+
2. Create token files in \`tokens/\` (colors, typography, spacing)
|
|
148
|
+
3. Create screen specs in \`screens/\` (one YAML per screen)
|
|
149
|
+
4. Create navigation flows in \`flows/\`
|
|
150
|
+
5. Ask AI to generate native code from the spec
|
|
151
|
+
|
|
152
|
+
### Existing project (adopting OpenUISpec)
|
|
153
|
+
|
|
154
|
+
1. Scan the codebase for existing UI screens
|
|
155
|
+
2. Create a stub for each screen in \`screens/\`:
|
|
156
|
+
\`\`\`yaml
|
|
157
|
+
screen_name:
|
|
158
|
+
semantic: "Brief description of what this screen does"
|
|
159
|
+
status: stub
|
|
160
|
+
layout:
|
|
161
|
+
type: scroll_vertical
|
|
162
|
+
\`\`\`
|
|
163
|
+
3. Extract design tokens (colors, fonts, spacing) into \`tokens/\`
|
|
164
|
+
4. Fill in \`data_model\` and \`api.endpoints\` in \`openuispec.yaml\`
|
|
165
|
+
5. Spec screens incrementally: \`stub\` → \`draft\` → \`ready\`
|
|
166
|
+
|
|
167
|
+
## Screen and flow status
|
|
168
|
+
|
|
169
|
+
- \`stub\` — placeholder, not yet specced. Drift detection skips these.
|
|
170
|
+
- \`draft\` — actively being specced. Tracked by drift.
|
|
171
|
+
- \`ready\` — fully specified (default if omitted). Tracked by drift.
|
|
172
|
+
|
|
173
|
+
## JSON Schemas (validation & file structure)
|
|
174
|
+
|
|
175
|
+
**IMPORTANT:** Before creating or editing any spec file, read the corresponding JSON Schema to understand the valid structure. Schemas are located in the installed package:
|
|
176
|
+
|
|
177
|
+
\`\`\`
|
|
178
|
+
node_modules/openuispec/schema/
|
|
179
|
+
├── openuispec.schema.json ← root manifest (openuispec.yaml)
|
|
180
|
+
├── screen.schema.json ← screen files (screens/*.yaml)
|
|
181
|
+
├── flow.schema.json ← flow files (flows/*.yaml)
|
|
182
|
+
├── platform.schema.json ← platform overrides (platform/*.yaml)
|
|
183
|
+
├── locale.schema.json ← locale files (locales/*.json)
|
|
184
|
+
├── custom-contract.schema.json ← custom contracts (contracts/*.yaml)
|
|
185
|
+
├── tokens/
|
|
186
|
+
│ ├── color.schema.json ← tokens/color.yaml
|
|
187
|
+
│ ├── typography.schema.json ← tokens/typography.yaml
|
|
188
|
+
│ ├── spacing.schema.json ← tokens/spacing.yaml
|
|
189
|
+
│ ├── elevation.schema.json ← tokens/elevation.yaml
|
|
190
|
+
│ ├── motion.schema.json ← tokens/motion.yaml
|
|
191
|
+
│ ├── layout.schema.json ← tokens/layout.yaml
|
|
192
|
+
│ ├── themes.schema.json ← tokens/themes.yaml
|
|
193
|
+
│ └── icons.schema.json ← tokens/icons.yaml
|
|
194
|
+
└── defs/
|
|
195
|
+
├── common.schema.json ← shared types (icons, badges, etc.)
|
|
196
|
+
├── action.schema.json ← 13 action types (discriminated union)
|
|
197
|
+
├── data-binding.schema.json ← data sources, state, params
|
|
198
|
+
├── adaptive.schema.json ← adaptive override pattern
|
|
199
|
+
└── validation.schema.json ← validation rule definitions
|
|
200
|
+
\`\`\`
|
|
201
|
+
|
|
202
|
+
**Workflow:** read the schema → create the YAML file → run \`openuispec validate\` to verify.
|
|
203
|
+
|
|
204
|
+
**Example spec files:** \`node_modules/openuispec/examples/taskflow/\` — a complete app demonstrating all file types. Read these for real-world examples of screens, flows, tokens, and platform overrides.
|
|
205
|
+
|
|
206
|
+
## Spec format quick reference
|
|
207
|
+
|
|
208
|
+
- **7 contract families:** nav_container, surface, action_trigger, input_field, data_display, collection, feedback
|
|
209
|
+
- **Custom contracts:** prefixed with \`x_\` (e.g., \`x_media_player\`)
|
|
210
|
+
- **Data binding:** \`$data:\`, \`$state:\`, \`$param:\`, \`$t:\` prefixes
|
|
211
|
+
- **Actions:** typed objects — navigate, api_call, set_state, confirm, sequence, feedback, etc.
|
|
212
|
+
- **Adaptive layout:** size classes (compact, regular, expanded) with per-section overrides
|
|
213
|
+
|
|
214
|
+
## CLI commands
|
|
215
|
+
|
|
216
|
+
\`\`\`bash
|
|
217
|
+
openuispec validate # Validate spec files against schemas
|
|
218
|
+
openuispec validate screens # Validate only screens
|
|
219
|
+
openuispec drift --target ${targets[0]} # Check for spec drift
|
|
220
|
+
openuispec drift --snapshot --target ${targets[0]} # Snapshot current state
|
|
221
|
+
openuispec drift --all # Include stubs in drift check
|
|
222
|
+
\`\`\`
|
|
223
|
+
|
|
224
|
+
## Targets
|
|
225
|
+
|
|
226
|
+
This project generates native code for: **${targetList}**
|
|
227
|
+
|
|
228
|
+
## Learn more
|
|
229
|
+
|
|
230
|
+
- Full spec: https://github.com/rsktash/openuispec/blob/main/spec/openuispec-v0.1.md
|
|
231
|
+
- Example app: https://github.com/rsktash/openuispec/tree/main/examples/taskflow
|
|
232
|
+
- Repository: https://github.com/rsktash/openuispec
|
|
233
|
+
`;
|
|
234
|
+
}
|
|
235
|
+
|
|
121
236
|
function aiRulesBlock(specDir: string, targets: string[]): string {
|
|
122
237
|
const targetList = targets.map((t) => `"${t}"`).join(", ");
|
|
123
238
|
return `
|
|
@@ -173,6 +288,20 @@ This means the project has existing UI code but hasn't been specced yet. Your jo
|
|
|
173
288
|
2. Run \`openuispec drift --snapshot --target <target>\` for each affected platform.
|
|
174
289
|
3. Run \`openuispec drift\` to verify no untracked drift remains.
|
|
175
290
|
|
|
291
|
+
## JSON Schemas — read before creating spec files
|
|
292
|
+
Before creating or editing any spec file, read the corresponding JSON Schema to understand the valid structure. Schemas are in the installed package:
|
|
293
|
+
- \`node_modules/openuispec/schema/openuispec.schema.json\` — root manifest
|
|
294
|
+
- \`node_modules/openuispec/schema/screen.schema.json\` — screens
|
|
295
|
+
- \`node_modules/openuispec/schema/flow.schema.json\` — flows
|
|
296
|
+
- \`node_modules/openuispec/schema/platform.schema.json\` — platform overrides
|
|
297
|
+
- \`node_modules/openuispec/schema/locale.schema.json\` — locales
|
|
298
|
+
- \`node_modules/openuispec/schema/custom-contract.schema.json\` — custom contracts
|
|
299
|
+
- \`node_modules/openuispec/schema/tokens/*.schema.json\` — token files (color, typography, spacing, elevation, motion, layout, themes, icons)
|
|
300
|
+
- \`node_modules/openuispec/schema/defs/*.schema.json\` — shared types (actions, data-binding, adaptive, validation, common)
|
|
301
|
+
|
|
302
|
+
Workflow: read the schema → create the YAML → run \`openuispec validate\`.
|
|
303
|
+
Example spec files: \`node_modules/openuispec/examples/taskflow/\` — a complete app with all file types.
|
|
304
|
+
|
|
176
305
|
## Spec format reference
|
|
177
306
|
- 7 contract families: nav_container, surface, action_trigger, input_field, data_display, collection, feedback
|
|
178
307
|
- Custom contracts: prefixed with \`x_\` (e.g., \`x_media_player\`)
|
|
@@ -247,6 +376,13 @@ export async function init(): Promise<void> {
|
|
|
247
376
|
manifestTemplate(name, targets, specDir)
|
|
248
377
|
);
|
|
249
378
|
|
|
379
|
+
// ── spec README ──────────────────────────────────────────────
|
|
380
|
+
|
|
381
|
+
writeIfMissing(
|
|
382
|
+
join(root, "README.md"),
|
|
383
|
+
specReadmeTemplate(name, targets)
|
|
384
|
+
);
|
|
385
|
+
|
|
250
386
|
// ── .gitkeep for empty dirs ────────────────────────────────────
|
|
251
387
|
|
|
252
388
|
for (const d of dirs) {
|