@sanity/runtime-cli 5.1.0 → 5.2.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 (46) hide show
  1. package/README.md +23 -22
  2. package/dist/actions/blueprints/blueprint.d.ts +9 -5
  3. package/dist/actions/blueprints/index.d.ts +1 -1
  4. package/dist/actions/blueprints/index.js +1 -1
  5. package/dist/baseCommands.d.ts +10 -0
  6. package/dist/baseCommands.js +23 -11
  7. package/dist/commands/blueprints/add.d.ts +0 -8
  8. package/dist/commands/blueprints/add.js +12 -93
  9. package/dist/commands/blueprints/config.d.ts +2 -24
  10. package/dist/commands/blueprints/config.js +12 -179
  11. package/dist/commands/blueprints/deploy.js +12 -69
  12. package/dist/commands/blueprints/destroy.d.ts +5 -4
  13. package/dist/commands/blueprints/destroy.js +21 -61
  14. package/dist/commands/blueprints/info.js +11 -19
  15. package/dist/commands/blueprints/init.d.ts +0 -16
  16. package/dist/commands/blueprints/init.js +10 -167
  17. package/dist/commands/blueprints/logs.js +14 -67
  18. package/dist/commands/blueprints/plan.js +8 -13
  19. package/dist/commands/blueprints/stacks.js +10 -19
  20. package/dist/cores/blueprints/add.d.ts +13 -0
  21. package/dist/cores/blueprints/add.js +107 -0
  22. package/dist/cores/blueprints/config.d.ts +13 -0
  23. package/dist/cores/blueprints/config.js +222 -0
  24. package/dist/cores/blueprints/deploy.d.ts +14 -0
  25. package/dist/cores/blueprints/deploy.js +81 -0
  26. package/dist/cores/blueprints/destroy.d.ts +13 -0
  27. package/dist/cores/blueprints/destroy.js +106 -0
  28. package/dist/cores/blueprints/index.d.ts +18 -0
  29. package/dist/cores/blueprints/index.js +9 -0
  30. package/dist/cores/blueprints/info.d.ts +11 -0
  31. package/dist/cores/blueprints/info.js +33 -0
  32. package/dist/cores/blueprints/init.d.ts +15 -0
  33. package/dist/cores/blueprints/init.js +190 -0
  34. package/dist/cores/blueprints/logs.d.ts +11 -0
  35. package/dist/cores/blueprints/logs.js +74 -0
  36. package/dist/cores/blueprints/plan.d.ts +6 -0
  37. package/dist/cores/blueprints/plan.js +11 -0
  38. package/dist/cores/blueprints/stacks.d.ts +10 -0
  39. package/dist/cores/blueprints/stacks.js +30 -0
  40. package/dist/cores/index.d.ts +20 -0
  41. package/dist/cores/index.js +1 -0
  42. package/dist/utils/display/blueprints-formatting.js +12 -11
  43. package/dist/utils/display/colors.d.ts +3 -1
  44. package/dist/utils/display/colors.js +8 -2
  45. package/oclif.manifest.json +29 -15
  46. package/package.json +5 -1
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/5.1.0 linux-x64 node-v22.15.0
23
+ @sanity/runtime-cli/5.2.0 linux-x64 node-v22.15.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -47,7 +47,7 @@ USAGE
47
47
 
48
48
  ## `sanity-run blueprints add TYPE`
49
49
 
50
- Add a (function) resource to a Blueprint
50
+ Add a Resource to a Blueprint
51
51
 
52
52
  ```
53
53
  USAGE
@@ -57,15 +57,15 @@ ARGUMENTS
57
57
  TYPE (function) Type of resource to add (e.g. function)
58
58
 
59
59
  FLAGS
60
- -n, --name=<value> Name of the resource to add
61
- --fn-type=<option> Type of new function
60
+ -n, --name=<value> Name of the Resource to add
61
+ --fn-type=<option> Type of new Function
62
62
  <options: document-publish>
63
63
  --javascript Use JavaScript instead of TypeScript
64
- --language=<option> [default: ts] Language of the new function
64
+ --language=<option> [default: ts] Language of the new Function
65
65
  <options: ts|js>
66
66
 
67
67
  DESCRIPTION
68
- Add a (function) resource to a Blueprint
68
+ Add a Resource to a Blueprint
69
69
 
70
70
  EXAMPLES
71
71
  $ sanity-run blueprints add function
@@ -77,7 +77,7 @@ EXAMPLES
77
77
  $ sanity-run blueprints add function --name my-function --fn-type document-publish --lang js
78
78
  ```
