@buildpad/cli 0.1.4

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 (44) hide show
  1. package/README.md +557 -0
  2. package/dist/chunk-J4KKVECI.js +365 -0
  3. package/dist/chunk-J4KKVECI.js.map +1 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +2582 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/outdated-JMAYAZ7W.js +110 -0
  8. package/dist/outdated-JMAYAZ7W.js.map +1 -0
  9. package/dist/templates/api/auth-callback-route.ts +36 -0
  10. package/dist/templates/api/auth-headers.ts +72 -0
  11. package/dist/templates/api/auth-login-route.ts +63 -0
  12. package/dist/templates/api/auth-logout-route.ts +41 -0
  13. package/dist/templates/api/auth-user-route.ts +71 -0
  14. package/dist/templates/api/collections-route.ts +54 -0
  15. package/dist/templates/api/fields-route.ts +44 -0
  16. package/dist/templates/api/files-id-route.ts +116 -0
  17. package/dist/templates/api/files-route.ts +83 -0
  18. package/dist/templates/api/items-id-route.ts +120 -0
  19. package/dist/templates/api/items-route.ts +88 -0
  20. package/dist/templates/api/login-page.tsx +142 -0
  21. package/dist/templates/api/permissions-me-route.ts +72 -0
  22. package/dist/templates/api/relations-route.ts +46 -0
  23. package/dist/templates/app/content/[collection]/[id]/page.tsx +35 -0
  24. package/dist/templates/app/content/[collection]/page.tsx +65 -0
  25. package/dist/templates/app/content/layout.tsx +64 -0
  26. package/dist/templates/app/content/page.tsx +66 -0
  27. package/dist/templates/app/design-tokens.css +183 -0
  28. package/dist/templates/app/globals.css +58 -0
  29. package/dist/templates/app/layout.tsx +49 -0
  30. package/dist/templates/app/page.tsx +23 -0
  31. package/dist/templates/components/ColorSchemeToggle.tsx +35 -0
  32. package/dist/templates/lib/common-utils.ts +156 -0
  33. package/dist/templates/lib/hooks/index.ts +98 -0
  34. package/dist/templates/lib/services/index.ts +31 -0
  35. package/dist/templates/lib/theme.ts +241 -0
  36. package/dist/templates/lib/types/index.ts +10 -0
  37. package/dist/templates/lib/utils-index.ts +32 -0
  38. package/dist/templates/lib/utils.ts +14 -0
  39. package/dist/templates/lib/vform/index.ts +24 -0
  40. package/dist/templates/middleware/middleware.ts +29 -0
  41. package/dist/templates/supabase/client.ts +25 -0
  42. package/dist/templates/supabase/middleware.ts +66 -0
  43. package/dist/templates/supabase/server.ts +45 -0
  44. package/package.json +61 -0
