@sanity/runtime-cli 1.4.1 → 1.4.2

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
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
20
20
  $ sanity COMMAND
21
21
  running command...
22
22
  $ sanity (--version)
23
- @sanity/runtime-cli/1.4.1 linux-x64 node-v22.14.0
23
+ @sanity/runtime-cli/1.4.2 linux-x64 node-v22.14.0
24
24
  $ sanity --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity COMMAND
@@ -33,6 +33,7 @@ USAGE
33
33
  * [`sanity blueprints info`](#sanity-blueprints-info)
34
34
  * [`sanity blueprints logs`](#sanity-blueprints-logs)
35
35
  * [`sanity blueprints plan`](#sanity-blueprints-plan)
36
+ * [`sanity blueprints stacks`](#sanity-blueprints-stacks)
36
37
  * [`sanity functions dev`](#sanity-functions-dev)
37
38
  * [`sanity functions invoke ID`](#sanity-functions-invoke-id)
38
39
  * [`sanity functions logs ID`](#sanity-functions-logs-id)
@@ -64,7 +65,7 @@ EXAMPLES
64
65
  $ sanity blueprints deploy
65
66
  ```
66
67
 
67
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.1/src/commands/blueprints/deploy.ts)_
68
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.2/src/commands/blueprints/deploy.ts)_
68
69
 
69
70
  ## `sanity blueprints info`
70
71
 
@@ -72,16 +73,21 @@ Show information about a Blueprint
72
73
 
73
74
  ```
74
75
  USAGE
75
- $ sanity blueprints info
76
+ $ sanity blueprints info [--id <value>]
77
+
78
+ FLAGS
79
+ --id=<value> Stack ID to show info for (defaults to current stack)
76
80
 
77
81
  DESCRIPTION
78
82
  Show information about a Blueprint
79
83
 
80
84
  EXAMPLES
81
85
  $ sanity blueprints info
86
+
87
+ $ sanity blueprints info --id abc123
82
88
  ```
83
89
 
84
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.1/src/commands/blueprints/info.ts)_
90
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.2/src/commands/blueprints/info.ts)_
85
91
 
86
92
  ## `sanity blueprints logs`
87
93
 
@@ -103,7 +109,7 @@ EXAMPLES
103
109
  $ sanity blueprints logs --watch
104
110
  ```
105
111
 
106
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.1/src/commands/blueprints/logs.ts)_
112
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.2/src/commands/blueprints/logs.ts)_
107
113
 
108
114
  ## `sanity blueprints plan`
109
115
 
@@ -120,7 +126,24 @@ EXAMPLES
120
126
  $ sanity blueprints plan
121
127
  ```
122
128
 
123
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.1/src/commands/blueprints/plan.ts)_
129
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.2/src/commands/blueprints/plan.ts)_
130
+
131
+ ## `sanity blueprints stacks`
132
+
133
+ List all Blueprint stacks
134
+
135
+ ```
136
+ USAGE
137
+ $ sanity blueprints stacks
138
+
139
+ DESCRIPTION
140
+ List all Blueprint stacks
141
+
142
+ EXAMPLES
143
+ $ sanity blueprints stacks
144
+ ```
145
+
146
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.2/src/commands/blueprints/stacks.ts)_
124
147
 
125
148
  ## `sanity functions dev`
126
149
 
@@ -140,7 +163,7 @@ EXAMPLES
140
163
  $ sanity functions dev --port 8974
141
164
  ```
142
165
 
143
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.1/src/commands/functions/dev.ts)_
166
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.2/src/commands/functions/dev.ts)_
144
167
 
145
168
  ## `sanity functions invoke ID`
146
169
 
@@ -166,7 +189,7 @@ EXAMPLES
166
189
  $ sanity functions invoke <ID> --file 'payload.json'
167
190
  ```
168
191
 
169
- _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.1/src/commands/functions/invoke.ts)_
192
+ _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.2/src/commands/functions/invoke.ts)_
170
193
 
171
194
  ## `sanity functions logs ID`
172
195
 
@@ -186,7 +209,7 @@ EXAMPLES
186
209
  $ sanity functions logs <ID>
187
210
  ```
188
211
 
189
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.1/src/commands/functions/logs.ts)_
212
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.2/src/commands/functions/logs.ts)_
190
213
 
191
214
  ## `sanity functions test PATH`
192
215
 
@@ -215,7 +238,7 @@ EXAMPLES
215
238
  $ sanity functions test ./test.ts --data '{ "id": 1 }' --timeout 60
216
239
  ```
217
240
 
218
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.1/src/commands/functions/test.ts)_
241
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.2/src/commands/functions/test.ts)_
219
242
 
220
243
  ## `sanity help [COMMAND]`
221
244
 
@@ -54,12 +54,6 @@ export default async function readBlueprintOnDisk({ blueprintPath, getStack, } =
54
54
  type: BlueprintErrorType.MissingProject,
55
55
  });
56
56
  }
57
- if (!stackResource) {
58
- errors.push({
59
- message: 'Blueprint is missing a stack resource',
60
- type: BlueprintErrorType.MissingStack,
61
- });
62
- }
63
57
  let deployedStack;
64
58
  if (getStack && projectResource && stackResource) {
65
59
  const { stack } = await getStackByName({
@@ -1,8 +1,9 @@
1
1
  import { Command } from '@oclif/core';
2
+ import inquirer from 'inquirer';
2
3
  import readBlueprintOnDisk from '../../actions/blueprints/read-blueprint.js';
3
4
  import { createStack, updateStack } from '../../actions/blueprints/stacks.js';
4
5
  import { stashAsset } from '../../actions/blueprints/stash-asset.js';
5
- import { green, red, yellow } from '../../utils/display/colors.js';
6
+ import { bold, green, red, yellow } from '../../utils/display/colors.js';
6
7
  import Spinner from '../../utils/spinner.js';
7
8
  export default class Deploy extends Command {
8
9
  static description = 'Deploy a Blueprint';
@@ -17,12 +18,24 @@ export default class Deploy extends Command {
17
18
  }
18
19
  if (!projectResource)
19
20
  this.error('Blueprint must contain a project resource'); // returns
20
- if (!stackResource)
21
- this.error('Blueprint must contain a stack resource'); // returns
22
21
  const { id: projectId } = projectResource;
23
- const { name } = stackResource;
22
+ let name = stackResource?.name;
23
+ if (!name) {
24
+ const { stackName } = await inquirer.prompt([
25
+ {
26
+ type: 'input',
27
+ name: 'stackName',
28
+ message: 'Enter stack name:',
29
+ validate: (input) => input.length > 0 || 'Stack name is required',
30
+ },
31
+ ]);
32
+ name = stackName;
33
+ }
34
+ if (!name)
35
+ this.error('Stack name is required');
24
36
  const s = new Spinner();
25
- const functionResources = resources.filter((r) => r.type === 'function');
37
+ const validResources = resources.filter((r) => r.kind);
38
+ const functionResources = validResources.filter((r) => r.type?.startsWith('sanity.function.'));
26
39
  // First stash all function assets
27
40
  if (functionResources.length > 0) {
28
41
  for (const resource of functionResources) {
@@ -45,7 +58,7 @@ export default class Deploy extends Command {
45
58
  const blueprint = {
46
59
  name,
47
60
  projectId,
48
- document: { resources },
61
+ document: { resources: validResources },
49
62
  };
50
63
  this.debug('BLUEPRINT DOCUMENT:', blueprint);
51
64
  const { ok: deployOk, stack, error: deployError, } = deployedStack
@@ -53,13 +66,13 @@ export default class Deploy extends Command {
53
66
  : await createStack({ blueprint, projectId });
54
67
  this.debug('STACK RESPONSE:', stack);
55
68
  if (deployOk) {
56
- s.stop(`${green('Success!')} Stack ${deployedStack ? 'updated' : 'created'} <${yellow(stack.id)}>`);
69
+ s.stop(`${green('Success!')} Stack "${bold(stack.name)}" ${deployedStack ? 'updated' : 'created'} <${yellow(stack.id)}>`);
57
70
  this.log('\nUse `sanity blueprints info` to check deployment status');
58
71
  }
59
72
  else {
60
73
  this.debug('STACK ERROR RESPONSE:', stack);
61
74
  s.stop(`${red('Failed')} to ${deployedStack ? 'update' : 'create'} stack`);
62
- this.log(`Error: ${deployError || 'Unknown error'}`);
75
+ this.log(`Error: ${deployError || JSON.stringify(stack, null, 2) || 'Unknown error'}`);
63
76
  }
64
77
  }
65
78
  }
@@ -2,5 +2,8 @@ import { Command } from '@oclif/core';
2
2
  export default class Info extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
+ static flags: {
6
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ };
5
8
  run(): Promise<void>;
6
9
  }
@@ -1,32 +1,55 @@
1
- import { Command } from '@oclif/core';
1
+ import { Command, Flags } from '@oclif/core';
2
2
  import readBlueprintOnDisk from '../../actions/blueprints/read-blueprint.js';
3
+ import { getStack } from '../../actions/blueprints/stacks.js';
3
4
  import { formatResourceTree } from '../../utils/display/blueprints-formatting.js';
4
5
  import { bold, green, red, yellow } from '../../utils/display/colors.js';
5
6
  import { formatDate, formatDuration } from '../../utils/display/dates.js';
6
7
  export default class Info extends Command {
7
8
  static description = 'Show information about a Blueprint';
8
- static examples = ['<%= config.bin %> <%= command.id %>'];
9
+ static examples = [
10
+ '<%= config.bin %> <%= command.id %>',
11
+ '<%= config.bin %> <%= command.id %> --id abc123',
12
+ ];
13
+ static flags = {
14
+ id: Flags.string({
15
+ description: 'Stack ID to show info for (defaults to current stack)',
16
+ required: false,
17
+ }),
18
+ };
9
19
  async run() {
10
- const { errors, deployedStack } = await readBlueprintOnDisk({ getStack: true });
20
+ const { flags } = await this.parse(Info);
21
+ const { errors, deployedStack, projectResource } = await readBlueprintOnDisk({ getStack: true });
11
22
  if (errors.length > 0) {
12
23
  // printErrors(errors)
13
24
  this.log('Blueprint parse errors:');
14
25
  console.dir(errors, { depth: null });
15
26
  return;
16
27
  }
17
- if (!deployedStack)
18
- this.error('Stack not found'); // returns
28
+ if (!projectResource)
29
+ this.error('Project resource not found in blueprint');
30
+ let stack = deployedStack;
31
+ if (flags.id) {
32
+ const { ok, stack: foundStack, error, } = await getStack({ stackId: flags.id, projectId: projectResource.id });
33
+ if (!ok)
34
+ this.error(error || 'Failed to get stack');
35
+ stack = foundStack;
36
+ }
37
+ else if (!stack) {
38
+ this.error('No stack found');
39
+ }
40
+ if (!stack)
41
+ this.error('Stack not found. Is it deployed?');
19
42
  try {
20
- this.log(`Stack name: ${bold(deployedStack.name)}`);
21
- this.log(`Stack ID: ${yellow(deployedStack.id)}`);
22
- if (deployedStack.createdAt) {
23
- this.log(`Created: ${formatDate(deployedStack.createdAt)}`);
43
+ this.log(`Stack name: ${bold(stack.name)}`);
44
+ this.log(`Stack ID: ${yellow(stack.id)}`);
45
+ if (stack.createdAt) {
46
+ this.log(`Created: ${formatDate(stack.createdAt)}`);
24
47
  }
25
- if (deployedStack.updatedAt) {
26
- this.log(`Updated: ${formatDate(deployedStack.updatedAt)}`);
48
+ if (stack.updatedAt) {
49
+ this.log(`Updated: ${formatDate(stack.updatedAt)}`);
27
50
  }
28
- if (deployedStack.recentOperation) {
29
- const operation = deployedStack.recentOperation;
51
+ if (stack.recentOperation) {
52
+ const operation = stack.recentOperation;
30
53
  if (operation.id) {
31
54
  this.log(`Recent Operation <${yellow(operation.id)}>:`);
32
55
  }
@@ -44,8 +67,8 @@ export default class Info extends Command {
44
67
  }
45
68
  }
46
69
  this.log('');
47
- if (deployedStack.resources) {
48
- formatResourceTree(deployedStack.resources, this.log.bind(this));
70
+ if (stack.resources) {
71
+ formatResourceTree(stack.resources, this.log.bind(this));
49
72
  }
50
73
  }
51
74
  catch (err) {
@@ -0,0 +1,6 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Stacks extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ run(): Promise<void>;
6
+ }
@@ -0,0 +1,40 @@
1
+ import { Command } from '@oclif/core';
2
+ import readBlueprintOnDisk from '../../actions/blueprints/read-blueprint.js';
3
+ import { listStacks } from '../../actions/blueprints/stacks.js';
4
+ import { bold, boldnblue, yellow } from '../../utils/display/colors.js';
5
+ import { formatDate } from '../../utils/display/dates.js';
6
+ export default class Stacks extends Command {
7
+ static description = 'List all Blueprint stacks';
8
+ static examples = ['<%= config.bin %> <%= command.id %>'];
9
+ async run() {
10
+ const { errors, projectResource, stackResource } = await readBlueprintOnDisk();
11
+ if (errors.length > 0) {
12
+ this.log('Blueprint parse errors:');
13
+ console.dir(errors, { depth: null });
14
+ return;
15
+ }
16
+ if (!projectResource)
17
+ this.error('Project resource not found in blueprint');
18
+ const { ok, stacks, error } = await listStacks({ projectId: projectResource.id });
19
+ if (!ok)
20
+ this.error(error || 'Failed to list stacks');
21
+ if (!stacks || stacks.length === 0) {
22
+ this.log('No stacks found');
23
+ return;
24
+ }
25
+ this.log(`${bold('Project')} <${yellow(projectResource.id)}> ${bold('Stacks')} :\n`);
26
+ for (const stack of stacks) {
27
+ const isCurrentStack = stackResource?.name === stack.name;
28
+ const stackName = isCurrentStack ? boldnblue(stack.name) : bold(stack.name);
29
+ this.log(`${stackName} <${yellow(stack.id)}>${isCurrentStack ? ' (current)' : ''}`);
30
+ if (stack.createdAt) {
31
+ this.log(` Created: ${formatDate(stack.createdAt)}`);
32
+ }
33
+ if (stack.updatedAt) {
34
+ this.log(` Updated: ${formatDate(stack.updatedAt)}`);
35
+ }
36
+ this.log(` ${stack.resources.length} resource${stack.resources.length === 1 ? '' : 's'}`);
37
+ this.log('');
38
+ }
39
+ }
40
+ }
@@ -29,9 +29,19 @@
29
29
  "args": {},
30
30
  "description": "Show information about a Blueprint",
31
31
  "examples": [
32
- "<%= config.bin %> <%= command.id %>"
32
+ "<%= config.bin %> <%= command.id %>",
33
+ "<%= config.bin %> <%= command.id %> --id abc123"
33
34
  ],
34
- "flags": {},
35
+ "flags": {
36
+ "id": {
37
+ "description": "Stack ID to show info for (defaults to current stack)",
38
+ "name": "id",
39
+ "required": false,
40
+ "hasDynamicHelp": false,
41
+ "multiple": false,
42
+ "type": "option"
43
+ }
44
+ },
35
45
  "hasDynamicHelp": false,
36
46
  "hiddenAliases": [],
37
47
  "id": "blueprints:info",
@@ -106,6 +116,30 @@
106
116
  "plan.js"
107
117
  ]
108
118
  },
119
+ "blueprints:stacks": {
120
+ "aliases": [],
121
+ "args": {},
122
+ "description": "List all Blueprint stacks",
123
+ "examples": [
124
+ "<%= config.bin %> <%= command.id %>"
125
+ ],
126
+ "flags": {},
127
+ "hasDynamicHelp": false,
128
+ "hiddenAliases": [],
129
+ "id": "blueprints:stacks",
130
+ "pluginAlias": "@sanity/runtime-cli",
131
+ "pluginName": "@sanity/runtime-cli",
132
+ "pluginType": "core",
133
+ "strict": true,
134
+ "enableJsonFlag": false,
135
+ "isESM": true,
136
+ "relativePath": [
137
+ "dist",
138
+ "commands",
139
+ "blueprints",
140
+ "stacks.js"
141
+ ]
142
+ },
109
143
  "functions:dev": {
110
144
  "aliases": [],
111
145
  "args": {},
@@ -281,5 +315,5 @@
281
315
  ]
282
316
  }
283
317
  },
284
- "version": "1.4.1"
318
+ "version": "1.4.2"
285
319
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sanity/runtime-cli",
3
3
  "description": "A new CLI generated with oclif",
4
- "version": "1.4.1",
4
+ "version": "1.4.2",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -41,6 +41,7 @@
41
41
  "@oclif/plugin-help": "^6",
42
42
  "@oclif/plugin-plugins": "^5",
43
43
  "eventsource": "^3.0.5",
44
+ "inquirer": "^12.5.0",
44
45
  "jszip": "^3.10.1",
45
46
  "mime-types": "^2.1.35",
46
47
  "xdg-basedir": "^5.1.0"