@sanity/runtime-cli 12.3.0 → 12.4.0

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 (71) hide show
  1. package/README.md +32 -31
  2. package/dist/actions/blueprints/assets.js +7 -1
  3. package/dist/baseCommands.d.ts +43 -7
  4. package/dist/baseCommands.js +82 -10
  5. package/dist/commands/blueprints/add.d.ts +2 -2
  6. package/dist/commands/blueprints/add.js +2 -2
  7. package/dist/commands/blueprints/config.d.ts +2 -2
  8. package/dist/commands/blueprints/config.js +2 -2
  9. package/dist/commands/blueprints/deploy.d.ts +2 -2
  10. package/dist/commands/blueprints/deploy.js +2 -2
  11. package/dist/commands/blueprints/destroy.d.ts +2 -2
  12. package/dist/commands/blueprints/destroy.js +2 -2
  13. package/dist/commands/blueprints/doctor.d.ts +5 -4
  14. package/dist/commands/blueprints/doctor.js +10 -12
  15. package/dist/commands/blueprints/info.d.ts +2 -2
  16. package/dist/commands/blueprints/info.js +2 -2
  17. package/dist/commands/blueprints/init.d.ts +2 -2
  18. package/dist/commands/blueprints/init.js +6 -9
  19. package/dist/commands/blueprints/logs.d.ts +2 -2
  20. package/dist/commands/blueprints/logs.js +2 -2
  21. package/dist/commands/blueprints/plan.d.ts +2 -2
  22. package/dist/commands/blueprints/plan.js +2 -2
  23. package/dist/commands/blueprints/stacks.d.ts +2 -2
  24. package/dist/commands/blueprints/stacks.js +2 -2
  25. package/dist/commands/functions/add.d.ts +2 -2
  26. package/dist/commands/functions/add.js +2 -2
  27. package/dist/commands/functions/dev.d.ts +2 -2
  28. package/dist/commands/functions/dev.js +2 -2
  29. package/dist/commands/functions/env/add.d.ts +2 -2
  30. package/dist/commands/functions/env/add.js +2 -2
  31. package/dist/commands/functions/env/list.d.ts +2 -2
  32. package/dist/commands/functions/env/list.js +2 -2
  33. package/dist/commands/functions/env/remove.d.ts +2 -2
  34. package/dist/commands/functions/env/remove.js +2 -2
  35. package/dist/commands/functions/logs.d.ts +3 -3
  36. package/dist/commands/functions/logs.js +7 -4
  37. package/dist/commands/functions/test.d.ts +3 -3
  38. package/dist/commands/functions/test.js +7 -4
  39. package/dist/cores/blueprints/config.d.ts +2 -5
  40. package/dist/cores/blueprints/deploy.js +0 -1
  41. package/dist/cores/blueprints/destroy.d.ts +2 -5
  42. package/dist/cores/blueprints/doctor.js +12 -2
  43. package/dist/cores/blueprints/info.js +2 -2
  44. package/dist/cores/blueprints/stacks.d.ts +2 -5
  45. package/dist/cores/functions/logs.d.ts +3 -1
  46. package/dist/cores/functions/logs.js +11 -2
  47. package/dist/cores/functions/test.d.ts +3 -1
  48. package/dist/cores/functions/test.js +11 -2
  49. package/dist/server/static/components/app.css +0 -116
  50. package/dist/server/static/components/clear-button.js +1 -1
  51. package/dist/server/static/components/console-panel.js +27 -6
  52. package/dist/server/static/components/fetch-button.js +1 -1
  53. package/dist/server/static/components/filter-api-version.js +39 -3
  54. package/dist/server/static/components/filter-document-id.js +39 -3
  55. package/dist/server/static/components/filter-with-token.js +27 -4
  56. package/dist/server/static/components/filters.js +127 -62
  57. package/dist/server/static/components/function-list.js +33 -13
  58. package/dist/server/static/components/network-spinner.js +6 -4
  59. package/dist/server/static/components/payload-panel.js +46 -24
  60. package/dist/server/static/components/response-panel.js +33 -6
  61. package/dist/server/static/components/rule-panel.js +13 -4
  62. package/dist/server/static/components/run-panel.js +14 -7
  63. package/dist/server/static/components/select-dropdown.js +34 -5
  64. package/dist/server/static/components/shared-styles.js +31 -0
  65. package/dist/server/static/components/toggle-switch.js +11 -2
  66. package/dist/utils/display/blueprints-formatting.d.ts +2 -2
  67. package/dist/utils/display/blueprints-formatting.js +31 -26
  68. package/dist/utils/find-function.d.ts +4 -0
  69. package/dist/utils/find-function.js +6 -0
  70. package/oclif.manifest.json +281 -38
  71. package/package.json +2 -2