package/README.md ADDED
@@ -0,0 +1,557 @@
1
+ # @buildpad/cli
2
+
3
+ A CLI for adding Buildpad components to your project.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@buildpad/cli)](https://www.npmjs.com/package/@buildpad/cli)
6
+
7
+ ## Usage
8
+
9
+ Use the `init` command to set up a new project and the `add` command to add components.
10
+
11
+ ```bash
12
+ npx @buildpad/cli init
13
+ npx @buildpad/cli add input select-dropdown
14
+ ```
15
+
16
+ ## init
17
+
18
+ Use the `init` command to initialize configuration and dependencies for a new project.
19
+
20
+ The `init` command creates a `buildpad.json` file, sets up directory structure, and checks for required dependencies.
21
+
22
+ ```bash
23
+ npx @buildpad/cli init
24
+ ```
25
+
26
+ ### Options
27
+
28
+ ```
29
+ Usage: buildpad init [options]
30
+
31
+ initialize your project and install dependencies
32
+
33
+ Options:
34
+ -y, --yes skip confirmation prompt (default: false)
35
+ -c, --cwd <cwd> the working directory (defaults to current directory)
36
+ -h, --help display help for command
37
+ ```
38
+
39
+ ## add
40
+
41
+ Use the `add` command to add components to your project.
42
+
43
+ ```bash
44
+ npx @buildpad/cli add [component]
45
+ ```
46
+
47
+ ### Options
48
+
49
+ ```
50
+ Usage: buildpad add [options] [components...]
51
+
52
+ add components to your project
53
+
54
+ Arguments:
55
+ components name of components to add
56
+
57
+ Options:
58
+ -a, --all add all available components (default: false)
59
+ --with-api also add API routes and Supabase auth templates
60
+ --category <name> add all components from a category
61
+ -o, --overwrite overwrite existing files (default: false)
62
+ -n, --dry-run preview changes without modifying files
63
+ --cwd <cwd> the working directory (defaults to current directory)
64
+ -h, --help display help for command
65
+ ```
66
+
67
+ ### Examples
68
+
69
+ ```bash
70
+ # Add specific components
71
+ npx @buildpad/cli add input
72
+ npx @buildpad/cli add input select-dropdown datetime
73
+
74
+ # Add collection-form (includes VForm + all 32 interface components)
75
+ npx @buildpad/cli add collection-form
76
+
77
+ # Add all components from a category
78
+ npx @buildpad/cli add --category selection
79
+
80
+ # Add all components
81
+ npx @buildpad/cli add --all
82
+ ```
83
+
84
+ ## list
85
+
86
+ Use the `list` command to view all available components.
87
+
88
+ ```bash
89
+ npx @buildpad/cli list
90
+ ```
91
+
92
+ ### Options
93
+
94
+ ```
95
+ Usage: buildpad list [options]
96
+
97
+ list available components
98
+
99
+ Options:
100
+ --category <name> filter by category
101
+ --json output as JSON
102
+ -h, --help display help for command
103
+ ```
104
+
105
+ ## bootstrap
106
+
107
+ Use the `bootstrap` command for full project setup in a single non-interactive command. Recommended for AI agents and CI/CD pipelines.
108
+
109
+ ```bash
110
+ npx @buildpad/cli bootstrap
111
+ ```
112
+
113
+ ### Options
114
+
115
+ ```
116
+ Usage: buildpad bootstrap [options]
117
+
118
+ Full project setup: init + add --all + install deps + validate (single command for AI agents)
119
+
120
+ Options:
121
+ --cwd <cwd> the working directory (defaults to current directory)
122
+ --skip-deps skip npm dependency installation
123
+ --skip-validate skip post-install validation
124
+ -h, --help display help for command
125
+ ```
126
+
127
+ ### What Bootstrap Does
128
+
129
+ 1. Creates `buildpad.json` and project skeleton (package.json, tsconfig, Next.js layout/page, design tokens)
130
+ 2. Copies all 40+ UI components to `components/ui/`
131
+ 3. Copies types, services, hooks to `lib/buildpad/`
132
+ 4. Copies API proxy routes (fields, items, relations, files)
133
+ 5. Copies auth proxy routes (login, logout, user, callback) + login page
134
+ 6. Copies Supabase auth utilities and middleware
135
+ 7. Runs `pnpm install` to resolve all dependencies
136
+ 8. Validates the installation
137
+
138
+ **Auth Routes Installed:**
139
+ | Route | Method | Purpose |
140
+ |-------|--------|---------|
141
+ | `/api/auth/login` | POST | Login via Supabase Auth (server-side, no CORS) |
142
+ | `/api/auth/logout` | POST | Sign out and clear session cookies |
143
+ | `/api/auth/user` | GET | Get current user profile |
144
+ | `/api/auth/callback` | GET | Handle OAuth/email-confirm redirects |
145
+ | `/app/login/page.tsx` | — | Login page using proxy pattern |
146
+
147
+ ## validate
148
+
149
+ Use the `validate` command to check your Buildpad installation for common issues.
150
+
151
+ ```bash
152
+ npx @buildpad/cli validate
153
+ ```
154
+
155
+ ### Options
156
+
157
+ ```
158
+ Usage: buildpad validate [options]
159
+
160
+ validate Buildpad installation (check imports, missing files, SSR issues)
161
+
162
+ Options:
163
+ --json output as JSON for CI/CD
164
+ --cwd <cwd> the working directory (defaults to current directory)
165
+ -h, --help display help for command
166
+ ```
167
+
168
+ ### What It Checks
169
+
170
+ - **Untransformed imports** - `@buildpad/*` imports that weren't converted to local paths
171
+ - **Missing lib files** - Required utility modules not present (types, services, hooks, utils)
172
+ - **Missing CSS files** - CSS required by rich text editors (RichTextHTML.css, InputBlockEditor.css)
173
+ - **SSR issues** - Components like InputBlockEditor exported without SSR-safe wrappers
174
+ - **Missing API routes** - DaaS integration routes for fields, items, permissions
175
+
176
+ ### Example Output
177
+
178
+ ```
179
+ ✗ Found 2 error(s):
180
+
181
+ ✗ src/components/ui/input.tsx:5
182
+ Untransformed import: import { Field } from '@buildpad/types';
183
+
184
+ ✗ lib/buildpad/interface-registry.ts
185
+ Missing required file for utils module
186
+
187
+ ⚠ Found 1 warning(s):
188
+
189
+ ⚠ components/ui/index.ts
190
+ InputBlockEditor exported directly may cause SSR errors. Use input-block-editor-wrapper instead.
191
+
192
+ 💡 Suggestions:
193
+
194
+ 1. Fix 2 untransformed import(s) by running: pnpm cli add --all --overwrite --cwd .
195
+ 2. Update components/ui/index.ts to export InputBlockEditor from './input-block-editor-wrapper'
196
+ ```
197
+
198
+ ## diff
199
+
200
+ Use the `diff` command to preview changes before adding a component.
201
+
202
+ ```bash
203
+ npx @buildpad/cli diff [component]
204
+ ```
205
+
206
+ ### Options
207
+
208
+ ```
209
+ Usage: buildpad diff [options] <component>
210
+
211
+ preview changes before adding a component
212
+
213
+ Options:
214
+ --cwd <cwd> the working directory (defaults to current directory)
215
+ -h, --help display help for command
216
+ ```
217
+
218
+ ## status
219
+
220
+ Use the `status` command to view all installed Buildpad components and their origins.
221
+
222
+ ```bash
223
+ npx @buildpad/cli status
224
+ ```
225
+
226
+ ### Options
227
+
228
+ ```
229
+ Usage: buildpad status [options]
230
+
231
+ show installed Buildpad components and their origins
232
+
233
+ Options:
234
+ --json output as JSON
235
+ --cwd <cwd> the working directory (defaults to current directory)
236
+ -h, --help display help for command
237
+ ```
238
+
239
+ ### Example Output
240
+
241
+ ```
242
+ 📦 Buildpad Status
243
+
244
+ Config file: buildpad.json
245
+ Lib modules: types, hooks, services
246
+ Components: input, select-dropdown, list-m2m
247
+
248
+ Installed Files:
249
+
250
+ @buildpad/ui-interfaces/input
251
+ └─ src/components/ui/input.tsx
252
+ v1.0.0 (2026-01-12)
253
+
254
+ @buildpad/lib/hooks
255
+ └─ src/lib/buildpad/hooks/useRelationM2M.ts
256
+ v1.0.0 (2026-01-12)
257
+
258
+ Total: 15 files from Buildpad
259
+ ```
260
+
261
+ ## buildpad.json
262
+
263
+ The `buildpad.json` file holds configuration for your project. We use it to understand how your project is set up and how to generate components customized for your project.
264
+
265
+ You can create a `buildpad.json` file by running the `init` command.
266
+
267
+ ```json
268
+ {
269
+ "$schema": "https://buildpad.dev/schema.json",
270
+ "model": "copy-own",
271
+ "tsx": true,
272
+ "srcDir": true,
273
+ "aliases": {
274
+ "components": "@/components/ui",
275
+ "lib": "@/lib/buildpad"
276
+ },
277
+ "installedLib": [],
278
+ "installedComponents": []
279
+ }
280
+ ```
281
+
282
+ ### tsx
283
+
284
+ Choose between TypeScript or JavaScript components.
285
+
286
+ Setting this option to `false` allows components to be added as JavaScript with the `.jsx` file extension.
287
+
288
+ ```json
289
+ {
290
+ "tsx": true | false
291
+ }
292
+ ```
293
+
294
+ ### srcDir
295
+
296
+ Whether your project uses the `src/` directory structure.
297
+
298
+ ```json
299
+ {
300
+ "srcDir": true | false
301
+ }
302
+ ```
303
+
304
+ ### aliases
305
+
306
+ The CLI uses these values to place generated components in the correct location.
307
+
308
+ ```json
309
+ {
310
+ "aliases": {
311
+ "components": "@/components/ui",
312
+ "lib": "@/lib/buildpad"
313
+ }
314
+ }
315
+ ```
316
+
317
+ Path aliases have to be set up in your `tsconfig.json` or `jsconfig.json` file:
318
+
319
+ ```json
320
+ {
321
+ "compilerOptions": {
322
+ "baseUrl": ".",
323
+ "paths": {
324
+ "@/*": ["./src/*"]
325
+ }
326
+ }
327
+ }
328
+ ```
329
+
330
+ ### installedLib and installedComponents
331
+
332
+ These arrays track what has been installed. The CLI uses them to avoid reinstalling dependencies.
333
+
334
+ ## What Gets Copied
335
+
336
+ When you add a component, the CLI:
337
+
338
+ 1. **Copies the component source** to your components directory
339
+ 2. **Copies required lib modules** (types, services, hooks) if needed
340
+ 3. **Transforms imports** from `@buildpad/*` to local paths
341
+ 4. **Reports missing dependencies** that need to be installed
342
+
343
+ ### Example: Adding `list-m2m`
344
+
345
+ ```bash
346
+ npx @buildpad/cli add list-m2m
347
+ ```
348
+
349
+ This copies:
350
+ - `components/ui/list-m2m.tsx` - The component
351
+ - `lib/buildpad/types/` - Type definitions
352
+ - `lib/buildpad/services/` - CRUD services
353
+ - `lib/buildpad/hooks/` - React hooks
354
+
355
+ ### Import Transformation
356
+
357
+ Original (in source):
358
+ ```tsx
359
+ import { useRelationM2M } from '@buildpad/hooks';
360
+ import type { M2MItem } from '@buildpad/types';
361
+ ```
362
+
363
+ Transformed (in your project):
364
+ ```tsx
365
+ import { useRelationM2M } from '@/lib/buildpad/hooks';
366
+ import type { M2MItem } from '@/lib/buildpad/types';
367
+ ```
368
+
369
+ ## Component Categories
370
+
371
+ | Category | Components |
372
+ |----------|------------|
373
+ | `input` | Input, Textarea, InputCode, InputBlockEditor, Tags |
374
+ | `selection` | SelectDropdown, SelectRadio, SelectMultipleCheckbox, SelectIcon, AutocompleteAPI, CollectionItemDropdown |
375
+ | `datetime` | DateTime |
376
+ | `boolean` | Boolean, Toggle |
377
+ | `media` | FileInterface, FileImage, Files, Upload, Color |
378
+ | `relational` | ListM2M, ListM2O, ListO2M, ListM2A |
379
+ | `layout` | Divider, Notice, GroupDetail, Slider |
380
+ | `rich-text` | RichTextHtml, RichTextMarkdown |
381
+ | `collection` | VForm, CollectionForm, CollectionList |
382
+
383
+ ### VForm and CollectionForm
384
+
385
+ When you add `collection-form`, it automatically includes:
386
+ - **VForm** - Dynamic form component that renders any field type
387
+ - **32 interface components** - All field types (input, select, datetime, M2M, M2O, etc.)
388
+ - **Lib modules** - types, services, hooks, and field-interface-mapper utilities
389
+
390
+ This is because `collection-form` has `registryDependencies: ["vform"]` and VForm has dependencies on all interface components.
391
+
392
+ ## Peer Dependencies
393
+
394
+ Components require these external packages:
395
+
396
+ **Core (always needed):**
397
+ ```bash
398
+ pnpm add @mantine/core @mantine/hooks react react-dom
399
+ ```
400
+
401
+ **Component-specific:**
402
+ ```bash
403
+ # DateTime component
404
+ pnpm add @mantine/dates dayjs
405
+
406
+ # Icon components
407
+ pnpm add @tabler/icons-react
408
+
409
+ # File upload
410
+ pnpm add @mantine/dropzone
411
+
412
+ # CollectionForm notifications
413
+ pnpm add @mantine/notifications
414
+
415
+ # Rich text editor
416
+ pnpm add @tiptap/react @tiptap/starter-kit @tiptap/extension-link
417
+ ```
418
+
419
+ **Utils (optional, for cn() helper):**
420
+ ```bash
421
+ pnpm add clsx tailwind-merge
422
+ ```
423
+
424
+ ## Project Structure After Installation
425
+
426
+ ```
427
+ your-project/
428
+ ├── app/
429
+ │ ├── api/
430
+ │ │ ├── auth/ # Auth proxy routes
431
+ │ │ │ ├── login/route.ts # POST - Supabase login
432
+ │ │ │ ├── logout/route.ts # POST - Sign out
433
+ │ │ │ ├── user/route.ts # GET - Current user info
434
+ │ │ │ └── callback/route.ts # GET - OAuth callback
435
+ │ │ ├── fields/[collection]/route.ts # Fields proxy
436
+ │ │ ├── items/[collection]/route.ts # Items proxy
437
+ │ │ └── ...
438
+ │ └── login/page.tsx # Login page template
439
+ ├── src/
440
+ │ ├── components/
441
+ │ │ └── ui/
442
+ │ │ ├── input.tsx
443
+ │ │ ├── select-dropdown.tsx
444
+ │ │ └── datetime.tsx
445
+ │ └── lib/
446
+ │ ├── buildpad/
447
+ │ │ ├── utils.ts
448
+ │ │ ├── types/
449
+ │ │ │ ├── index.ts
450
+ │ │ │ ├── core.ts
451
+ │ │ │ ├── file.ts
452
+ │ │ │ └── relations.ts
453
+ │ │ ├── services/
454
+ │ │ │ ├── index.ts
455
+ │ │ │ ├── api-request.ts
456
+ │ │ │ ├── items.ts
457
+ │ │ │ ├── fields.ts
458
+ │ │ │ └── collections.ts
459
+ │ │ └── hooks/
460
+ │ │ ├── index.ts
461
+ │ │ ├── useRelationM2M.ts
462
+ │ │ ├── useRelationM2O.ts
463
+ │ │ └── ...
464
+ │ ├── api/auth-headers.ts # Auth header utilities
465
+ │ └── supabase/ # Supabase client utilities
466
+ │ ├── server.ts
467
+ │ └── client.ts
468
+ ├── middleware.ts # Auth middleware
469
+ ├── buildpad.json
470
+ └── package.json
471
+ ```
472
+
473
+ ## CLI Commands Reference
474
+
475
+ ```bash
476
+ # Initialize project
477
+ buildpad init [--yes] [--cwd <path>]
478
+
479
+ # Bootstrap full project (init + add all + deps + validate)
480
+ buildpad bootstrap [--cwd <path>] [--skip-deps] [--skip-validate]
481
+
482
+ # Add components
483
+ buildpad add [components...] [--all] [--category <name>] [--overwrite] [--cwd <path>]
484
+
485
+ # List components
486
+ buildpad list [--category <name>] [--json]
487
+
488
+ # Preview changes
489
+ buildpad diff <component> [--cwd <path>]
490
+
491
+ # Validate installation
492
+ buildpad validate [--json] [--cwd <path>]
493
+
494
+ # Check installed components
495
+ buildpad status [--json] [--cwd <path>]
496
+
497
+ # Component info and dependency tree
498
+ buildpad info <component> [--json]
499
+ buildpad tree <component> [--json] [--depth <n>]
500
+
501
+ # Auto-fix common issues
502
+ buildpad fix [--dry-run] [--yes] [--cwd <path>]
503
+
504
+ # Check for component updates
505
+ buildpad outdated [--json] [--cwd <path>]
506
+ ```
507
+
508
+ ## Troubleshooting
509
+
510
+ ### "Registry file not found"
511
+
512
+ Make sure you're running the CLI from within the Buildpad workspace or have the registry properly configured.
513
+
514
+ ### "buildpad.json not found"
515
+
516
+ Run `npx @buildpad/cli init` first to initialize your project.
517
+
518
+ ### Import errors after adding components
519
+
520
+ Ensure your `tsconfig.json` has the correct path aliases:
521
+
522
+ ```json
523
+ {
524
+ "compilerOptions": {
525
+ "baseUrl": ".",
526
+ "paths": {
527
+ "@/*": ["./src/*"]
528
+ }
529
+ }
530
+ }
531
+ ```
532
+
533
+ ## Development
534
+
535
+ Build the CLI:
536
+
537
+ ```bash
538
+ cd packages/cli
539
+ pnpm build
540
+ ```
541
+
542
+ Run in development:
543
+
544
+ ```bash
545
+ pnpm dev
546
+ ```
547
+
548
+ Test locally:
549
+
550
+ ```bash
551
+ node dist/index.js init
552
+ node dist/index.js add input
553
+ ```
554
+
555
+ ## License
556
+
557
+ MIT