79
79
 
80
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/blueprints/add.ts)_
80
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/add.ts)_
81
81
 
82
82
  ## `sanity-run blueprints config`
83
83
 
@@ -105,7 +105,7 @@ EXAMPLES
105
105
  $ sanity-run blueprints config --edit --project-id <projectId>
106
106
  ```
107
107
 
108
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/blueprints/config.ts)_
108
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/config.ts)_
109
109
 
110
110
  ## `sanity-run blueprints deploy`
111
111
 
@@ -127,7 +127,7 @@ EXAMPLES
127
127
  $ sanity-run blueprints deploy --no-wait
128
128
  ```
129
129
 
130
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/blueprints/deploy.ts)_
130
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/deploy.ts)_
131
131
 
132
132
  ## `sanity-run blueprints destroy`
133
133
 
@@ -135,10 +135,11 @@ Destroy a Blueprint deployment (will not delete local files)
135
135
 
136
136
  ```
137
137
  USAGE
138
- $ sanity-run blueprints destroy [--force]
138
+ $ sanity-run blueprints destroy [--force] [--no-wait]
139
139
 
140
140
  FLAGS
141
- --force Force destroy (skip confirmation)
141
+ --force Force destroy (skip confirmation)
142
+ --no-wait Do not wait for destruction to complete
142
143
 
143
144
  DESCRIPTION
144
145
  Destroy a Blueprint deployment (will not delete local files)
@@ -147,7 +148,7 @@ EXAMPLES
147
148
  $ sanity-run blueprints destroy
148
149
  ```
149
150
 
150
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/blueprints/destroy.ts)_
151
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/destroy.ts)_
151
152
 
152
153
  ## `sanity-run blueprints info`
153
154
 
@@ -164,7 +165,7 @@ EXAMPLES
164
165
  $ sanity-run blueprints info
165
166
  ```
166
167
 
167
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/blueprints/info.ts)_
168
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/info.ts)_
168
169
 
169
170
  ## `sanity-run blueprints init [DIR]`
170
171
 
@@ -196,7 +197,7 @@ EXAMPLES
196
197
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --project-id <projectId>
197
198
  ```
198
199
 
199
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/blueprints/init.ts)_
200
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/init.ts)_
200
201
 
201
202
  ## `sanity-run blueprints logs`
202
203
 
@@ -218,7 +219,7 @@ EXAMPLES
218
219
  $ sanity-run blueprints logs --watch
219
220
  ```
220
221
 
221
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/blueprints/logs.ts)_
222
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/logs.ts)_
222
223
 
223
224
  ## `sanity-run blueprints plan`
224
225
 
@@ -235,7 +236,7 @@ EXAMPLES
235
236
  $ sanity-run blueprints plan
236
237
  ```
237
238
 
238
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/blueprints/plan.ts)_
239
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/plan.ts)_
239
240
 
240
241
  ## `sanity-run functions dev`
241
242
 
@@ -255,7 +256,7 @@ EXAMPLES
255
256
  $ sanity-run functions dev --port 8974
256
257
  ```
257
258
 
258
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/functions/dev.ts)_
259
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/dev.ts)_
259
260
 
260
261
  ## `sanity-run functions env add NAME KEY VALUE`
261
262
 
@@ -277,7 +278,7 @@ EXAMPLES
277
278
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
278
279
  ```
279
280
 
280
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/functions/env/add.ts)_
281
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/env/add.ts)_
281
282
 
282
283
  ## `sanity-run functions env list NAME`
283
284
 