package/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
20
20
  $ sanity-run COMMAND
21
21
  running command...
22
22
  $ sanity-run (--version)
23
- @sanity/runtime-cli/12.3.0 linux-x64 node-v24.11.1
23
+ @sanity/runtime-cli/12.4.0 linux-x64 node-v24.12.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -44,8 +44,8 @@ USAGE
44
44
  * [`sanity-run functions env add NAME KEY VALUE`](#sanity-run-functions-env-add-name-key-value)
45
45
  * [`sanity-run functions env list NAME`](#sanity-run-functions-env-list-name)
46
46
  * [`sanity-run functions env remove NAME KEY`](#sanity-run-functions-env-remove-name-key)
47
- * [`sanity-run functions logs NAME`](#sanity-run-functions-logs-name)
48
- * [`sanity-run functions test NAME`](#sanity-run-functions-test-name)
47
+ * [`sanity-run functions logs [NAME]`](#sanity-run-functions-logs-name)
48
+ * [`sanity-run functions test [NAME]`](#sanity-run-functions-test-name)
49
49
  * [`sanity-run help [COMMAND]`](#sanity-run-help-command)
50
50
 
51
51
  ## `sanity-run blueprints add TYPE`
@@ -92,7 +92,7 @@ EXAMPLES
92
92
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
93
93
  ```
94
94
 
95
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/blueprints/add.ts)_
95
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/blueprints/add.ts)_
96
96
 
97
97
  ## `sanity-run blueprints config`
98
98
 
@@ -121,7 +121,7 @@ EXAMPLES
121
121
  $ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
122
122
  ```
123
123
 
124
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/blueprints/config.ts)_
124
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/blueprints/config.ts)_
125
125
 
126
126
  ## `sanity-run blueprints deploy`
127
127
 
@@ -143,7 +143,7 @@ EXAMPLES
143
143
  $ sanity-run blueprints deploy --no-wait
144
144
  ```
145
145
 
146
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/blueprints/deploy.ts)_
146
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/blueprints/deploy.ts)_
147
147
 
148
148
  ## `sanity-run blueprints destroy`
149
149
 
@@ -170,7 +170,7 @@ EXAMPLES
170
170
  $ sanity-run blueprints destroy --stack-id <stackId> --project-id <projectId> --force --no-wait
171
171
  ```
172
172
 
173
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/blueprints/destroy.ts)_
173
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/blueprints/destroy.ts)_
174
174
 
175
175
  ## `sanity-run blueprints doctor`
176
176
 
@@ -178,18 +178,19 @@ Diagnose potential issues with Blueprint configuration
178
178
 
179
179
  ```
180
180
  USAGE
181
- $ sanity-run blueprints doctor [--verbose] [--path <value>] [--fix]
181
+ $ sanity-run blueprints doctor [--json] [--path <value>] [--verbose] [--fix]
182
182
 
183
183
  FLAGS
184
184
  --fix Interactively fix configuration issues
185
- --path=<value> Path to the Blueprint configuration file
186
- --verbose Provide detailed information about issues
185
+ --json Format output as json.
186
+ --path=<value> Path to the directory containing the Blueprint
187
+ --verbose Verbose output
187
188
 
188
189
  DESCRIPTION
189
190
  Diagnose potential issues with Blueprint configuration
190
191
  ```
191
192
 
192
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/blueprints/doctor.ts)_
193
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/blueprints/doctor.ts)_
193
194
 
194
195
  ## `sanity-run blueprints info`
195
196
 
@@ -211,7 +212,7 @@ EXAMPLES
211
212
  $ sanity-run blueprints info --id <stackId>
212
213
  ```
213
214
 
214
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/blueprints/info.ts)_
215
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/blueprints/info.ts)_
215
216
 
216
217
  ## `sanity-run blueprints init [DIR]`
217
218
 
@@ -219,8 +220,8 @@ Initialize a new Blueprint Stack deployment
219
220
 
220
221
  ```
221
222
  USAGE
222
- $ sanity-run blueprints init [DIR] [--dir <value>] [--example <value> | --blueprint-type json|js|ts | --stack-id
223
- <value> | --stack-name <value>] [--project-id <value>] [--organization-id <value>] [--verbose]
223
+ $ sanity-run blueprints init [DIR] [--verbose] [--dir <value>] [--example <value> | --blueprint-type json|js|ts |
224
+ --stack-id <value> | --stack-name <value>] [--project-id <value>] [--organization-id <value>]
224
225
 
225
226
  ARGUMENTS
226
227
  [DIR] Directory to create the Blueprint in
@@ -251,7 +252,7 @@ EXAMPLES
251
252
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
252
253
  ```
253
254
 
254
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/blueprints/init.ts)_
255
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/blueprints/init.ts)_
255
256
 
256
257
  ## `sanity-run blueprints logs`
257
258
 
@@ -273,7 +274,7 @@ EXAMPLES
273
274
  $ sanity-run blueprints logs --watch
274
275
  ```
275
276
 
276
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/blueprints/logs.ts)_
277
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/blueprints/logs.ts)_
277
278
 
