@sanity/runtime-cli 11.2.0 → 12.0.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 (47) hide show
  1. package/README.md +36 -38
  2. package/dist/actions/blueprints/blueprint.d.ts +3 -0
  3. package/dist/actions/blueprints/blueprint.js +26 -14
  4. package/dist/actions/blueprints/config.d.ts +34 -3
  5. package/dist/actions/blueprints/config.js +67 -14
  6. package/dist/actions/blueprints/stacks.d.ts +1 -2
  7. package/dist/actions/blueprints/stacks.js +2 -3
  8. package/dist/commands/blueprints/config.d.ts +0 -1
  9. package/dist/commands/blueprints/config.js +4 -12
  10. package/dist/commands/blueprints/deploy.js +1 -1
  11. package/dist/commands/blueprints/destroy.js +3 -3
  12. package/dist/commands/blueprints/info.js +2 -2
  13. package/dist/commands/blueprints/init.d.ts +1 -0
  14. package/dist/commands/blueprints/init.js +4 -0
  15. package/dist/commands/blueprints/logs.js +2 -2
  16. package/dist/commands/blueprints/plan.js +1 -0
  17. package/dist/config.d.ts +2 -1
  18. package/dist/config.js +8 -1
  19. package/dist/cores/blueprints/config.d.ts +1 -1
  20. package/dist/cores/blueprints/config.js +92 -78
  21. package/dist/cores/blueprints/deploy.js +8 -8
  22. package/dist/cores/blueprints/destroy.d.ts +1 -0
  23. package/dist/cores/blueprints/destroy.js +22 -26
  24. package/dist/cores/blueprints/doctor.js +24 -72
  25. package/dist/cores/blueprints/info.d.ts +1 -0
  26. package/dist/cores/blueprints/info.js +5 -4
  27. package/dist/cores/blueprints/init.d.ts +1 -1
  28. package/dist/cores/blueprints/init.js +50 -78
  29. package/dist/cores/blueprints/logs.d.ts +1 -0
  30. package/dist/cores/blueprints/logs.js +7 -7
  31. package/dist/cores/blueprints/plan.d.ts +3 -0
  32. package/dist/cores/blueprints/plan.js +5 -4
  33. package/dist/cores/blueprints/stacks.d.ts +1 -0
  34. package/dist/cores/blueprints/stacks.js +1 -2
  35. package/dist/cores/functions/add.js +58 -70
  36. package/dist/cores/functions/logs.js +2 -4
  37. package/dist/cores/index.js +3 -3
  38. package/dist/server/static/vendor/vendor.bundle.js +515 -234
  39. package/dist/utils/display/blueprints-formatting.js +8 -3
  40. package/dist/utils/display/errors.js +2 -2
  41. package/dist/utils/display/presenters.d.ts +2 -0
  42. package/dist/utils/display/presenters.js +7 -0
  43. package/dist/utils/display/prompt.d.ts +14 -2
  44. package/dist/utils/display/prompt.js +60 -41
  45. package/dist/utils/types.d.ts +0 -1
  46. package/oclif.manifest.json +19 -26
  47. package/package.json +6 -5
@@ -1,9 +1,9 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
3
  import { cwd } from 'node:process';
4
+ import { checkbox, confirm, input, select } from '@inquirer/prompts';
4
5
  import { highlight } from 'cardinal';
5
6
  import chalk from 'chalk';
6
- import inquirer from 'inquirer';
7
7
  import { createFunctionResource } from '../../actions/blueprints/resources.js';
8
8
  import { verifyExampleExists, writeExample } from '../../actions/sanity/examples.js';
9
9
  import { check, indent, warn } from '../../utils/display/presenters.js';
@@ -198,86 +198,74 @@ export async function functionAddCore(options) {
198
198
  }
199
199
  }
200
200
  async function promptForFunctionName() {
201
- const { functionName } = await inquirer.prompt([
202
- {
203
- type: 'input',
204
- name: 'functionName',
205
- message: 'Enter function name:',
206
- validate: (input) => validateFunctionName(input) ||
207
- 'Invalid function name. Must be 6+ characters, no special characters, no spaces',
208
- },
209
- ]);
201
+ const functionName = await input({
202
+ message: 'Enter function name:',
203
+ validate: (input) => validateFunctionName(input) ||
204
+ 'Invalid function name. Must be 6+ characters, no special characters, no spaces',
205
+ });
210
206
  return functionName;
211
207
  }