@@ -297,7 +298,7 @@ EXAMPLES
297
298
  $ sanity-run functions env list MyFunction
298
299
  ```
299
300
 
300
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/functions/env/list.ts)_
301
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/env/list.ts)_
301
302
 
302
303
  ## `sanity-run functions env remove NAME KEY`
303
304
 
@@ -318,7 +319,7 @@ EXAMPLES
318
319
  $ sanity-run functions env remove MyFunction API_URL
319
320
  ```
320
321
 
321
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/functions/env/remove.ts)_
322
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/env/remove.ts)_
322
323
 
323
324
  ## `sanity-run functions logs NAME`
324
325
 
@@ -350,7 +351,7 @@ EXAMPLES
350
351
  $ sanity-run functions logs <name> --delete
351
352
  ```
352
353
 
353
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/functions/logs.ts)_
354
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/logs.ts)_
354
355
 
355
356
  ## `sanity-run functions test NAME`
356
357
 
@@ -383,7 +384,7 @@ EXAMPLES
383
384
  $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
384
385
  ```
385
386
 
386
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v5.1.0/src/commands/functions/test.ts)_
387
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/test.ts)_
387
388
 
388
389
  ## `sanity-run help [COMMAND]`
389
390
 
@@ -13,11 +13,9 @@ export declare function findBlueprintFile(blueprintPath?: string): {
13
13
  extension: BlueprintFileExtension;
14
14
  } | null;
15
15
  /**
16
- * Reads the blueprint file from disk and parses it. Greedily looks for project and stack config
17
- * @param blueprintPath - The path of the blueprint file or directory- will search up the directory tree!
18
- * @returns Known information about the Blueprint, config, and Stack
16
+ * Result of the blueprint read operation
19
17
  */