278
279
  ## `sanity-run blueprints plan`
279
280
 
@@ -290,7 +291,7 @@ EXAMPLES
290
291
  $ sanity-run blueprints plan
291
292
  ```
292
293
 
293
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/blueprints/plan.ts)_
294
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/blueprints/plan.ts)_
294
295
 
295
296
  ## `sanity-run blueprints stacks`
296
297
 
@@ -315,7 +316,7 @@ EXAMPLES
315
316
  $ sanity-run blueprints stacks --organization-id <organizationId>
316
317
  ```
317
318
 
318
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/blueprints/stacks.ts)_
319
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/blueprints/stacks.ts)_
319
320
 
320
321
  ## `sanity-run functions add`
321
322
 
@@ -357,7 +358,7 @@ EXAMPLES
357
358
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
358
359
  ```
359
360
 
360
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/functions/add.ts)_
361
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/functions/add.ts)_
361
362
 
362
363
  ## `sanity-run functions dev`
363
364
 
@@ -380,7 +381,7 @@ EXAMPLES
380
381
  $ sanity-run functions dev --host 127.0.0.1 --port 8974
381
382
  ```
382
383
 
383
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/functions/dev.ts)_
384
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/functions/dev.ts)_
384
385
 
385
386
  ## `sanity-run functions env add NAME KEY VALUE`
386
387
 
@@ -402,7 +403,7 @@ EXAMPLES
402
403
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
403
404
  ```
404
405
 
405
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/functions/env/add.ts)_
406
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/functions/env/add.ts)_
406
407
 
407
408
  ## `sanity-run functions env list NAME`
408
409
 
@@ -422,7 +423,7 @@ EXAMPLES
422
423
  $ sanity-run functions env list MyFunction
423
424
  ```
424
425
 
425
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/functions/env/list.ts)_
426
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/functions/env/list.ts)_
426
427
 
427
428
  ## `sanity-run functions env remove NAME KEY`
428
429
 
@@ -443,18 +444,18 @@ EXAMPLES
443
444
  $ sanity-run functions env remove MyFunction API_URL
444
445
  ```
445
446
 
446
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/functions/env/remove.ts)_
447
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/functions/env/remove.ts)_
447
448
 
448
- ## `sanity-run functions logs NAME`
449
+ ## `sanity-run functions logs [NAME]`
449
450
 
450
451
  Retrieve or delete logs for a Sanity Function
451
452
 
452
453
  ```
453
454
  USAGE
454
- $ sanity-run functions logs NAME [-u] [-f [-d | -l <value> | -j]] [-w]
455
+ $ sanity-run functions logs [NAME] [-u] [-f [-d | -l <value> | -j]] [-w]
455
456
 
456
457
  ARGUMENTS
457
- NAME The name of the Sanity Function
458
+ [NAME] The name of the Sanity Function
458
459
 
