buildx-cli 1.0.9 → 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/README.md CHANGED
@@ -6,7 +6,8 @@ A command-line interface tool for BuildX API with authentication, project manage
6
6
 
7
7
  - **🔐 Authentication Management**: Secure login/logout with token validation
8
8
  - **📁 Project Management**: List, set default, and manage multiple projects
9
- - **🔄 Schema Synchronization**: Generate TypeScript types from API schema
9
+ - **🔄 Schema Synchronization**: Pull and push collections/types as code
10
+ - **⚡ Function Synchronization**: Pull and push function source files as code
10
11
  - **⚙️ Configuration Management**: Store settings or use environment variables
11
12
  - **🎯 Interactive CLI**: User-friendly command-line interface with prompts
12
13
 
@@ -48,9 +49,14 @@ yarn start --help
48
49
  npx buildx-cli projects:list
49
50
  ```
50
51
 
51
- 4. **Sync schema:**
52
+ 4. **Pull schema:**
52
53
  ```bash
53
- npx buildx-cli schema:sync --project-id <project-id>
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>
54
60
  ```
55
61
 
56
62
  ## Configuration
@@ -69,6 +75,28 @@ BUILDX_API_KEY=your-api-key
69
75
  BUILDX_PROJECT_ID=your-default-project-id
70
76
  ```
71
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
+
72
100
  ### Method 3: Command Line Options
73
101
  ```bash
74
102
  npx buildx-cli config:setup --endpoint https://api.example.com --api-key your-api-key
@@ -86,82 +114,307 @@ npx buildx-cli config:clear
86
114
 
87
115
  ## Commands
88
116
 
89
- ### Authentication Commands
117
+ ### Authentication
118
+
119
+ #### `auth:login`
120
+ Logs in with token or username/password interactively.
90
121
 
91
- #### Login
92
122
  ```bash
93
123
  npx buildx-cli auth:login
94
124
  ```
95
- Interactive login with username/password or token.
96
125
 
97
- #### Logout
126
+ #### `auth:logout`
127
+ Clears stored authentication.
128
+
98
129
  ```bash
99
130
  npx buildx-cli auth:logout
100
131
  ```
101
- Clear stored authentication.
102
132
 
103
- #### Check Status
133
+ #### `auth:status`
134
+ Shows current auth state and user details (if available).
135
+
104
136
  ```bash
105
137
  npx buildx-cli auth:status
106
138
  ```
107
- Display authentication status and user information.
108
139
 
109
- ### Project Management Commands
140
+ ### Projects
141
+
142
+ #### `projects:list`
143
+ Lists available projects for the authenticated account.
110
144
 
111
- #### List Projects
112
145
  ```bash
113
146
  npx buildx-cli projects:list
114
147
  ```
115
- Display all available projects.
116
148
 
117
- #### Set Default Project
149
+ #### `projects:set-default <project-id>`
150
+ Sets default project used by commands when `--project-id` is not provided.
151
+
118
152
  ```bash
119
- npx buildx-cli projects:set-default <project-id>
153
+ npx buildx-cli projects:set-default hello-world
120
154
  ```
121
- Set the default project for operations.
122
155
 
123
- #### Show Current Project
156
+ #### `projects:current`
157
+ Shows currently selected default project.
158
+
124
159
  ```bash
125
160
  npx buildx-cli projects:current
126
161
  ```
127
- Display the currently selected default project.
128
162
 
129
- ### Schema Synchronization Commands
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`
130
290
 
131
- #### Sync Schema
132
291
  ```bash
133
- npx buildx-cli schema:sync --project-id <project-id>
292
+ npx buildx-cli schema:diff --project-id hello-world --target-dir ./.sandbox/buildx-cli
134
293
  ```
135
294
 
136
- #### Sync with Custom Output
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
+
137
325
  ```bash
138
- npx buildx-cli schema:sync --project-id <project-id> --output ./src/types/generated.ts
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
139
328
  ```
140
329
 
141
- #### Sync with Custom API URL
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
+
142
367
  ```bash
143
- npx buildx-cli schema:sync --project-id <project-id> --api-url https://custom-api.example.com
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
144
394
  ```
145
395
 
146
396
  ### Configuration Commands
147
397
 
148
- #### Setup Configuration
398
+ #### `config:setup`
399
+ Interactive API configuration (`endpoint`, `api key`).
400
+
149
401
  ```bash
150
402
  npx buildx-cli config:setup
151
403
  ```
152
- Interactive configuration setup.
153
404
 
154
- #### Show Configuration
405
+ #### `config:show`
406
+ Displays current resolved configuration (use this to inspect configured API endpoint).
407
+
155
408
  ```bash
156
409
  npx buildx-cli config:show
157
410
  ```
158
- Display current configuration and sources.
159
411
 
160
- #### Clear Configuration
412
+ #### `config:clear`
413
+ Clears all saved CLI configuration.
414
+
161
415
  ```bash
162
416
  npx buildx-cli config:clear
163
417
  ```
164
- Clear all stored configuration.
165
418
 
166
419
  ## Configuration Sources
167
420
 
@@ -178,6 +431,11 @@ The CLI checks for configuration in this order:
178
431
  - `BUILDX_API_ENDPOINT` - Your API endpoint URL
179
432
  - `BUILDX_API_KEY` - Your API key
180
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
181
439
 
182
440
  ## API Endpoints
183
441
 
@@ -186,7 +444,13 @@ The CLI interacts with the following API endpoints:
186
444
  - `POST /auth/login` - User authentication
187
445
  - `GET /auth/me` - Get current user info
188
446
  - `GET /projects` - List user projects
189
- - `GET /project/:project_id/collections/schema` - Fetch project schema
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
190
454
 
191
455
  ## Development
192
456
 
@@ -238,8 +502,8 @@ export BUILDX_API_ENDPOINT=https://api.example.com
238
502
  export BUILDX_API_KEY=$CI_API_KEY
239
503
  export BUILDX_PROJECT_ID=$CI_PROJECT_ID
240
504
 
241
- # Run schema sync
242
- npx buildx-cli schema:sync --project-id $BUILDX_PROJECT_ID --output ./src/types/api.ts
505
+ # Run schema pull
506
+ npx buildx-cli schema:pull --project-id $BUILDX_PROJECT_ID --output ./src/types/api.ts
243
507
  ```
244
508
 
245
509
  ### Local Development
@@ -249,7 +513,23 @@ npx buildx-cli config:setup
249
513
 
250
514
  # Use regularly
251
515
  npx buildx-cli projects:list
252
- npx buildx-cli schema:sync --project-id my-project
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
253
533
  ```
254
534
 
255
535
  ## Contributing
@@ -263,4 +543,4 @@ npx buildx-cli schema:sync --project-id my-project
263
543
 
264
544
  ## License
265
545
 
266
- MIT License - see LICENSE file for details.
546
+ MIT License - see LICENSE file for details.