20
- export declare function readLocalBlueprint(blueprintPath?: string): Promise<{
18
+ export interface ReadBlueprintResult {
21
19
  fileInfo: {
22
20
  blueprintFilePath: string;
23
21
  fileName: string;
@@ -29,7 +27,13 @@ export declare function readLocalBlueprint(blueprintPath?: string): Promise<{
29
27
  configPath?: string;
30
28
  projectId?: string;
31
29
  stackId?: string;
32
- }>;
30
+ }
31
+ /**
32
+ * Reads the blueprint file from disk and parses it. Greedily looks for project and stack config
33
+ * @param blueprintPath - The path of the blueprint file or directory- will search up the directory tree!
34
+ * @returns Known information about the Blueprint, config, and Stack
35
+ */
36
+ export declare function readLocalBlueprint(blueprintPath?: string): Promise<ReadBlueprintResult>;
33
37
  export declare function writeBlueprintToDisk({ blueprintFilePath, content, }: {
34
38
  blueprintFilePath: string;
35
39
  content?: LocalBlueprint;
@@ -32,7 +32,7 @@ type BlueprintResult = BlueprintSuccess | BlueprintFailure;
32
32
  * Get the local Blueprint and deployed Stack
33
33
  * @param blueprintPath - The path of the Blueprint file or directory- will search up the directory tree if not provided
34
34
  * @param token - The Sanity API token
35
- * @returns The local Blueprint and deployed Stack
35
+ * @returns The local Blueprint, issues, and maybe a deployed Stack
36
36
  */
37
37
  export declare function getBlueprintAndStack({ token, blueprintPath, }: {
38
38
  token: string;
@@ -11,7 +11,7 @@ import { getStack } from './stacks.js';
11
11
  * Get the local Blueprint and deployed Stack
12
12
  * @param blueprintPath - The path of the Blueprint file or directory- will search up the directory tree if not provided
13
13
  * @param token - The Sanity API token
14
- * @returns The local Blueprint and deployed Stack
14
+ * @returns The local Blueprint, issues, and maybe a deployed Stack
15
15
  */
16
16
  export async function getBlueprintAndStack({ token, blueprintPath, }) {
17
17
  if (!token)
@@ -4,6 +4,11 @@ import { readLocalBlueprint } from './actions/blueprints/blueprint.js';
4
4
  import type { AuthParams, Stack } from './utils/types.js';
5
5
  export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BlueprintCommand)['baseFlags'] & T['flags']>;
6
6
  export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
7
+ /**
8
+ * @description Guarantees flags, args, sanityToken, and blueprint.
9
+ * Blueprint parser errors are logged and the command exits with an error
10
+ * @extends Command
11
+ */
7
12
  export declare abstract class BlueprintCommand<T extends typeof Command> extends Command {
8
13
  protected sanityToken: string;
9
14
  protected blueprint: Awaited<ReturnType<typeof readLocalBlueprint>>;
@@ -15,6 +20,11 @@ export declare abstract class BlueprintCommand<T extends typeof Command> extends
15
20
  }): Promise<unknown>;
16
21
  protected finally(_: Error | undefined): Promise<unknown>;
17
22
  }
23
+ /**
24
+ * @description Guarantees flags, args, sanityToken, blueprint, projectId, stackId, auth, and deployedStack.
25
+ * If a project or stack is missing, the command exits with an error
26
+ * @extends BlueprintCommand
27
+ */
18
28
  export declare abstract class DeployedBlueprintCommand<T extends typeof Command> extends BlueprintCommand<T> {
19
29
  protected auth: AuthParams;
20
30
  protected deployedStack: Stack;
@@ -2,8 +2,14 @@
2
2
  import { Command } from '@oclif/core';
3
3
  import { readLocalBlueprint } from './actions/blueprints/blueprint.js';
4
4
  import { getStack } from './actions/blueprints/stacks.js';
5
+ import { niceId } from './utils/display/colors.js';
5
6
  import { presentBlueprintParserErrors } from './utils/display/errors.js';
6
7
  import { validTokenOrErrorMessage } from './utils/validated-token.js';
8
+ /**
9
+ * @description Guarantees flags, args, sanityToken, and blueprint.
10
+ * Blueprint parser errors are logged and the command exits with an error
11
+ * @extends Command
12
+ */
7
13
  export class BlueprintCommand extends Command {
8
14
  sanityToken;
9
15
  blueprint;
@@ -27,7 +33,7 @@ export class BlueprintCommand extends Command {
27
33
  const blueprint = await readLocalBlueprint();
28
34
  if (blueprint.errors.length > 0) {
29
35
  this.log(presentBlueprintParserErrors(blueprint.errors));
30
- this.error('Blueprint parse errors.');
36
+ this.error('Unable to parse Blueprint file.');
31
37
  }
32
38
  this.blueprint = blueprint;
33
39
  }
@@ -41,6 +47,11 @@ export class BlueprintCommand extends Command {
41
47
  return super.finally(_);
42
48
  }
43
49
  }
50
+ /**
51
+ * @description Guarantees flags, args, sanityToken, blueprint, projectId, stackId, auth, and deployedStack.
52
+ * If a project or stack is missing, the command exits with an error
53
+ * @extends BlueprintCommand
54
+ */
44
55
  export class DeployedBlueprintCommand extends BlueprintCommand {
45
56
  auth;
46
57
  deployedStack;
@@ -49,21 +60,22 @@ export class DeployedBlueprintCommand extends BlueprintCommand {
49
60
  async init() {
50
61
  await super.init();
51
62
  const { projectId, stackId } = this.blueprint;
52
- if (!projectId)
53
- this.error('Missing Project ID for Blueprint');
54
- if (!stackId)
55
- this.error('Missing Stack ID for Blueprint');
63
+ if (!(projectId && stackId)) {
64
+ this.log(`Run \`${this.config.bin} blueprints config --edit --test\` to update your config`);
65
+ if (!projectId)
66
+ this.error('Missing Project configuration for Blueprint');
67
+ if (!stackId)
68
+ this.error('Missing deployment configuration for Blueprint');
69
+ }
56
70
  this.projectId = projectId;
57
71
  this.stackId = stackId;
58
72
  this.auth = { token: this.sanityToken, projectId };
59
73
  const stackResponse = await getStack({ stackId, auth: this.auth });
60
74
  if (!stackResponse.ok) {
61
- this.error(stackResponse.error ?? 'Could not retrieve deployment info');
62
- }
63
- const { stack: deployedStack } = stackResponse;
64
- if (!deployedStack) {
65
- this.error('Unable to find deployed Stack. Run `sanity-run blueprints init`');
75
+ this.log(`Could not retrieve deployment info for ${niceId(stackId)}. Was it destroyed?`);
76
+ this.log(`Run \`${this.config.bin} blueprints config --edit --test\` to update your config`);
77
+ this.error('Missing deployment');
66
78
  }
67
- this.deployedStack = deployedStack;
79
+ this.deployedStack = stackResponse.stack;
68
80
  }
69
81
  }
@@ -12,12 +12,4 @@ export default class AddCommand extends Command {
12
12
  javascript: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
13
  };
14
14
  run(): Promise<void>;
15
- promptForFunctionName(): Promise<string>;
16
- promptForFunctionType(): Promise<string>;
17
- promptForFunctionLang(): Promise<string>;
18
- addFunction({ name, type, lang, }: {
19
- name?: string;
20
- type?: string;
21
- lang?: string;
22
- }): Promise<void>;
23
15
  }
@@ -1,13 +1,7 @@
1
- import { cwd } from 'node:process';
2
1
  import { Args, Command, Flags } from '@oclif/core';
3
- import chalk from 'chalk';
4
- import highlight from 'color-json';
5
- import inquirer from 'inquirer';
6
- import { findBlueprintFile } from '../../actions/blueprints/blueprint.js';
7
- import { createFunctionResource } from '../../actions/blueprints/resources.js';
8
- import { validateFunctionName } from '../../utils/validate/resource.js';
2
+ import { blueprintAddCore } from '../../cores/blueprints/index.js';
9
3
  export default class AddCommand extends Command {
10
- static description = 'Add a (function) resource to a Blueprint';
4
+ static description = 'Add a Resource to a Blueprint';
11
5
  static examples = [
12
6
  '<%= config.bin %> <%= command.id %> function',
13
7
  '<%= config.bin %> <%= command.id %> function --name my-function',
@@ -23,18 +17,18 @@ export default class AddCommand extends Command {
23
17
  };
24
18
  static flags = {
25
19
  name: Flags.string({
26
- description: 'Name of the resource to add',
20
+ description: 'Name of the Resource to add',
27
21
  char: 'n',
28
22
  }),
29
23
  'fn-type': Flags.string({
30
- description: 'Type of new function',
24
+ description: 'Type of new Function',
31
25
  options: ['document-publish' /*, 'document-create', 'document-delete'*/],
32
26
  aliases: ['function-type'],
33
27
  // default: 'document-publish', // prompting informs user of default
34
28
  dependsOn: ['name'],
35
29
  }),
36
30
  language: Flags.string({
37
- description: 'Language of the new function',
31
+ description: 'Language of the new Function',
38
32
  aliases: ['function-language', 'lang'],
39
33
  options: ['ts', 'js'],
40
34
  default: 'ts',
@@ -46,88 +40,13 @@ export default class AddCommand extends Command {
46
40
  };
47
41
  async run() {
48
42
  const { args, flags } = await this.parse(AddCommand);
49
- if (args.type !== 'function')
50
- this.error(`Unsupported Resource type: ${args.type}`);
51
- const existingBlueprint = findBlueprintFile();
52
- if (!existingBlueprint) {
53
- this.error('No Blueprint file found. Run `sanity-run blueprints init` first.');
54
- }
55
- const { name: resourceName, 'fn-type': functionType, javascript } = flags;
56
- let { language: functionLang } = flags;
57
- if (javascript)
58
- functionLang = 'js';
59
- await this.addFunction({ name: resourceName, type: functionType, lang: functionLang });
60
- }
61
- async promptForFunctionName() {
62
- const { functionName } = await inquirer.prompt([
63
- {
64
- type: 'input',
65
- name: 'functionName',
66
- message: 'Enter function name:',
67
- validate: (input) => input.length > 0 || 'Function name is required',
68
- },
69
- ]);
70
- return functionName;
71
- }
72
- async promptForFunctionType() {
73
- const { functionType } = await inquirer.prompt([
74
- {
75
- type: 'list',
76
- name: 'functionType',
77
- message: 'Choose function type:',
78
- choices: [
79
- { name: 'Document Publish', value: 'document-publish' },
80
- { name: 'Document Create', value: 'document-create', disabled: true },
81
- { name: 'Document Delete', value: 'document-delete', disabled: true },
82
- ],
83
- default: 'document-publish',
84
- },
85
- ]);
86
- return functionType;
87
- }
88
- async promptForFunctionLang() {
89
- const { functionLang } = await inquirer.prompt([
90
- {
91
- type: 'list',
92
- name: 'functionLang',
93
- message: 'Choose function language:',
94
- choices: [
95
- { name: 'TypeScript', value: 'ts' },
96
- { name: 'JavaScript', value: 'js' },
97
- ],
98
- default: 'ts',
99
- },
100
- ]);
101
- return functionLang;
102
- }
103
- async addFunction({ name, type, lang, }) {
104
- const functionName = name || (await this.promptForFunctionName());
105
- if (!validateFunctionName(functionName)) {
106
- this.error('Invalid function name. Must be 6+ characters, no special characters, no spaces');
107
- }
108
- const functionType = type || (await this.promptForFunctionType());
109
- const functionLang = lang || (await this.promptForFunctionLang());
110
- if (!['document-publish', 'document-create', 'document-delete'].includes(functionType)) {
111
- this.error('Invalid function type. Must be one of: document-publish, document-create, document-delete');
112
- }
113
- const { filePath, resourceAdded, resource } = createFunctionResource({
114
- name: functionName,
115
- type: functionType,
116
- lang: functionLang,
117
- displayName: functionName,
43
+ const { success, error } = await blueprintAddCore({
44
+ bin: this.config.bin,
45
+ log: (msg) => this.log(msg),
46
+ args,
47
+ flags,
118
48
  });
119
- this.log(`\nCreated function: ${filePath.replace(cwd(), '')}`);
120
- if (functionLang === 'ts') {
121
- this.log(chalk.dim('To avoid committing build artifacts, it is helpful to .gitignore "functions/**/.build/**"'));
122
- }
123
- if (!resourceAdded) {
124
- // print the resource JSON for manual addition
125
- this.log('\nAdd this Function resource to your blueprint:');
126
- this.log(highlight(JSON.stringify(resource, null, 2)));
127
- }
128
- else {
129
- // added to blueprint.json
130
- this.log('Function resource added to blueprint');
131
- }
49
+ if (!success)
50
+ this.error(error);
132
51
  }
133
52
  }
@@ -1,5 +1,5 @@
1
- import { Command } from '@oclif/core';
2
- export default class ConfigCommand extends Command {
1
+ import { BlueprintCommand } from '../../baseCommands.js';
2
+ export default class ConfigCommand extends BlueprintCommand<typeof ConfigCommand> {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
@@ -8,27 +8,5 @@ export default class ConfigCommand extends Command {
8
8
  'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
9
  'stack-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
10
  };
11
- sanityToken: string | undefined;
12
- projectId: string | undefined;
13
- stackId: string | undefined;
14
11
  run(): Promise<void>;
15
- promptForProjectId({ knownProjectId }: {
16
- knownProjectId?: string;
17
- }): Promise<string>;
18
- promptForStackId({ projectId, knownStackId, }: {
19
- projectId: string;
20
- knownStackId?: string;
21
- }): Promise<string | undefined>;
22
- testConfigAndReport({ stackId, projectId, reinit, }: {
23
- stackId: string;
24
- projectId: string;
25
- reinit?: boolean;
26
- }): Promise<{
27
- ok: boolean;
28
- error: string | null;
29
- }>;
30
- startReinitializeStack({ projectId, stackId }: {
31
- projectId: string;
32
- stackId: string;
33
- }): Promise<void>;
34
12
  }