459
460
  FLAGS
460
461
  -d, --delete Delete all logs for the function
@@ -477,21 +478,21 @@ EXAMPLES
477
478
  $ sanity-run functions logs <name> --delete
478
479
  ```
479
480
 
480
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/functions/logs.ts)_
481
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/functions/logs.ts)_
481
482
 
482
- ## `sanity-run functions test NAME`
483
+ ## `sanity-run functions test [NAME]`
483
484
 
484
485
  Invoke a local Sanity Function
485
486
 
486
487
  ```
487
488
  USAGE
488
- $ sanity-run functions test NAME [--data-before <value> | [-d <value> | -f <value> | --document-id <value>] | |
489
+ $ sanity-run functions test [NAME] [--data-before <value> | [-d <value> | -f <value> | --document-id <value>] | |
489
490
  | --file-before <value> | --file-after <value> | --document-id-before <value> | --document-id-after <value>]
490
491
  [--data-after <value> | | | | | | | ] [-e create|update|delete] [-t <value>] [-a <value>] [--organization-id
491
492
  <value>] [--with-user-token] [--media-library-id <value> | --project-id <value> | --dataset <value>]
492
493
 
493
494
  ARGUMENTS
494
- NAME The name of the Sanity Function
495
+ [NAME] The name of the Sanity Function
495
496
 
496
497
  FLAGS
497
498
  -a, --api=<value> Sanity API Version to use
@@ -526,7 +527,7 @@ EXAMPLES
526
527
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
527
528
  ```
528
529
 
529
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v12.3.0/src/commands/functions/test.ts)_
530
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v12.4.0/src/commands/functions/test.ts)_
530
531
 
531
532
  ## `sanity-run help [COMMAND]`
532
533
 
@@ -21,6 +21,7 @@ export async function stashAsset({ resource, auth, }) {
21
21
  const isCollection = isLocalFunctionCollection(resource);
22
22
  const functions = isCollection ? resource.functions : [resource];
23
23
  const combinedAsset = [];
24
+ const prepareErrors = [];
24
25
  try {
25
26
  for (const func of functions) {
26
27
  const prepResult = await prepareAsset({ resource: func, auth });
@@ -30,13 +31,18 @@ export async function stashAsset({ resource, auth, }) {
30
31
  partAsset: { outputPath: prepResult.outputPath, cleanup: prepResult.cleanup },
31
32
  });
32
33
  }
34
+ else if (prepResult.error) {
35
+ prepareErrors.push({ name: func.name, error: prepResult.error });
36
+ }
33
37
  }
34
38
  if (combinedAsset.length !== functions.length) {
35
39
  const processedNames = new Set(combinedAsset.map((asset) => asset.name));
36
40
  const failedFunctions = functions.filter((func) => !processedNames.has(func.name));
41
+ const failedNames = failedFunctions.map((f) => f.name).join(', ');
42
+ const errorDetails = prepareErrors.map((e) => `${e.name}: ${e.error}`).join('; ');
37
43
  return {
38
44
  success: false,
39
- error: `Failed to prepare ${failedFunctions.length} function(s) in collection: ${failedFunctions.map((f) => f.name).join(', ')}`,
45
+ error: `Failed to prepare ${failedFunctions.length} function(s) in blueprint: ${failedNames}${errorDetails ? `. Details: ${errorDetails}` : ''}`,
40
46
  };
41
47
  }
42
48
  let result = { success: false };
@@ -2,19 +2,53 @@ import type { Interfaces } from '@oclif/core';
2
2
  import { Command } from '@oclif/core';
3
3
  import type { ReadBlueprintResult } from './actions/blueprints/blueprint.js';
4
4
  import type { AuthParams, ScopeType, Stack } from './utils/types.js';
5
- export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BlueprintCommand)['baseFlags'] & T['flags']>;
5
+ export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof RuntimeCommand)['baseFlags'] & T['flags']>;
6
6
  export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
7
+ export declare const baseFlags: {
8
+ json: Interfaces.BooleanFlag<boolean>;
9
+ path: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
10
+ verbose: Interfaces.BooleanFlag<boolean>;
11
+ };
12
+ /**
13
+ * @description Unhides a flag by setting its hidden property to false
14
+ * Also makes oclif's types happy when destructuring the flag
15
+ */
16
+ export declare function unhide<T>(flag: T): T;
17
+ /**
18
+ * @description Guarantees flags and args.
19
+ * Also centralizes baseFlags and enables oclif's built-in --json for all subclasses.
20
+ * @extends Command
21
+ */
22
+ export declare abstract class RuntimeCommand<T extends typeof Command> extends Command {
23
+ protected flags: Flags<T>;
24
+ protected args: Args<T>;
25
+ static baseFlags: {
26
+ json: Interfaces.BooleanFlag<boolean>;
27
+ path: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
28
+ verbose: Interfaces.BooleanFlag<boolean>;
29
+ };
30
+ static enableJsonFlag: boolean;
31
+ /**
32
+ * Generates help text for this command class
33
+ * @param bin - The bin name to use for the help text; e.g. 'sanity', defaults to 'sanity-run'
34
+ * @param commandId - The sub-command to use for the help text; optional but recommended for better help text
35
+ * @returns The oclif-styled help text for the command
36
+ * @example const helpText = InfoCommand.getHelpText('sanity', 'blueprints info')
37
+ */
38
+ static getHelpText(bin?: string, commandId?: string): string;
39
+ init(): Promise<void>;
40
+ }
7
41
  /**
8
42
  * @description Guarantees flags, args, sanityToken, and blueprint.
9
43
  * Blueprint parser errors are logged and the command exits with an error
10
- * @extends Command
44
+ * @extends RuntimeCommand
11
45
  */
12
- export declare abstract class BlueprintCommand<T extends typeof Command> extends Command {
46
+ export declare abstract class LocalBlueprintCommand<T extends typeof Command> extends RuntimeCommand<T> {
13
47
  protected sanityToken: string;
14
48
  protected blueprint: ReadBlueprintResult;
15
- protected flags: Flags<T>;
16
- protected args: Args<T>;
17
49
  static baseFlags: {
50
+ json: Interfaces.BooleanFlag<boolean>;
51
+ path: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
18
52
  verbose: Interfaces.BooleanFlag<boolean>;
19
53
  };
20
54
  init(): Promise<void>;
@@ -26,15 +60,17 @@ export declare abstract class BlueprintCommand<T extends typeof Command> extends
26
60
  /**
27
61
  * @description Guarantees flags, args, sanityToken, blueprint, scopeType, scopeId, stackId, auth, and deployedStack.
28
62
  * If scope or stack is missing, the command exits with an error
29
- * @extends BlueprintCommand
63
+ * @extends LocalBlueprintCommand
30
64
  */
31
- export declare abstract class DeployedBlueprintCommand<T extends typeof Command> extends BlueprintCommand<T> {
65
+ export declare abstract class DeployedStackCommand<T extends typeof Command> extends LocalBlueprintCommand<T> {
32
66
  protected auth: AuthParams;
33
67
  protected deployedStack: Stack;
34
68
  protected scopeType: ScopeType;
35
69
  protected scopeId: string;
36
70
  protected stackId: string;
37
71
  static baseFlags: {
72
+ json: Interfaces.BooleanFlag<boolean>;
73
+ path: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
38
74
  verbose: Interfaces.BooleanFlag<boolean>;
39
75
  };
40
76
  init(): Promise<void>;
@@ -1,24 +1,83 @@
1
1
  // * https://oclif.io/docs/base_class
2
- import { Command, Flags as OclifFlags } from '@oclif/core';
2
+ import { Command, CommandHelp, Flags as OclifFlags } from '@oclif/core';
3
3
  import { initBlueprintConfig, initDeployedBlueprintConfig } from './cores/index.js';
4
- const baseFlags = {
4
+ const hidden = true;
5
+ export const baseFlags = {
6
+ json: OclifFlags.boolean({
7
+ // override defaults from oclif's built-in --json flag
8
+ description: 'Format output as json.',
9
+ hidden,
10
+ }),
11
+ path: OclifFlags.string({
12
+ description: 'Path to the directory containing the Blueprint',
13
+ hidden,
14
+ }),
5
15
  verbose: OclifFlags.boolean({
6
16
  description: 'Verbose output',
7
17
  default: false,
8
- hidden: true, // prevent help output on all commands
18
+ hidden,
9
19
  }),
10
20
  };
11
21
  /**
12
- * @description Guarantees flags, args, sanityToken, and blueprint.
13
- * Blueprint parser errors are logged and the command exits with an error
22
+ * @description Unhides a flag by setting its hidden property to false
23
+ * Also makes oclif's types happy when destructuring the flag
24
+ */
25
+ export function unhide(flag) {
26
+ return { ...flag, hidden: false };
27
+ }
28
+ /**
29
+ * @description Guarantees flags and args.
30
+ * Also centralizes baseFlags and enables oclif's built-in --json for all subclasses.
14
31
  * @extends Command
15
32
  */
16
- export class BlueprintCommand extends Command {
17
- sanityToken;
18
- blueprint;
33
+ export class RuntimeCommand extends Command {
19
34
  flags;
20
35
  args;
21
36
  static baseFlags = baseFlags;
37
+ static enableJsonFlag = true; // oclif's built-in --json flag
38
+ /**
39
+ * Generates help text for this command class
40
+ * @param bin - The bin name to use for the help text; e.g. 'sanity', defaults to 'sanity-run'
41
+ * @param commandId - The sub-command to use for the help text; optional but recommended for better help text
42
+ * @returns The oclif-styled help text for the command
43
+ * @example const helpText = InfoCommand.getHelpText('sanity', 'blueprints info')
44
+ */
45
+ static getHelpText(bin = 'sanity-run', commandId) {
46
+ // biome-ignore lint/complexity/noThisInStatic: this is this command class - not confusing
47
+ const thisClass = this;
48
+ const rawArgs = thisClass.args || {};
49
+ const args = Object.entries(rawArgs).reduce((acc, [name, arg]) => {
50
+ acc[name] = { ...arg, name };
51
+ return acc;
52
+ }, {});
53
+ const commandLoadable = {
54
+ //! required properties
55
+ id: commandId || thisClass.id || '',
56
+ flags: thisClass.flags || {},
57
+ args,
58
+ aliases: thisClass.aliases || [],
59
+ hidden: thisClass.hidden || false,
60
+ hiddenAliases: thisClass.hiddenAliases || [],
61
+ load: async () => thisClass,
62
+ //* optional properties
63
+ // bin, // seems to not be used in the CommandHelp class
64
+ // thisClass, // doesn't change the help text
65
+ help: thisClass.help,
66
+ usage: thisClass.usage,
67
+ examples: thisClass.examples,
68
+ description: thisClass.description,
69
+ summary: thisClass.summary,
70
+ state: thisClass.state,
71
+ deprecateAliases: thisClass.deprecateAliases,
72
+ deprecationOptions: thisClass.deprecationOptions,
73
+ strict: thisClass.strict,
74
+ hasDynamicHelp: thisClass.hasDynamicHelp,
75
+ };
76
+ const commandHelp = new CommandHelp(commandLoadable, { bin }, {
77
+ maxWidth: 120,
78
+ });
79
+ return commandHelp.generate();
80
+ }
22
81
  async init() {
23
82
  const { args, flags } = await this.parse({
24
83
  flags: this.ctor.flags,
@@ -30,6 +89,19 @@ export class BlueprintCommand extends Command {
30
89
  this.flags = flags;
31
90
  this.args = args;
32
91
  await super.init();
92
+ }
93
+ }
94
+ /**
95
+ * @description Guarantees flags, args, sanityToken, and blueprint.
96
+ * Blueprint parser errors are logged and the command exits with an error
97
+ * @extends RuntimeCommand
98
+ */
99
+ export class LocalBlueprintCommand extends RuntimeCommand {
100
+ sanityToken;
101
+ blueprint;
102
+ static baseFlags = baseFlags;
103
+ async init() {
104
+ await super.init();
33
105
  const result = await initBlueprintConfig({
34
106
  bin: this.config.bin,
35
107
  log: (msg) => this.log(msg),
@@ -53,9 +125,9 @@ export class BlueprintCommand extends Command {
53
125
  /**
54
126
  * @description Guarantees flags, args, sanityToken, blueprint, scopeType, scopeId, stackId, auth, and deployedStack.
55
127
  * If scope or stack is missing, the command exits with an error
56
- * @extends BlueprintCommand
128
+ * @extends LocalBlueprintCommand
57
129
  */
58
- export class DeployedBlueprintCommand extends BlueprintCommand {
130
+ export class DeployedStackCommand extends LocalBlueprintCommand {
59
131
  auth;
60
132
  deployedStack;
61
133
  scopeType;
@@ -3,8 +3,8 @@
3
3
  * @deprecated Use `functions add` instead.
4
4
  * We're in the process of deprecating the `blueprints add` command.
5
5
  */
6
- import { BlueprintCommand } from '../../baseCommands.js';
7
- export default class AddCommand extends BlueprintCommand<typeof AddCommand> {
6
+ import { LocalBlueprintCommand } from '../../baseCommands.js';
7
+ export default class AddCommand extends LocalBlueprintCommand<typeof AddCommand> {
8
8
  static description: string;
9
9
  static examples: string[];
10
10
  static args: {
@@ -4,10 +4,10 @@
4
4
  * We're in the process of deprecating the `blueprints add` command.
5
5
  */
6
6
  import { Args, Flags } from '@oclif/core';
7
- import { BlueprintCommand } from '../../baseCommands.js';
7
+ import { LocalBlueprintCommand } from '../../baseCommands.js';
8
8
  import { functionAddCore } from '../../cores/functions/index.js';
9
9
  // import {warn} from '../../utils/display/presenters.js'
10
- export default class AddCommand extends BlueprintCommand {
10
+ export default class AddCommand extends LocalBlueprintCommand {
11
11
  // static state = 'deprecated'
12
12
  // static deprecationOptions = {
13
13
  // message: '`blueprints add` is deprecated. Use `functions add` instead.',
@@ -1,5 +1,5 @@
1
- import { BlueprintCommand } from '../../baseCommands.js';
2
- export default class ConfigCommand extends BlueprintCommand<typeof ConfigCommand> {
1
+ import { LocalBlueprintCommand } from '../../baseCommands.js';
2
+ export default class ConfigCommand extends LocalBlueprintCommand<typeof ConfigCommand> {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
@@ -1,7 +1,7 @@
1
1
  import { Flags } from '@oclif/core';
2
- import { BlueprintCommand } from '../../baseCommands.js';
2
+ import { LocalBlueprintCommand } from '../../baseCommands.js';
3
3
  import { blueprintConfigCore } from '../../cores/blueprints/config.js';
4
- export default class ConfigCommand extends BlueprintCommand {
4
+ export default class ConfigCommand extends LocalBlueprintCommand {
5
5
  static description = 'View or edit Blueprint configuration';
6
6
  static examples = [
7
7
  '<%= config.bin %> <%= command.id %>',
@@ -1,5 +1,5 @@
1
- import { DeployedBlueprintCommand } from '../../baseCommands.js';
2
- export default class DeployCommand extends DeployedBlueprintCommand<typeof DeployCommand> {
1
+ import { DeployedStackCommand } from '../../baseCommands.js';
2
+ export default class DeployCommand extends DeployedStackCommand<typeof DeployCommand> {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
@@ -1,7 +1,7 @@
1
1
  import { Flags } from '@oclif/core';
2
- import { DeployedBlueprintCommand } from '../../baseCommands.js';
2
+ import { DeployedStackCommand } from '../../baseCommands.js';
3
3
  import { blueprintDeployCore } from '../../cores/blueprints/deploy.js';
4
- export default class DeployCommand extends DeployedBlueprintCommand {
4
+ export default class DeployCommand extends DeployedStackCommand {
5
5
  static description = 'Deploy a Blueprint';
6
6
  static examples = [
7
7
  '<%= config.bin %> <%= command.id %>',
@@ -1,5 +1,5 @@
1
- import { BlueprintCommand } from '../../baseCommands.js';
2
- export default class DestroyCommand extends BlueprintCommand<typeof DestroyCommand> {
1
+ import { LocalBlueprintCommand } from '../../baseCommands.js';
2
+ export default class DestroyCommand extends LocalBlueprintCommand<typeof DestroyCommand> {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
@@ -1,7 +1,7 @@
1
1
  import { Flags } from '@oclif/core';
2
- import { BlueprintCommand } from '../../baseCommands.js';
2
+ import { LocalBlueprintCommand } from '../../baseCommands.js';
3
3
  import { blueprintDestroyCore } from '../../cores/blueprints/destroy.js';
4
- export default class DestroyCommand extends BlueprintCommand {
4
+ export default class DestroyCommand extends LocalBlueprintCommand {
5
5
  static description = 'Destroy a Blueprint Stack deployment and its resources (will not delete local files)';
6
6
  static examples = [
7
7
  '<%= config.bin %> <%= command.id %>',
@@ -1,11 +1,12 @@
1
- import { Command } from '@oclif/core';
2
- export default class DoctorCommand extends Command {
1
+ import { RuntimeCommand } from '../../baseCommands.js';
2
+ export default class DoctorCommand extends RuntimeCommand<typeof DoctorCommand> {
3
3
  static description: string;
4
4
  static examples: never[];
5
5
  static flags: {
6
- verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
6
  path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
7
  fix: import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
+ verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
10
  };
10
- run(): Promise<void>;
11
+ run(): Promise<Record<string, unknown> | undefined>;
11
12
  }
@@ -1,32 +1,30 @@
1
- import { Command, Flags } from '@oclif/core';
1
+ import { Flags } from '@oclif/core';
2
+ import { baseFlags, RuntimeCommand, unhide } from '../../baseCommands.js';
2
3
  import config from '../../config.js';
3
4
  import { blueprintDoctorCore } from '../../cores/blueprints/doctor.js';
4
- export default class DoctorCommand extends Command {
5
+ export default class DoctorCommand extends RuntimeCommand {
5
6
  static description = 'Diagnose potential issues with Blueprint configuration';
6
7
  static examples = [];
7
8
  static flags = {
8
- verbose: Flags.boolean({
9
- description: 'Provide detailed information about issues',
10
- default: false,
11
- }),
12
- path: Flags.string({
13
- description: 'Path to the Blueprint configuration file',
14
- }),
9
+ path: unhide(baseFlags.path),
15
10
  fix: Flags.boolean({
16
11
  description: 'Interactively fix configuration issues',
17
12
  default: false,
18
13
  }),
14
+ json: unhide(baseFlags.json),
15
+ verbose: unhide(baseFlags.verbose),
19
16
  };
20
17
  async run() {
21
- const { flags } = await this.parse(DoctorCommand);
22
18
  const { token } = config;
23
- const { success, error } = await blueprintDoctorCore({
19
+ const result = await blueprintDoctorCore({
24
20
  bin: this.config.bin,
25
21
  log: (message) => this.log(message),
26
22
  token,
27
- flags,
23
+ flags: this.flags,
28
24
  });
25
+ const { success, error } = result;
29
26
  if (!success)
30
27
  this.error(error);
28
+ return result.data;
31
29
  }
32
30
  }
@@ -1,5 +1,5 @@
1
- import { DeployedBlueprintCommand } from '../../baseCommands.js';
2
- export default class InfoCommand extends DeployedBlueprintCommand<typeof InfoCommand> {
1
+ import { DeployedStackCommand } from '../../baseCommands.js';
2
+ export default class InfoCommand extends DeployedStackCommand<typeof InfoCommand> {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
@@ -1,7 +1,7 @@
1
1
  import { Flags } from '@oclif/core';
2
- import { DeployedBlueprintCommand } from '../../baseCommands.js';
2
+ import { DeployedStackCommand } from '../../baseCommands.js';
3
3
  import { blueprintInfoCore } from '../../cores/blueprints/info.js';
4
- export default class InfoCommand extends DeployedBlueprintCommand {
4
+ export default class InfoCommand extends DeployedStackCommand {
5
5
  static description = 'Show information about a Blueprint Stack deployment';
6
6
  static examples = [
7
7
  '<%= config.bin %> <%= command.id %>',
@@ -1,5 +1,5 @@
1
- import { Command } from '@oclif/core';
2
- export default class InitCommand extends Command {
1
+ import { RuntimeCommand } from '../../baseCommands.js';
2
+ export default class InitCommand extends RuntimeCommand<typeof InitCommand> {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static args: {