buildx-cli 1.0.10 → 1.0.11

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/dist/README.md ADDED
@@ -0,0 +1,546 @@
1
+ # BuildX CLI
2
+
3
+ A command-line interface tool for BuildX API with authentication, project management, and schema synchronization capabilities.
4
+
5
+ ## Features
6
+
7
+ - **🔐 Authentication Management**: Secure login/logout with token validation
8
+ - **📁 Project Management**: List, set default, and manage multiple projects
9
+ - **🔄 Schema Synchronization**: Pull and push collections/types as code
10
+ - **⚡ Function Synchronization**: Pull and push function source files as code
11
+ - **⚙️ Configuration Management**: Store settings or use environment variables
12
+ - **🎯 Interactive CLI**: User-friendly command-line interface with prompts
13
+
14
+ ## Installation
15
+
16
+ ### Using npx (Recommended)
17
+ ```bash
18
+ npx buildx-cli --help
19
+ ```
20
+
21
+ ### Global Installation
22
+ ```bash
23
+ npm install -g buildx-cli
24
+ ```
25
+
26
+ ### Local Development
27
+ ```bash
28
+ git clone <repository-url>
29
+ cd buildx-cli
30
+ yarn install
31
+ yarn build
32
+ yarn start --help
33
+ ```
34
+
35
+ ## Quick Start
36
+
37
+ 1. **Configure API settings:**
38
+ ```bash
39
+ npx buildx-cli config:setup
40
+ ```
41
+
42
+ 2. **Authenticate:**
43
+ ```bash
44
+ npx buildx-cli auth:login
45
+ ```
46
+
47
+ 3. **List projects:**
48
+ ```bash
49
+ npx buildx-cli projects:list
50
+ ```
51
+
52
+ 4. **Pull schema:**
53
+ ```bash
54
+ npx buildx-cli schema:pull --project-id <project-id>
55
+ ```
56
+
57
+ 5. **Pull function code:**
58
+ ```bash
59
+ npx buildx-cli function:pull --project-id <project-id>
60
+ ```
61
+
62
+ ## Configuration
63
+
64
+ ### Method 1: Interactive Setup
65
+ ```bash
66
+ npx buildx-cli config:setup
67
+ ```
68
+
69
+ ### Method 2: Environment Variables
70
+ Set these environment variables or add them to a `.env` file:
71
+
72
+ ```bash
73
+ BUILDX_API_ENDPOINT=https://api.example.com
74
+ BUILDX_API_KEY=your-api-key
75
+ BUILDX_PROJECT_ID=your-default-project-id
76
+ ```
77
+
78
+ Supported aliases (auto-resolved):
79
+
80
+ ```bash
81
+ NEXT_PUBLIC_API_ENDPOINT=
82
+ NEXT_PUBLIC_API_KEY=
83
+ NEXT_PUBLIC_BUILDX_PROJECT_ID=
84
+
85
+ NEXT_PUBLIC_BUILDX_API_ENDPOINT=
86
+ NEXT_PUBLIC_BUILDX_API_KEY=
87
+
88
+ BUILDX_API_ENDPOINT=
89
+ BUILDX_API_KEY=
90
+ BUILDX_PROJECT_ID=
91
+ ```
92
+
93
+ Resolution priority is strict-first:
94
+ - Endpoint: `BUILDX_API_ENDPOINT` -> `NEXT_PUBLIC_BUILDX_API_ENDPOINT` -> `NEXT_PUBLIC_API_ENDPOINT`
95
+ - API key: `BUILDX_API_KEY` -> `NEXT_PUBLIC_BUILDX_API_KEY` -> `NEXT_PUBLIC_API_KEY`
96
+ - Project ID: `BUILDX_PROJECT_ID` -> `NEXT_PUBLIC_BUILDX_PROJECT_ID`
97
+
98
+ When running `config:setup`, CLI auto-detects these values and asks for confirmation before using them.
99
+
100
+ ### Method 3: Command Line Options
101
+ ```bash
102
+ npx buildx-cli config:setup --endpoint https://api.example.com --api-key your-api-key
103
+ ```
104
+
105
+ ### View Current Configuration
106
+ ```bash
107
+ npx buildx-cli config:show
108
+ ```
109
+
110
+ ### Clear Configuration
111
+ ```bash
112
+ npx buildx-cli config:clear
113
+ ```
114
+
115
+ ## Commands
116
+
117
+ ### Authentication
118
+
119
+ #### `auth:login`
120
+ Logs in with token or username/password interactively.
121
+
122
+ ```bash
123
+ npx buildx-cli auth:login
124
+ ```
125
+
126
+ #### `auth:logout`
127
+ Clears stored authentication.
128
+
129
+ ```bash
130
+ npx buildx-cli auth:logout
131
+ ```
132
+
133
+ #### `auth:status`
134
+ Shows current auth state and user details (if available).
135
+
136
+ ```bash
137
+ npx buildx-cli auth:status
138
+ ```
139
+
140
+ ### Projects
141
+
142
+ #### `projects:list`
143
+ Lists available projects for the authenticated account.
144
+
145
+ ```bash
146
+ npx buildx-cli projects:list
147
+ ```
148
+
149
+ #### `projects:set-default <project-id>`
150
+ Sets default project used by commands when `--project-id` is not provided.
151
+
152
+ ```bash
153
+ npx buildx-cli projects:set-default hello-world
154
+ ```
155
+
156
+ #### `projects:current`
157
+ Shows currently selected default project.
158
+
159
+ ```bash
160
+ npx buildx-cli projects:current
161
+ ```
162
+
163
+ ### Schema Commands
164
+
165
+ #### `schema:pull`
166
+ Pulls schema artifacts from remote and writes local files.
167
+
168
+ Writes:
169
+ - `types.ts`
170
+ - `collections.json` (unless `--skip-collections-code`)
171
+ - `collections.manifest.json`
172
+
173
+ Key options:
174
+ - `-p, --project-id <id>`: project to sync from
175
+ - `-t, --target-dir <path>`: base output directory (recommended)
176
+ - `-o, --output <path>`: custom types path (when no `--target-dir`)
177
+ - `--collections-file <path>`: custom collections JSON path (when no `--target-dir`)
178
+ - `--filter <pattern...>`: include only matching collection IDs
179
+ - `--include-buildx`: include `buildx_*` collections
180
+ - `--skip-collections-code`: skip collections JSON/manifest output
181
+ - `--no-annotate-types`: disable `@bx.*` annotations injection into pulled `types.ts`
182
+ - `--dry-run`: print full file content previews without writing files
183
+ - `-f, --force`: overwrite even if local file drift is detected
184
+
185
+ ```bash
186
+ npx buildx-cli schema:pull --project-id hello-world --target-dir ./.sandbox/buildx-cli
187
+ npx buildx-cli schema:pull --project-id hello-world --dry-run
188
+ ```
189
+
190
+ `schema:sync` is still available as a compatibility alias (deprecated).
191
+
192
+ #### `schema:push`
193
+ Pushes local `collections.json` back to remote project.
194
+
195
+ Reads:
196
+ - `collections.json`
197
+ - `collections.manifest.json` (for drift checks)
198
+
199
+ Behavior:
200
+ - validates minimum shape (`collection_id`, `form_schema`)
201
+ - compares local checksum vs remote checksum
202
+ - skips remote-drift conflicts unless `--force`
203
+
204
+ Key options:
205
+ - `-p, --project-id <id>`
206
+ - `-t, --target-dir <path>`
207
+ - `--collections-file <path>` (when no `--target-dir`)
208
+ - `--filter <pattern...>`
209
+ - `--dry-run`
210
+ - `-f, --force`
211
+
212
+ ```bash
213
+ npx buildx-cli schema:push --project-id hello-world --target-dir ./.sandbox/buildx-cli --dry-run
214
+ ```
215
+
216
+ #### `schema:types:convert`
217
+ Converts a local `types.ts` file into collections JSON first, so you can review before push.
218
+
219
+ Reads:
220
+ - `types.ts` (or `--types-file`)
221
+ - base `collections.json` to preserve metadata (required by default)
222
+
223
+ Writes:
224
+ - `collections.json` (or `--collections-file`)
225
+
226
+ Key options:
227
+ - `-t, --target-dir <path>`
228
+ - `--types-file <path>`
229
+ - `--collections-file <path>`
230
+ - `--base-collections-file <path>`
231
+ - `--no-allow-lossy` (strict mode: require base metadata file)
232
+ - `--filter <pattern...>`
233
+ - `--dry-run`
234
+
235
+ Field annotations (JSDoc in `types.ts`) are supported:
236
+ - `@bx.title <text>`
237
+ - `@bx.description <text>`
238
+ - `@bx.required` or `@bx.required false`
239
+ - `@bx.ref <collection_id_or_enum_key>`
240
+ - `@bx.choices value1:Label 1|value2:Label 2` (for `Choices`/`MultipleChoices`)
241
+
242
+ Example:
243
+ ```ts
244
+ export type Employees = {
245
+ /** @bx.title Employment status @bx.choices active:Active|on_leave:On Leave */
246
+ status?: BxChoices;
247
+ /** @bx.required */
248
+ employee_id?: BxText;
249
+ /** @bx.ref departments @bx.title Department */
250
+ department?: Partial<Departments> | BxDataObject;
251
+ };
252
+ ```
253
+
254
+ ```bash
255
+ npx buildx-cli schema:types:convert --target-dir ./.sandbox/buildx-cli --dry-run
256
+ npx buildx-cli schema:types:convert --target-dir ./.sandbox/buildx-cli
257
+ npx buildx-cli schema:push --collections-file ./.sandbox/buildx-cli/collections.json --project-id hello-world --dry-run
258
+ ```
259
+
260
+ #### `schema:list`
261
+ Lists remote collections.
262
+
263
+ Key options:
264
+ - `-p, --project-id <id>`
265
+ - `--filter <pattern...>`
266
+ - `--include-buildx`
267
+
268
+ ```bash
269
+ npx buildx-cli schema:list --project-id hello-world --filter "user*"
270
+ ```
271
+
272
+ #### `schema:diff`
273
+ Diffs local collections against remote by `collection_id`.
274
+
275
+ Reads:
276
+ - local `collections.json`
277
+
278
+ Output markers:
279
+ - `= same`
280
+ - `~ changed`
281
+ - `+ local-only`
282
+ - `- remote-only`
283
+
284
+ Key options:
285
+ - `-p, --project-id <id>`
286
+ - `-t, --target-dir <path>`
287
+ - `--collections-file <path>` (when no `--target-dir`)
288
+ - `--filter <pattern...>`
289
+ - `--include-buildx`
290
+
291
+ ```bash
292
+ npx buildx-cli schema:diff --project-id hello-world --target-dir ./.sandbox/buildx-cli
293
+ ```
294
+
295
+ ### Function Commands
296
+
297
+ #### `function:pull`
298
+ Pulls function context schema and function source code from remote.
299
+
300
+ Writes:
301
+ - `function-context.d.ts`
302
+ - `functions/*.ts`
303
+ - `functions/functions.manifest.json`
304
+
305
+ Behavior:
306
+ - writes a compact `function-context.d.ts` by default (use `--full-context` to keep full remote schema)
307
+ - preserves remote function code as-is by default (safe with existing runtime)
308
+ - optional `--module-wrap` can normalize arrow-function code into module format (`export default`) for local tooling
309
+ - skips overwriting local edited files unless `--force`
310
+ - supports dry-run file content previews
311
+
312
+ Key options:
313
+ - `-p, --project-id <id>`
314
+ - `-t, --target-dir <path>`
315
+ - `--context-output <path>` (when no `--target-dir`)
316
+ - `--functions-dir <path>` (when no `--target-dir`)
317
+ - `--filter <pattern...>`
318
+ - `--full-context`
319
+ - `--module-wrap`
320
+ - `--no-validate-code`
321
+ - `--no-lint`
322
+ - `--dry-run`
323
+ - `-f, --force`
324
+
325
+ ```bash
326
+ npx buildx-cli function:pull --project-id hello-world --target-dir ./.sandbox/buildx-cli
327
+ npx buildx-cli function:pull --project-id hello-world --dry-run
328
+ ```
329
+
330
+ `function:sync` is still available as a compatibility alias (deprecated).
331
+
332
+ #### `function:push`
333
+ Pushes local function source files back to remote.
334
+
335
+ Reads:
336
+ - `functions/*.ts`
337
+ - `functions/functions.manifest.json`
338
+
339
+ Behavior:
340
+ - checks remote drift against manifest baseline
341
+ - validates local function code compatibility before push (can bypass via `--no-validate-code`)
342
+ - runs basic syntax lint before push (can bypass via `--no-lint`)
343
+ - skips conflicts unless `--force`
344
+
345
+ Key options:
346
+ - `-p, --project-id <id>`
347
+ - `-t, --target-dir <path>`
348
+ - `--functions-dir <path>` (when no `--target-dir`)
349
+ - `-n, --name <function-name>` for a single function
350
+ - `--filter <pattern...>`
351
+ - `--no-validate-code`
352
+ - `--no-lint`
353
+ - `--dry-run`
354
+ - `-f, --force`
355
+
356
+ ```bash
357
+ npx buildx-cli function:push --project-id hello-world --target-dir ./.sandbox/buildx-cli --dry-run
358
+ ```
359
+
360
+ #### `function:list`
361
+ Lists remote function names.
362
+
363
+ Key options:
364
+ - `-p, --project-id <id>`
365
+ - `--filter <pattern...>`
366
+
367
+ ```bash
368
+ npx buildx-cli function:list --project-id hello-world --filter "send*"
369
+ ```
370
+
371
+ #### `function:diff`
372
+ Diffs local function sources against remote.
373
+
374
+ Reads:
375
+ - local `functions/*.ts`
376
+ - `functions/functions.manifest.json`
377
+
378
+ Output markers:
379
+ - `= same`
380
+ - `~ changed`
381
+ - `+ local-missing`
382
+ - `- remote-missing`
383
+ - `! remote-drift`
384
+
385
+ Key options:
386
+ - `-p, --project-id <id>`
387
+ - `-t, --target-dir <path>`
388
+ - `--functions-dir <path>` (when no `--target-dir`)
389
+ - `-n, --name <function-name>`
390
+ - `--filter <pattern...>`
391
+
392
+ ```bash
393
+ npx buildx-cli function:diff --project-id hello-world --target-dir ./.sandbox/buildx-cli
394
+ ```
395
+
396
+ ### Configuration Commands
397
+
398
+ #### `config:setup`
399
+ Interactive API configuration (`endpoint`, `api key`).
400
+
401
+ ```bash
402
+ npx buildx-cli config:setup
403
+ ```
404
+
405
+ #### `config:show`
406
+ Displays current resolved configuration (use this to inspect configured API endpoint).
407
+
408
+ ```bash
409
+ npx buildx-cli config:show
410
+ ```
411
+
412
+ #### `config:clear`
413
+ Clears all saved CLI configuration.
414
+
415
+ ```bash
416
+ npx buildx-cli config:clear
417
+ ```
418
+
419
+ ## Configuration Sources
420
+
421
+ The CLI checks for configuration in this order:
422
+
423
+ 1. **Stored Configuration** (via `config:setup`)
424
+ 2. **Environment Variables** (`BUILDX_API_ENDPOINT`, `BUILDX_API_KEY`)
425
+ 3. **`.env` File** (in current directory)
426
+
427
+ ### Configuration File Location
428
+ - **Global config**: `~/.config/buildx-cli-nodejs/config.json`
429
+
430
+ ### Environment Variables
431
+ - `BUILDX_API_ENDPOINT` - Your API endpoint URL
432
+ - `BUILDX_API_KEY` - Your API key
433
+ - `BUILDX_PROJECT_ID` - Default project ID (optional)
434
+ - `NEXT_PUBLIC_BUILDX_API_ENDPOINT` - Alias for API endpoint
435
+ - `NEXT_PUBLIC_API_ENDPOINT` - Alias for API endpoint
436
+ - `NEXT_PUBLIC_BUILDX_API_KEY` - Alias for API key
437
+ - `NEXT_PUBLIC_API_KEY` - Alias for API key
438
+ - `NEXT_PUBLIC_BUILDX_PROJECT_ID` - Alias for default project ID
439
+
440
+ ## API Endpoints
441
+
442
+ The CLI interacts with the following API endpoints:
443
+
444
+ - `POST /auth/login` - User authentication
445
+ - `GET /auth/me` - Get current user info
446
+ - `GET /projects` - List user projects
447
+ - `GET /project/:project_id/collections/schema` - Fetch project schema types
448
+ - `GET /project/:project_id/collections` - Fetch collections as code
449
+ - `POST /project/:project_id/collections` - Upsert collection
450
+ - `GET /project/:project_id/functions/context/schema/info` - Fetch function context schema info
451
+ - `GET /project/:project_id/functions` - List functions
452
+ - `GET /project/:project_id/functions/:function_name` - Fetch function source
453
+ - `POST /project/:project_id/functions/:function_name` - Upsert function source
454
+
455
+ ## Development
456
+
457
+ ### Project Structure
458
+
459
+ ```
460
+ src/
461
+ ├── commands/ # CLI commands
462
+ │ ├── auth/ # Authentication commands
463
+ │ ├── config/ # Configuration commands
464
+ │ ├── projects/ # Project management commands
465
+ │ └── sync.ts # Schema synchronization
466
+ ├── services/ # Business logic services
467
+ ├── types/ # TypeScript type definitions
468
+ ├── utils/ # Utility functions
469
+ ├── config/ # Configuration management
470
+ └── index.ts # Main entry point
471
+ ```
472
+
473
+ ### Available Scripts
474
+
475
+ ```bash
476
+ yarn build # Build the project
477
+ yarn dev # Run in development mode
478
+ yarn start # Run built version
479
+ yarn test # Run tests
480
+ yarn lint # Run linter
481
+ yarn format # Format code
482
+ ```
483
+
484
+ ### Building
485
+
486
+ ```bash
487
+ yarn build
488
+ ```
489
+
490
+ ### Development Mode
491
+
492
+ ```bash
493
+ yarn dev
494
+ ```
495
+
496
+ ## Examples
497
+
498
+ ### CI/CD Pipeline
499
+ ```bash
500
+ # Set environment variables
501
+ export BUILDX_API_ENDPOINT=https://api.example.com
502
+ export BUILDX_API_KEY=$CI_API_KEY
503
+ export BUILDX_PROJECT_ID=$CI_PROJECT_ID
504
+
505
+ # Run schema pull
506
+ npx buildx-cli schema:pull --project-id $BUILDX_PROJECT_ID --output ./src/types/api.ts
507
+ ```
508
+
509
+ ### Local Development
510
+ ```bash
511
+ # Setup once
512
+ npx buildx-cli config:setup
513
+
514
+ # Use regularly
515
+ npx buildx-cli projects:list
516
+ npx buildx-cli schema:pull --project-id my-project
517
+ npx buildx-cli function:pull --project-id my-project
518
+ ```
519
+
520
+ ### Monorepo Local Shortcuts (No Publish)
521
+ From monorepo root:
522
+
523
+ ```bash
524
+ yarn cli:build
525
+ yarn cli --help
526
+ ```
527
+
528
+ Isolated test output:
529
+
530
+ ```bash
531
+ yarn cli -- schema:pull --project-id my-project --target-dir ./.sandbox/buildx-cli
532
+ yarn cli -- function:pull --project-id my-project --target-dir ./.sandbox/buildx-cli
533
+ ```
534
+
535
+ ## Contributing
536
+
537
+ 1. Fork the repository
538
+ 2. Create a feature branch
539
+ 3. Make your changes
540
+ 4. Add tests for new functionality
541
+ 5. Run the test suite
542
+ 6. Submit a pull request
543
+
544
+ ## License
545
+
546
+ MIT License - see LICENSE file for details.