212
208
  async function promptForFunctionType() {
213
- const { functionType } = await inquirer.prompt([
214
- {
215
- type: 'checkbox',
216
- name: 'functionType',
217
- message: 'Choose events to trigger your function:',
218
- choices: [
219
- { name: 'Document Create', value: 'document-create' },
220
- { name: 'Document Update', value: 'document-update' },
221
- { name: 'Document Delete', value: 'document-delete' },
222
- { name: 'Media Library Asset Create', value: 'media-library-asset-create' },
223
- { name: 'Media Library Asset Update', value: 'media-library-asset-update' },
224
- { name: 'Media Library Asset Delete', value: 'media-library-asset-delete' },
225
- ],
226
- default: ['document-create', 'document-update'],
227
- validate(choices) {
228
- if (choices.length === 0) {
229
- return 'You must choose at least one function type / document change event';
230
- }
231
- if (choices.some((c) => String(c.value).startsWith('media-library')) &&
232
- choices.some((c) => String(c.value).startsWith('document'))) {
233
- return 'You cannot mix both Document and Media Library Asset events together in one Function';
234
- }
235
- return true;
236
- },
209
+ function hasAtLeastOne(arr) {
210
+ // TypeScript believes me when I make a funciton to "guard" the type
211
+ return arr.length > 0;
212
+ }
213
+ const functionTypes = await checkbox({
214
+ message: 'Choose events to trigger your function:',
215
+ choices: [
216
+ { name: 'Document Create', value: 'document-create', checked: true },
217
+ { name: 'Document Update', value: 'document-update', checked: true },
218
+ { name: 'Document Delete', value: 'document-delete' },
219
+ { name: 'Media Library Asset Create', value: 'media-library-asset-create' },
220
+ { name: 'Media Library Asset Update', value: 'media-library-asset-update' },
221
+ { name: 'Media Library Asset Delete', value: 'media-library-asset-delete' },
222
+ ],
223
+ validate(choices) {
224
+ if (choices.length === 0) {
225
+ return 'You must choose at least one function type / document change event';
226
+ }
227
+ if (choices.some((c) => String(c.value).startsWith('media-library')) &&
228
+ choices.some((c) => String(c.value).startsWith('document'))) {
229
+ return 'You cannot mix both Document and Media Library Asset events together in one Function';
230
+ }
231
+ return true;
237
232
  },
238
- ]);
239
- return functionType;
233
+ });
234
+ // checking functionTypes.length > 0 doesn't narrow the type
235
+ // validate should prevent this from happening, but just in case
236
+ if (!hasAtLeastOne(functionTypes)) {
237
+ throw new Error('You must choose at least one function type / document change event');
238
+ }
239
+ return functionTypes;
240
240
  }
241
241
  async function promptForFunctionLang() {
242
- const { functionLang } = await inquirer.prompt([
243
- {
244
- type: 'list',
245
- name: 'functionLang',
246
- message: 'Choose function language:',
247
- choices: [
248
- { name: 'TypeScript', value: 'ts' },
249
- { name: 'JavaScript', value: 'js' },
250
- ],
251
- default: 'ts',
252
- },
253
- ]);
242
+ const functionLang = await select({
243
+ message: 'Choose function language:',
244
+ choices: [
245
+ { name: 'TypeScript', value: 'ts' },
246
+ { name: 'JavaScript', value: 'js' },
247
+ ],
248
+ default: 'ts',
249
+ });
254
250
  return functionLang;
255
251
  }
256
252
  async function promptForAddHelpers() {
257
- const { addHelpers } = await inquirer.prompt([
258
- {
259
- type: 'confirm',
260
- name: 'addHelpers',
261
- message: 'Add @sanity/functions helpers to the new Function?',
262
- default: true,
263
- },
264
- ]);
253
+ const addHelpers = await confirm({
254
+ message: 'Add @sanity/functions helpers to the new Function?',
255
+ default: true,
256
+ });
265
257
  return addHelpers;
266
258
  }
267
259
  async function promptForInstallCommand() {
268
- const { command } = await inquirer.prompt([
269
- {
270
- type: 'list',
271
- name: 'command',
272
- message: 'How to install the @sanity/functions helpers:',
273
- choices: [
274
- { name: 'npm', value: 'npm' },
275
- { name: 'pnpm', value: 'pnpm' },
276
- { name: 'yarn', value: 'yarn' },
277
- { name: 'Skip install', value: null },
278
- ],
279
- default: 'npm',
280
- },
281
- ]);
260
+ const command = await select({
261
+ message: 'How to install the @sanity/functions helpers:',
262
+ choices: [
263
+ { name: 'npm', value: 'npm' },
264
+ { name: 'pnpm', value: 'pnpm' },
265
+ { name: 'yarn', value: 'yarn' },
266
+ { name: 'Skip install', value: null },
267
+ ],
268
+ default: 'npm',
269
+ });
282
270
  return command;
283
271
  }
@@ -1,5 +1,5 @@
1
+ import { confirm } from '@inquirer/prompts';
1
2
  import chalk from 'chalk';
2
- import inquirer from 'inquirer';
3
3
  import ora from 'ora';
4
4
  import { deleteLogs as deleteLogsAction, logs as getLogsAction, streamLogs as streamLogsAction, } from '../../actions/functions/logs.js';
5
5
  import { formatTitle } from '../../utils/display/blueprints-formatting.js';
@@ -18,9 +18,7 @@ export async function functionLogsCore(options) {
18
18
  }
19
19
  async function deleteLogs({ name, externalId, auth, force, }) {
20
20
  if (!force) {
21
- const { certain } = await inquirer.prompt({
22
- type: 'confirm',
23
- name: 'certain',
21
+ const certain = await confirm({
24
22
  message: `Are you sure you want to delete ${chalk.bold('all')} logs for function ${chalk.yellow(name)}?`,
25
23
  default: false,
26
24
  });
@@ -46,14 +46,14 @@ export async function initDeployedBlueprintConfig(config) {
46
46
  if (!scopeType || !scopeId)
47
47
  return { ok: false, error: 'Missing scope configuration for Blueprint' };
48
48
  if (!stackId)
49
- return { ok: false, error: 'Missing deployment configuration for Blueprint' };
49
+ return { ok: false, error: 'Missing Stack deployment configuration for Blueprint' };
50
50
  }
51
51
  const auth = { token: config.token, scopeType, scopeId };
52
52
  const stackResponse = await getStack({ stackId, auth });
53
53
  if (!stackResponse.ok) {
54
- config.log(`Could not retrieve deployment info for ${niceId(stackId)}.`);
54
+ config.log(`Could not retrieve Stack deployment info for ${niceId(stackId)}.`);
55
55
  config.log(`Run \`${config.bin} blueprints doctor\` for diagnostics.`);
56
- return { ok: false, error: 'Missing deployment' };
56
+ return { ok: false, error: 'Missing Stack deployment' };
57
57
  }
58
58
  return {
59
59
  ok: true,