@sanity/cli 8.21.0 → 8.22.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 (74) hide show
  1. package/README.md +106 -47
  2. package/codemods/dashboard.js +111 -0
  3. package/dist/actions/build/buildApp.js +1 -1
  4. package/dist/actions/build/buildApp.js.map +1 -1
  5. package/dist/actions/build/buildStudio.js +1 -1
  6. package/dist/actions/build/buildStudio.js.map +1 -1
  7. package/dist/actions/codemods/dashboard.js +113 -0
  8. package/dist/actions/codemods/dashboard.js.map +1 -0
  9. package/dist/actions/codemods/index.js +2 -0
  10. package/dist/actions/codemods/index.js.map +1 -1
  11. package/dist/actions/codemods/types.js.map +1 -1
  12. package/dist/actions/deploy/deployApp.js +13 -6
  13. package/dist/actions/deploy/deployApp.js.map +1 -1
  14. package/dist/actions/deploy/deployChecks.js +12 -7
  15. package/dist/actions/deploy/deployChecks.js.map +1 -1
  16. package/dist/actions/deploy/deployRunner.js +14 -8
  17. package/dist/actions/deploy/deployRunner.js.map +1 -1
  18. package/dist/actions/deploy/deployStudio.js +39 -4
  19. package/dist/actions/deploy/deployStudio.js.map +1 -1
  20. package/dist/actions/deploy/resolveDeployTarget.js +7 -6
  21. package/dist/actions/deploy/resolveDeployTarget.js.map +1 -1
  22. package/dist/actions/init/project/promptForAppTemplateSetup.js +22 -0
  23. package/dist/actions/init/project/promptForAppTemplateSetup.js.map +1 -1
  24. package/dist/actions/schema/listSchemas.js +2 -3
  25. package/dist/actions/schema/listSchemas.js.map +1 -1
  26. package/dist/actions/typegen/generateResourceTypes.js +11 -8
  27. package/dist/actions/typegen/generateResourceTypes.js.map +1 -1
  28. package/dist/actions/typegen/watchResourceTypes.js +208 -0
  29. package/dist/actions/typegen/watchResourceTypes.js.map +1 -0
  30. package/dist/actions/undeploy/runUndeploy.js +14 -8
  31. package/dist/actions/undeploy/runUndeploy.js.map +1 -1
  32. package/dist/commands/codemod.js +15 -4
  33. package/dist/commands/codemod.js.map +1 -1
  34. package/dist/commands/context/get.js +3 -8
  35. package/dist/commands/context/get.js.map +1 -1
  36. package/dist/commands/context/imports/download.js +3 -8
  37. package/dist/commands/context/imports/download.js.map +1 -1
  38. package/dist/commands/context/imports/get.js +3 -8
  39. package/dist/commands/context/imports/get.js.map +1 -1
  40. package/dist/commands/context/imports/list.js +3 -8
  41. package/dist/commands/context/imports/list.js.map +1 -1
  42. package/dist/commands/context/jobs/get.js +8 -8
  43. package/dist/commands/context/jobs/get.js.map +1 -1
  44. package/dist/commands/context/list.js +2 -6
  45. package/dist/commands/context/list.js.map +1 -1
  46. package/dist/commands/deploy.js +1 -0
  47. package/dist/commands/deploy.js.map +1 -1
  48. package/dist/commands/doctor.js +2 -1
  49. package/dist/commands/doctor.js.map +1 -1
  50. package/dist/commands/openapi/list.js +2 -4
  51. package/dist/commands/openapi/list.js.map +1 -1
  52. package/dist/commands/projects/create.js +3 -6
  53. package/dist/commands/projects/create.js.map +1 -1
  54. package/dist/commands/schemas/list.js +1 -3
  55. package/dist/commands/schemas/list.js.map +1 -1
  56. package/dist/commands/tokens/create.js +2 -5
  57. package/dist/commands/tokens/create.js.map +1 -1
  58. package/dist/commands/tokens/list.js +2 -6
  59. package/dist/commands/tokens/list.js.map +1 -1
  60. package/dist/commands/tokens/rotate.js +2 -5
  61. package/dist/commands/tokens/rotate.js.map +1 -1
  62. package/dist/commands/typegen/generate.js +83 -45
  63. package/dist/commands/typegen/generate.js.map +1 -1
  64. package/dist/commands/undeploy.js +1 -0
  65. package/dist/commands/undeploy.js.map +1 -1
  66. package/dist/commands/whoami.js +5 -11
  67. package/dist/commands/whoami.js.map +1 -1
  68. package/dist/exports/invokeSanityCli/index.js +26 -6
  69. package/dist/exports/invokeSanityCli/index.js.map +1 -1
  70. package/dist/generated/apiRoutes.js +11 -26
  71. package/dist/generated/apiRoutes.js.map +1 -1
  72. package/dist/telemetry/init.telemetry.js.map +1 -1
  73. package/oclif.manifest.json +1323 -1294
  74. package/package.json +6 -5
@@ -1,4 +1,4 @@
1
- import { Args, Flags } from '@oclif/core';
1
+ import { Args } from '@oclif/core';
2
2
  import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
3
  import { getErrorMessage } from '@sanity/cli-core/errors';
4
4
  import { isHttpError } from '@sanity/client';
@@ -18,18 +18,13 @@ export class DownloadImportCommand extends SanityCommand {
18
18
  })
19
19
  };
20
20
  static description = 'Get a short-lived signed URL for the original uploaded bytes of a file import';
21
+ static enableJsonFlag = true;
21
22
  static examples = [
22
23
  {
23
24
  command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456',
24
25
  description: 'Get a download URL for an uploaded file'
25
26
  }
26
27
  ];
27
- static flags = {
28
- json: Flags.boolean({
29
- default: false,
30
- description: 'Output the download URL in JSON format'
31
- })
32
- };
33
28
  async run() {
34
29
  const { importId, knowledgeBaseId } = this.args;
35
30
  const { json } = this.flags;
@@ -48,7 +43,7 @@ export class DownloadImportCommand extends SanityCommand {
48
43
  });
49
44
  }
50
45
  if (json) {
51
- this.log(JSON.stringify(download, null, 2));
46
+ this.logJson(download);
52
47
  return;
53
48
  }
54
49
  const padTo = 7 // "Expires" is the longest key
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/commands/context/imports/download.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {downloadImport} from '../../../services/context.js'\n\nconst downloadImportDebug = subdebug('context:imports:download')\n\nexport class DownloadImportCommand extends SanityCommand<typeof DownloadImportCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first\n importId: Args.string({\n description: 'Import ID',\n required: true,\n }),\n }\n\n static override description =\n 'Get a short-lived signed URL for the original uploaded bytes of a file import'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456',\n description: 'Get a download URL for an uploaded file',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n default: false,\n description: 'Output the download URL in JSON format',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {importId, knowledgeBaseId} = this.args\n const {json} = this.flags\n\n let download\n try {\n download = await downloadImport(knowledgeBaseId, importId)\n } catch (error) {\n downloadImportDebug('Error getting import download URL', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Import \"${importId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to get import download URL: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.log(JSON.stringify(download, null, 2))\n return\n }\n\n const padTo = 7 // \"Expires\" is the longest key\n this.log(formatKeyValue('URL', download.url, {padTo}))\n this.log(formatKeyValue('Expires', download.expiresAt, {padTo}))\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","formatKeyValue","downloadImport","downloadImportDebug","DownloadImportCommand","args","knowledgeBaseId","string","description","required","importId","examples","command","flags","json","boolean","default","run","download","error","statusCode","exit","RUNTIME_ERROR","log","JSON","stringify","padTo","url","expiresAt"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,cAAc,QAAO,+BAA8B;AAE3D,MAAMC,sBAAsBL,SAAS;AAErC,OAAO,MAAMM,8BAA8BP;IACzC,OAAgBQ,OAAO;QACrBC,iBAA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["../../../../src/commands/context/imports/download.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {downloadImport} from '../../../services/context.js'\n\nconst downloadImportDebug = subdebug('context:imports:download')\n\nexport class DownloadImportCommand extends SanityCommand<typeof DownloadImportCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first\n importId: Args.string({\n description: 'Import ID',\n required: true,\n }),\n }\n\n static override description =\n 'Get a short-lived signed URL for the original uploaded bytes of a file import'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456',\n description: 'Get a download URL for an uploaded file',\n },\n ]\n\n public async run(): Promise<void> {\n const {importId, knowledgeBaseId} = this.args\n const {json} = this.flags\n\n let download\n try {\n download = await downloadImport(knowledgeBaseId, importId)\n } catch (error) {\n downloadImportDebug('Error getting import download URL', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Import \"${importId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to get import download URL: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(download)\n return\n }\n\n const padTo = 7 // \"Expires\" is the longest key\n this.log(formatKeyValue('URL', download.url, {padTo}))\n this.log(formatKeyValue('Expires', download.expiresAt, {padTo}))\n }\n}\n"],"names":["Args","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","formatKeyValue","downloadImport","downloadImportDebug","DownloadImportCommand","args","knowledgeBaseId","string","description","required","importId","enableJsonFlag","examples","command","run","json","flags","download","error","statusCode","exit","RUNTIME_ERROR","logJson","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AO,CAACL;YACb;QACF;QAEA,MAAMM,QAAQ,EAAE,+BAA+B;;QAC/C,IAAI,CAACC,GAAG,CAACvB,eAAe,OAAOgB,SAASQ,GAAG,EAAE;YAACF;QAAK;QACnD,IAAI,CAACC,GAAG,CAACvB,eAAe,WAAWgB,SAASS,SAAS,EAAE;YAACH;QAAK;IAC/D;AACF"}
@@ -1,4 +1,4 @@
1
- import { Args, Flags } from '@oclif/core';
1
+ import { Args } from '@oclif/core';
2
2
  import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
3
  import { getErrorMessage } from '@sanity/cli-core/errors';
4
4
  import { isHttpError } from '@sanity/client';
@@ -18,6 +18,7 @@ export class GetImportCommand extends SanityCommand {
18
18
  })
19
19
  };
20
20
  static description = 'Get details of an import';
21
+ static enableJsonFlag = true;
21
22
  static examples = [
22
23
  {
23
24
  command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456',
@@ -28,12 +29,6 @@ export class GetImportCommand extends SanityCommand {
28
29
  description: 'Output the import as JSON'
29
30
  }
30
31
  ];
31
- static flags = {
32
- json: Flags.boolean({
33
- default: false,
34
- description: 'Output the import in JSON format'
35
- })
36
- };
37
32
  async run() {
38
33
  const { importId, knowledgeBaseId } = this.args;
39
34
  const { json } = this.flags;
@@ -52,7 +47,7 @@ export class GetImportCommand extends SanityCommand {
52
47
  });
53
48
  }
54
49
  if (json) {
55
- this.log(JSON.stringify(importDetail, null, 2));
50
+ this.logJson(importDetail);
56
51
  return;
57
52
  }
58
53
  const padTo = 9 // "Completed" is the longest key
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/commands/context/imports/get.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {getImport} from '../../../services/context.js'\n\nconst getImportDebug = subdebug('context:imports:get')\n\nexport class GetImportCommand extends SanityCommand<typeof GetImportCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first\n importId: Args.string({\n description: 'Import ID',\n required: true,\n }),\n }\n\n static override description = 'Get details of an import'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456',\n description: 'Get details of a specific import',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456 --json',\n description: 'Output the import as JSON',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n default: false,\n description: 'Output the import in JSON format',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {importId, knowledgeBaseId} = this.args\n const {json} = this.flags\n\n let importDetail\n try {\n importDetail = await getImport(knowledgeBaseId, importId)\n } catch (error) {\n getImportDebug('Error getting import', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Import \"${importId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to get import: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.log(JSON.stringify(importDetail, null, 2))\n return\n }\n\n const padTo = 9 // \"Completed\" is the longest key\n this.log(formatKeyValue('ID', importDetail.id, {padTo}))\n this.log(formatKeyValue('Name', importDetail.name ?? '-', {padTo}))\n this.log(formatKeyValue('Kind', importDetail.sourceKind, {padTo}))\n this.log(formatKeyValue('Status', importDetail.status, {padTo}))\n this.log(formatKeyValue('Detail', importDetail.statusDetail ?? '-', {padTo}))\n this.log(formatKeyValue('Error', importDetail.error ?? '-', {padTo}))\n this.log(formatKeyValue('Sources', importDetail.sourceCount, {padTo}))\n this.log(\n formatKeyValue(\n 'Distilled',\n `${importDetail.distilledCount}/${importDetail.totalDistillableCount}`,\n {padTo},\n ),\n )\n this.log(formatKeyValue('Created', importDetail.createdAt, {padTo}))\n this.log(formatKeyValue('Completed', importDetail.completedAt ?? '-', {padTo}))\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","formatKeyValue","getImport","getImportDebug","GetImportCommand","args","knowledgeBaseId","string","description","required","importId","examples","command","flags","json","boolean","default","run","importDetail","error","statusCode","exit","RUNTIME_ERROR","log","JSON","stringify","padTo","id","name","sourceKind","status","statusDetail","sourceCount","distilledCount","totalDistillableCount","createdAt","completedAt"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,SAAS,QAAO,+BAA8B;AAEtD,MAAMC,iBAAiBL,SAAS;AAEhC,OAAO,MAAMM,yBAAyBP;IACpC,OAAgBQ,OAAO;QACrBC,iBAAiBZ,KAAKa,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;QACA,gGAAgG;QAChGC,UAAUhB,KAAKa,MAAM,CAAC;YACpBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,2BAA0B;IAExD,OAAgBG,WAAW;QACzB;YACEC,SAAS;YACTJ,aAAa;QACf;QACA;YACEI,SAAS;YACTJ,aAAa;QACf;KACD,CAAA;IAED,OAAgBK,QAAQ;QACtBC,MAAMnB,MAAMoB,OAAO,CAAC;YAClBC,SAAS;YACTR,aAAa;QACf;IACF,EAAqB;IAErB,MAAaS,MAAqB;QAChC,MAAM,EAACP,QAAQ,EAAEJ,eAAe,EAAC,GAAG,IAAI,CAACD,IAAI;QAC7C,MAAM,EAACS,IAAI,EAAC,GAAG,IAAI,CAACD,KAAK;QAEzB,IAAIK;QAC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AI,CAACH,GAAG,CAACtB,eAAe,WAAWiB,aAAaiB,SAAS,EAAE;YAACT;QAAK;QACjE,IAAI,CAACH,GAAG,CAACtB,eAAe,aAAaiB,aAAakB,WAAW,IAAI,KAAK;YAACV;QAAK;IAC9E;AACF"}
1
+ {"version":3,"sources":["../../../../src/commands/context/imports/get.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {getImport} from '../../../services/context.js'\n\nconst getImportDebug = subdebug('context:imports:get')\n\nexport class GetImportCommand extends SanityCommand<typeof GetImportCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first\n importId: Args.string({\n description: 'Import ID',\n required: true,\n }),\n }\n\n static override description = 'Get details of an import'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456',\n description: 'Get details of a specific import',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 import-def456 --json',\n description: 'Output the import as JSON',\n },\n ]\n\n public async run(): Promise<void> {\n const {importId, knowledgeBaseId} = this.args\n const {json} = this.flags\n\n let importDetail\n try {\n importDetail = await getImport(knowledgeBaseId, importId)\n } catch (error) {\n getImportDebug('Error getting import', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Import \"${importId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to get import: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(importDetail)\n return\n }\n\n const padTo = 9 // \"Completed\" is the longest key\n this.log(formatKeyValue('ID', importDetail.id, {padTo}))\n this.log(formatKeyValue('Name', importDetail.name ?? '-', {padTo}))\n this.log(formatKeyValue('Kind', importDetail.sourceKind, {padTo}))\n this.log(formatKeyValue('Status', importDetail.status, {padTo}))\n this.log(formatKeyValue('Detail', importDetail.statusDetail ?? '-', {padTo}))\n this.log(formatKeyValue('Error', importDetail.error ?? '-', {padTo}))\n this.log(formatKeyValue('Sources', importDetail.sourceCount, {padTo}))\n this.log(\n formatKeyValue(\n 'Distilled',\n `${importDetail.distilledCount}/${importDetail.totalDistillableCount}`,\n {padTo},\n ),\n )\n this.log(formatKeyValue('Created', importDetail.createdAt, {padTo}))\n this.log(formatKeyValue('Completed', importDetail.completedAt ?? '-', {padTo}))\n }\n}\n"],"names":["Args","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","formatKeyValue","getImport","getImportDebug","GetImportCommand","args","knowledgeBaseId","string","description","required","importId","enableJsonFlag","examples","command","run","json","flags","importDetail","error","statusCode","exit","RUNTIME_ERROR","logJson","padTo","log","id","name","sourceKind","status","statusDetail","sourceCount","distilledCount","totalDistillableCount","createdAt","completedAt"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAChC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,SAAS,QAAO,+BAA8B;AAEtD,MAAMC,iBAAiBL,SAAS;AAEhC,OAAO,MAAMM,yBAAyBP;IACpC,OAAgBQ,OAAO;QACrBC,iBAAiBX,KAAKY,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;QACA,gGAAgG;QAChGC,UAAUf,KAAKY,MAAM,CAAC;YACpBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,2BAA0B;IAExD,OAAgBG,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;YACEC,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I,CAACC,GAAG,CAACvB,eAAe,WAAWgB,aAAaa,WAAW,EAAE;YAACP;QAAK;QACnE,IAAI,CAACC,GAAG,CACNvB,eACE,aACA,GAAGgB,aAAac,cAAc,CAAC,CAAC,EAAEd,aAAae,qBAAqB,EAAE,EACtE;YAACT;QAAK;QAGV,IAAI,CAACC,GAAG,CAACvB,eAAe,WAAWgB,aAAagB,SAAS,EAAE;YAACV;QAAK;QACjE,IAAI,CAACC,GAAG,CAACvB,eAAe,aAAagB,aAAaiB,WAAW,IAAI,KAAK;YAACX;QAAK;IAC9E;AACF"}
@@ -1,4 +1,4 @@
1
- import { Args, Flags } from '@oclif/core';
1
+ import { Args } from '@oclif/core';
2
2
  import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
3
  import { getErrorMessage } from '@sanity/cli-core/errors';
4
4
  import { isHttpError } from '@sanity/client';
@@ -13,6 +13,7 @@ export class ListImportsCommand extends SanityCommand {
13
13
  })
14
14
  };
15
15
  static description = 'List imports for a knowledge base';
16
+ static enableJsonFlag = true;
16
17
  static examples = [
17
18
  {
18
19
  command: '<%= config.bin %> <%= command.id %> kb-abc123',
@@ -23,12 +24,6 @@ export class ListImportsCommand extends SanityCommand {
23
24
  description: 'Output imports as JSON'
24
25
  }
25
26
  ];
26
- static flags = {
27
- json: Flags.boolean({
28
- default: false,
29
- description: 'Output imports in JSON format'
30
- })
31
- };
32
27
  async run() {
33
28
  const { knowledgeBaseId } = this.args;
34
29
  const { json } = this.flags;
@@ -47,7 +42,7 @@ export class ListImportsCommand extends SanityCommand {
47
42
  });
48
43
  }
49
44
  if (json) {
50
- this.log(JSON.stringify(imports, null, 2));
45
+ this.logJson(imports);
51
46
  return;
52
47
  }
53
48
  if (imports.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/commands/context/imports/list.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {listImports} from '../../../services/context.js'\nimport {Table} from '../../../util/responsiveTable.js'\n\nconst listImportsDebug = subdebug('context:imports:list')\n\nexport class ListImportsCommand extends SanityCommand<typeof ListImportsCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n }\n\n static override description = 'List imports for a knowledge base'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123',\n description: 'List all imports for a knowledge base',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 --json',\n description: 'Output imports as JSON',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n default: false,\n description: 'Output imports in JSON format',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {knowledgeBaseId} = this.args\n const {json} = this.flags\n\n let imports\n try {\n imports = await listImports(knowledgeBaseId)\n } catch (error) {\n listImportsDebug('Error listing imports', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Knowledge base \"${knowledgeBaseId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to list imports: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.log(JSON.stringify(imports, null, 2))\n return\n }\n\n if (imports.length === 0) {\n this.log('No imports found')\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'name', title: 'Name'},\n {alignment: 'left', name: 'kind', title: 'Kind'},\n {alignment: 'left', name: 'status', title: 'Status'},\n {alignment: 'right', name: 'sources', title: 'Sources'},\n {alignment: 'left', name: 'createdAt', title: 'Created'},\n ],\n })\n\n for (const {createdAt, id, name, sourceCount, sourceKind, status} of imports) {\n table.addRow({\n createdAt,\n id,\n kind: sourceKind,\n name: name ?? '-',\n sources: sourceCount,\n status,\n })\n }\n\n this.log(table.render())\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","listImports","Table","listImportsDebug","ListImportsCommand","args","knowledgeBaseId","string","description","required","examples","command","flags","json","boolean","default","run","imports","error","statusCode","exit","RUNTIME_ERROR","log","JSON","stringify","length","table","columns","alignment","name","title","createdAt","id","sourceCount","sourceKind","status","addRow","kind","sources","render"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,WAAW,QAAO,+BAA8B;AACxD,SAAQC,KAAK,QAAO,mCAAkC;AAEtD,MAAMC,mBAAmBL,SAAS;AAElC,OAAO,MAAMM,2BAA2BP;IACtC,OAAgBQ,OAAO;QACrBC,iBAAiBZ,KAAKa,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,oCAAmC;IAEjE,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtBC,MAAMlB,MAAMmB,OAAO,CAAC;YAClBC,SAAS;YACTP,aAAa;QACf;IACF,EAAqB;IAErB,MAAaQ,MAAqB;QAChC,MAAM,EAACV,eAAe,EAAC,GAAG,IAAI,CAACD,IAAI;QACnC,MAAM,EAACQ,IAAI,EAAC,GAAG,IAAI,CAACD,KAAK;QAEzB,IAAIK;QACJ,IAAI;YACFA,UAAU,MAAMhB,YAAYK;QAC9B,EAAE,OAAOY,OAAO;YACdf,iBAAiB,yBAAyBe;YAC1C,IAAIlB,YAAYkB,UAAUA,MAAMC,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACD,KAAK,CAAC,CAAC,gBAAgB,EAAEZ,gBAAgB,WAAW,CAAC,EAAE;oBAC1Dc,MAAMxB,UAAUyB,aAAa;gBAC/B;YACF;YACA,IAAI,CAACH,KAAK,CAAC,CAAC,wBAAwB,EAAEnB,gBAAgBmB,QAAQ,EAAE;gBAC9DE,MAAMxB,UAAUyB,aAAa;YAC/B;QACF;QAEA,IAAIR,MAAM;YACR,IAAI,CAACS,GAAG,CAACC,KAAKC,SAAS,CAACP,SAAS,MAAM;YACvC;QACF;QAEA,IAAIA,QAAQQ,MAAM,KAAK,GAAG;YACxB,IAAI,CAACH,GAAG,CAAC;YACT;QACF;QAEA,MAAMI,QAAQ,IAAIxB,MAAM;YACtByB,SAAS;gBACP;oBAACC,WAAW;oBAAQC,MAAM;oBAAMC,OAAO;gBAAI;gBAC3C;oBAACF,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;gBAC/C;oBAACF,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;gBAC/C;oBAACF,WAAW;oBAAQC,MAAM;oBAAUC,OAAO;gBAAQ;gBACnD;oBAACF,WAAW;oBAASC,MAAM;oBAAWC,OAAO;gBAAS;gBACtD;oBAACF,WAAW;oBAAQC,MAAM;oBAAaC,OAAO;gBAAS;aACxD;QACH;QAEA,KAAK,MAAM,EAACC,SAAS,EAAEC,EAAE,EAAEH,IAAI,EAAEI,WAAW,EAAEC,UAAU,EAAEC,MAAM,EAAC,IAAIlB,QAAS;YAC5ES,MAAMU,MAAM,CAAC;gBACXL;gBACAC;gBACAK,MAAMH;gBACNL,MAAMA,QAAQ;gBACdS,SAASL;gBACTE;YACF;QACF;QAEA,IAAI,CAACb,GAAG,CAACI,MAAMa,MAAM;IACvB;AACF"}
1
+ {"version":3,"sources":["../../../../src/commands/context/imports/list.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {listImports} from '../../../services/context.js'\nimport {Table} from '../../../util/responsiveTable.js'\n\nconst listImportsDebug = subdebug('context:imports:list')\n\nexport class ListImportsCommand extends SanityCommand<typeof ListImportsCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n }\n\n static override description = 'List imports for a knowledge base'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123',\n description: 'List all imports for a knowledge base',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 --json',\n description: 'Output imports as JSON',\n },\n ]\n\n public async run(): Promise<void> {\n const {knowledgeBaseId} = this.args\n const {json} = this.flags\n\n let imports\n try {\n imports = await listImports(knowledgeBaseId)\n } catch (error) {\n listImportsDebug('Error listing imports', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Knowledge base \"${knowledgeBaseId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to list imports: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(imports)\n return\n }\n\n if (imports.length === 0) {\n this.log('No imports found')\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'name', title: 'Name'},\n {alignment: 'left', name: 'kind', title: 'Kind'},\n {alignment: 'left', name: 'status', title: 'Status'},\n {alignment: 'right', name: 'sources', title: 'Sources'},\n {alignment: 'left', name: 'createdAt', title: 'Created'},\n ],\n })\n\n for (const {createdAt, id, name, sourceCount, sourceKind, status} of imports) {\n table.addRow({\n createdAt,\n id,\n kind: sourceKind,\n name: name ?? '-',\n sources: sourceCount,\n status,\n })\n }\n\n this.log(table.render())\n }\n}\n"],"names":["Args","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","listImports","Table","listImportsDebug","ListImportsCommand","args","knowledgeBaseId","string","description","required","enableJsonFlag","examples","command","run","json","flags","imports","error","statusCode","exit","RUNTIME_ERROR","logJson","length","log","table","columns","alignment","name","title","createdAt","id","sourceCount","sourceKind","status","addRow","kind","sources","render"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAChC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,WAAW,QAAO,+BAA8B;AACxD,SAAQC,KAAK,QAAO,mCAAkC;AAEtD,MAAMC,mBAAmBL,SAAS;AAElC,OAAO,MAAMM,2BAA2BP;IACtC,OAAgBQ,OAAO;QACrBC,iBAAiBX,KAAKY,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,oCAAmC;IAEjE,OAAgBE,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTJ,aAAa;QACf;QACA;YACEI,SAAS;YACTJ,aAAa;QACf;KACD,CAAA;IAED,MAAaK,MAAqB;QAChC,MAAM,EAACP,eAAe,EAAC,GAAG,IAAI,CAACD,IAAI;QACnC,MAAM,EAACS,IAAI,EAAC,GAAG,IAAI,CAACC,KAAK;QAEzB,IAAIC;QACJ,IAAI;YACFA,UAAU,MAAMf,YAAYK;QAC9B,EAAE,OAAOW,OAAO;YACdd,iBAAiB,yBAAyBc;YAC1C,IAAIjB,YAAYiB,UAAUA,MAAMC,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACD,KAAK,CAAC,CAAC,gBAAgB,EAAEX,gBAAgB,WAAW,CAAC,EAAE;oBAC1Da,MAAMvB,UAAUwB,aAAa;gBAC/B;YACF;YACA,IAAI,CAACH,KAAK,CAAC,CAAC,wBAAwB,EAAElB,gBAAgBkB,QAAQ,EAAE;gBAC9DE,MAAMvB,UAAUwB,aAAa;YAC/B;QACF;QAEA,IAAIN,MAAM;YACR,IAAI,CAACO,OAAO,CAACL;YACb;QACF;QAEA,IAAIA,QAAQM,MAAM,KAAK,GAAG;YACxB,IAAI,CAACC,GAAG,CAAC;YACT;QACF;QAEA,MAAMC,QAAQ,IAAItB,MAAM;YACtBuB,SAAS;gBACP;oBAACC,WAAW;oBAAQC,MAAM;oBAAMC,OAAO;gBAAI;gBAC3C;oBAACF,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;gBAC/C;oBAACF,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;gBAC/C;oBAACF,WAAW;oBAAQC,MAAM;oBAAUC,OAAO;gBAAQ;gBACnD;oBAACF,WAAW;oBAASC,MAAM;oBAAWC,OAAO;gBAAS;gBACtD;oBAACF,WAAW;oBAAQC,MAAM;oBAAaC,OAAO;gBAAS;aACxD;QACH;QAEA,KAAK,MAAM,EAACC,SAAS,EAAEC,EAAE,EAAEH,IAAI,EAAEI,WAAW,EAAEC,UAAU,EAAEC,MAAM,EAAC,IAAIjB,QAAS;YAC5EQ,MAAMU,MAAM,CAAC;gBACXL;gBACAC;gBACAK,MAAMH;gBACNL,MAAMA,QAAQ;gBACdS,SAASL;gBACTE;YACF;QACF;QAEA,IAAI,CAACV,GAAG,CAACC,MAAMa,MAAM;IACvB;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { Args, Flags } from '@oclif/core';
2
2
  import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
- import { getErrorMessage } from '@sanity/cli-core/errors';
3
+ import { getErrorMessage, JsonOutputError } from '@sanity/cli-core/errors';
4
4
  import { isHttpError } from '@sanity/client';
5
5
  import { watchJob } from '../../../actions/context/watchJob.js';
6
6
  import { formatKeyValue } from '../../../actions/debug/output.js';
@@ -19,6 +19,7 @@ export class GetJobCommand extends SanityCommand {
19
19
  })
20
20
  };
21
21
  static description = 'Get the status of a knowledge base job';
22
+ static enableJsonFlag = true;
22
23
  static examples = [
23
24
  {
24
25
  command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456',
@@ -30,10 +31,6 @@ export class GetJobCommand extends SanityCommand {
30
31
  }
31
32
  ];
32
33
  static flags = {
33
- json: Flags.boolean({
34
- default: false,
35
- description: 'Output the job in JSON format'
36
- }),
37
34
  watch: Flags.boolean({
38
35
  default: false,
39
36
  description: 'Poll until the job reaches a terminal state'
@@ -58,8 +55,11 @@ export class GetJobCommand extends SanityCommand {
58
55
  exit: exitCodes.RUNTIME_ERROR
59
56
  });
60
57
  }
58
+ const jobFailed = watch && job.status !== 'succeeded';
59
+ const failureMessage = `Job ${job.status}${job.error ? `: ${job.error}` : ''}`;
61
60
  if (json) {
62
- this.log(JSON.stringify(job, null, 2));
61
+ if (jobFailed) throw new JsonOutputError(failureMessage, job, exitCodes.RUNTIME_ERROR);
62
+ this.logJson(job);
63
63
  } else {
64
64
  const padTo = 9 // "Completed" is the longest key
65
65
  ;
@@ -79,8 +79,8 @@ export class GetJobCommand extends SanityCommand {
79
79
  padTo
80
80
  }));
81
81
  }
82
- if (watch && job.status !== 'succeeded') {
83
- this.error(`Job ${job.status}${job.error ? `: ${job.error}` : ''}`, {
82
+ if (jobFailed) {
83
+ this.error(failureMessage, {
84
84
  exit: exitCodes.RUNTIME_ERROR
85
85
  });
86
86
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/commands/context/jobs/get.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {watchJob} from '../../../actions/context/watchJob.js'\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {getJob} from '../../../services/context.js'\n\nconst getJobDebug = subdebug('context:jobs:get')\n\nexport class GetJobCommand extends SanityCommand<typeof GetJobCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first\n jobId: Args.string({\n description: 'Job ID',\n required: true,\n }),\n }\n\n static override description = 'Get the status of a knowledge base job'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456',\n description: 'Get the current status of a job',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456 --watch',\n description: 'Wait for the job to finish (non-zero exit if it does not succeed)',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n default: false,\n description: 'Output the job in JSON format',\n }),\n watch: Flags.boolean({\n default: false,\n description: 'Poll until the job reaches a terminal state',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {jobId, knowledgeBaseId} = this.args\n const {json, watch} = this.flags\n\n let job\n try {\n job = watch\n ? await watchJob(knowledgeBaseId, jobId, {label: 'Waiting for job'})\n : await getJob(knowledgeBaseId, jobId)\n } catch (error) {\n getJobDebug('Error getting job', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Job \"${jobId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to get job: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.log(JSON.stringify(job, null, 2))\n } else {\n const padTo = 9 // \"Completed\" is the longest key\n this.log(formatKeyValue('ID', job.id, {padTo}))\n this.log(formatKeyValue('Status', job.status, {padTo}))\n this.log(formatKeyValue('Started', job.startedAt ?? '-', {padTo}))\n this.log(formatKeyValue('Completed', job.completedAt ?? '-', {padTo}))\n this.log(formatKeyValue('Error', job.error ?? '-', {padTo}))\n }\n\n if (watch && job.status !== 'succeeded') {\n this.error(`Job ${job.status}${job.error ? `: ${job.error}` : ''}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","watchJob","formatKeyValue","getJob","getJobDebug","GetJobCommand","args","knowledgeBaseId","string","description","required","jobId","examples","command","flags","json","boolean","default","watch","run","job","label","error","statusCode","exit","RUNTIME_ERROR","log","JSON","stringify","padTo","id","status","startedAt","completedAt"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,QAAQ,QAAO,uCAAsC;AAC7D,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,MAAM,QAAO,+BAA8B;AAEnD,MAAMC,cAAcN,SAAS;AAE7B,OAAO,MAAMO,sBAAsBR;IACjC,OAAgBS,OAAO;QACrBC,iBAAiBb,KAAKc,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;QACA,gGAAgG;QAChGC,OAAOjB,KAAKc,MAAM,CAAC;YACjBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,yCAAwC;IAEtE,OAAgBG,WAAW;QACzB;YACEC,SAAS;YACTJ,aAAa;QACf;QACA;YACEI,SAAS;YACTJ,aAAa;QACf;KACD,CAAA;IAED,OAAgBK,QAAQ;QACtBC,MAAMpB,MAAMqB,OAAO,CAAC;YAClBC,SAAS;YACTR,aAAa;QACf;QACAS,OAAOvB,MAAMqB,OAAO,CAAC;YACnBC,SAAS;YACTR,aAAa;QACf;IACF,EAAqB;IAErB,MAAaU,MAAqB;QAChC,MAAM,EAACR,KAAK,EAAEJ,eAAe,EAAC,GAAG,IAAI,CAACD,IAAI;QAC1C,MAAM,EAACS,IAAI,EAAEG,KAAK,EAAC,GAAG,IAAI,CAACJ,KAAK;QAEhC,IAAIM;QACJ,IAAI;YACFA,MAAMF,QACF,MAAMjB,SAASM,iBAAiBI,OAAO;gBAACU,OAAO;YAAiB,KAChE,MAAMlB,OAAOI,iBAAiBI;QACpC,EAAE,OAAOW,OAAO;YACdlB,YAAY,qBAAqBkB;YACjC,IAAItB,YAAYsB,UAAUA,MAAMC,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACD,KAAK,CAAC,CAAC,KAAK,EAAEX,MAAM,+BAA+B,EAAEJ,gBAAgB,CAAC,CAAC,EAAE;oBAC5EiB,MAAM5B,UAAU6B,aAAa;gBAC/B;YACF;YACA,IAAI,CAACH,KAAK,CAAC,CAAC,mBAAmB,EAAEvB,gBAAgBuB,QAAQ,EAAE;gBACzDE,MAAM5B,UAAU6B,aAAa;YAC/B;QACF;QAEA,IAAIV,MAAM;YACR,IAAI,CAACW,GAAG,CAACC,KAAKC,SAAS,CAACR,KAAK,MAAM;QACrC,OAAO;YACL,MAAMS,QAAQ,EAAE,iCAAiC;;YACjD,IAAI,CAACH,GAAG,CAACxB,eAAe,MAAMkB,IAAIU,EAAE,EAAE;gBAACD;YAAK;YAC5C,IAAI,CAACH,GAAG,CAACxB,eAAe,UAAUkB,IAAIW,MAAM,EAAE;gBAACF;YAAK;YACpD,IAAI,CAACH,GAAG,CAACxB,eAAe,WAAWkB,IAAIY,SAAS,IAAI,KAAK;gBAACH;YAAK;YAC/D,IAAI,CAACH,GAAG,CAACxB,eAAe,aAAakB,IAAIa,WAAW,IAAI,KAAK;gBAACJ;YAAK;YACnE,IAAI,CAACH,GAAG,CAACxB,eAAe,SAASkB,IAAIE,KAAK,IAAI,KAAK;gBAACO;YAAK;QAC3D;QAEA,IAAIX,SAASE,IAAIW,MAAM,KAAK,aAAa;YACvC,IAAI,CAACT,KAAK,CAAC,CAAC,IAAI,EAAEF,IAAIW,MAAM,GAAGX,IAAIE,KAAK,GAAG,CAAC,EAAE,EAAEF,IAAIE,KAAK,EAAE,GAAG,IAAI,EAAE;gBAClEE,MAAM5B,UAAU6B,aAAa;YAC/B;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../src/commands/context/jobs/get.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage, JsonOutputError} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {watchJob} from '../../../actions/context/watchJob.js'\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {getJob} from '../../../services/context.js'\n\nconst getJobDebug = subdebug('context:jobs:get')\n\nexport class GetJobCommand extends SanityCommand<typeof GetJobCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first\n jobId: Args.string({\n description: 'Job ID',\n required: true,\n }),\n }\n\n static override description = 'Get the status of a knowledge base job'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456',\n description: 'Get the current status of a job',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 job-def456 --watch',\n description: 'Wait for the job to finish (non-zero exit if it does not succeed)',\n },\n ]\n\n static override flags = {\n watch: Flags.boolean({\n default: false,\n description: 'Poll until the job reaches a terminal state',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {jobId, knowledgeBaseId} = this.args\n const {json, watch} = this.flags\n\n let job\n try {\n job = watch\n ? await watchJob(knowledgeBaseId, jobId, {label: 'Waiting for job'})\n : await getJob(knowledgeBaseId, jobId)\n } catch (error) {\n getJobDebug('Error getting job', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Job \"${jobId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to get job: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n const jobFailed = watch && job.status !== 'succeeded'\n const failureMessage = `Job ${job.status}${job.error ? `: ${job.error}` : ''}`\n if (json) {\n if (jobFailed) throw new JsonOutputError(failureMessage, job, exitCodes.RUNTIME_ERROR)\n this.logJson(job)\n } else {\n const padTo = 9 // \"Completed\" is the longest key\n this.log(formatKeyValue('ID', job.id, {padTo}))\n this.log(formatKeyValue('Status', job.status, {padTo}))\n this.log(formatKeyValue('Started', job.startedAt ?? '-', {padTo}))\n this.log(formatKeyValue('Completed', job.completedAt ?? '-', {padTo}))\n this.log(formatKeyValue('Error', job.error ?? '-', {padTo}))\n }\n\n if (jobFailed) {\n this.error(failureMessage, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","JsonOutputError","isHttpError","watchJob","formatKeyValue","getJob","getJobDebug","GetJobCommand","args","knowledgeBaseId","string","description","required","jobId","enableJsonFlag","examples","command","flags","watch","boolean","default","run","json","job","label","error","statusCode","exit","RUNTIME_ERROR","jobFailed","status","failureMessage","logJson","padTo","log","id","startedAt","completedAt"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,EAAEC,eAAe,QAAO,0BAAyB;AACxE,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,QAAQ,QAAO,uCAAsC;AAC7D,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,MAAM,QAAO,+BAA8B;AAEnD,MAAMC,cAAcP,SAAS;AAE7B,OAAO,MAAMQ,sBAAsBT;IACjC,OAAgBU,OAAO;QACrBC,iBAAiBd,KAAKe,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;QACA,gGAAgG;QAChGC,OAAOlB,KAAKe,MAAM,CAAC;YACjBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,yCAAwC;IAEtE,OAAgBG,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTL,aAAa;QACf;QACA;YACEK,SAAS;YACTL,aAAa;Q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e,UAAUmB,IAAIO,MAAM,EAAE;gBAACG;YAAK;YACpD,IAAI,CAACC,GAAG,CAAC9B,eAAe,WAAWmB,IAAIa,SAAS,IAAI,KAAK;gBAACH;YAAK;YAC/D,IAAI,CAACC,GAAG,CAAC9B,eAAe,aAAamB,IAAIc,WAAW,IAAI,KAAK;gBAACJ;YAAK;YACnE,IAAI,CAACC,GAAG,CAAC9B,eAAe,SAASmB,IAAIE,KAAK,IAAI,KAAK;gBAACQ;YAAK;QAC3D;QAEA,IAAIJ,WAAW;YACb,IAAI,CAACJ,KAAK,CAACM,gBAAgB;gBACzBJ,MAAM9B,UAAU+B,aAAa;YAC/B;QACF;IACF;AACF"}
@@ -1,4 +1,3 @@
1
- import { Flags } from '@oclif/core';
2
1
  import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
2
  import { getErrorMessage } from '@sanity/cli-core/errors';
4
3
  import { MissingOrganizationError, resolveOrganizationId } from '../../actions/context/resolveOrganizationId.js';
@@ -8,6 +7,7 @@ import { getOrganizationFlag } from '../../util/sharedFlags.js';
8
7
  const listContextDebug = subdebug('context:list');
9
8
  export class ListKnowledgeBasesCommand extends SanityCommand {
10
9
  static description = 'List knowledge bases in an organization';
10
+ static enableJsonFlag = true;
11
11
  static examples = [
12
12
  {
13
13
  command: '<%= config.bin %> <%= command.id %>',
@@ -26,10 +26,6 @@ export class ListKnowledgeBasesCommand extends SanityCommand {
26
26
  ...getOrganizationFlag({
27
27
  description: 'Organization to list knowledge bases for',
28
28
  semantics: 'override'
29
- }),
30
- json: Flags.boolean({
31
- default: false,
32
- description: 'Output knowledge bases in JSON format'
33
29
  })
34
30
  };
35
31
  async run() {
@@ -57,7 +53,7 @@ export class ListKnowledgeBasesCommand extends SanityCommand {
57
53
  });
58
54
  }
59
55
  if (json) {
60
- this.log(JSON.stringify(knowledgeBases, null, 2));
56
+ this.logJson(knowledgeBases);
61
57
  return;
62
58
  }
63
59
  if (knowledgeBases.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/context/list.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\n\nimport {\n MissingOrganizationError,\n resolveOrganizationId,\n} from '../../actions/context/resolveOrganizationId.js'\nimport {listKnowledgeBases} from '../../services/context.js'\nimport {Table} from '../../util/responsiveTable.js'\nimport {getOrganizationFlag} from '../../util/sharedFlags.js'\n\nconst listContextDebug = subdebug('context:list')\n\nexport class ListKnowledgeBasesCommand extends SanityCommand<typeof ListKnowledgeBasesCommand> {\n static override description = 'List knowledge bases in an organization'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List knowledge bases, selecting the organization interactively',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --organization org-abc123',\n description: 'List knowledge bases in a specific organization',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --organization org-abc123 --json',\n description: 'Output knowledge bases as JSON',\n },\n ]\n\n static override flags = {\n ...getOrganizationFlag({\n description: 'Organization to list knowledge bases for',\n semantics: 'override',\n }),\n json: Flags.boolean({\n default: false,\n description: 'Output knowledge bases in JSON format',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {json, organization} = this.flags\n\n let organizationId: string\n try {\n organizationId = await resolveOrganizationId({\n configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,\n flagOrganizationId: organization,\n unattended: this.isUnattended(),\n })\n } catch (error) {\n listContextDebug('Error resolving organization', error)\n this.error(getErrorMessage(error), {\n exit:\n error instanceof MissingOrganizationError\n ? exitCodes.USAGE_ERROR\n : exitCodes.RUNTIME_ERROR,\n })\n }\n\n let knowledgeBases\n try {\n knowledgeBases = await listKnowledgeBases(organizationId)\n } catch (error) {\n listContextDebug('Error listing knowledge bases', error)\n this.error(`Failed to list knowledge bases: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.log(JSON.stringify(knowledgeBases, null, 2))\n return\n }\n\n if (knowledgeBases.length === 0) {\n this.log('No knowledge bases found')\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'title', title: 'Title'},\n {alignment: 'left', name: 'state', title: 'State'},\n {alignment: 'right', name: 'openIssues', title: 'Open issues'},\n {alignment: 'left', name: 'updatedAt', title: 'Updated'},\n ],\n })\n\n for (const {openIssueCount, publicId, state, title, updatedAt} of knowledgeBases) {\n table.addRow({id: publicId, openIssues: openIssueCount, state, title, updatedAt})\n }\n\n this.log(table.render())\n }\n}\n"],"names":["Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","MissingOrganizationError","resolveOrganizationId","listKnowledgeBases","Table","getOrganizationFlag","listContextDebug","ListKnowledgeBasesCommand","description","examples","command","flags","semantics","json","boolean","default","run","organization","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","isUnattended","error","exit","USAGE_ERROR","RUNTIME_ERROR","knowledgeBases","log","JSON","stringify","length","table","columns","alignment","name","title","openIssueCount","publicId","state","updatedAt","addRow","id","openIssues","render"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AAEjC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AAEvD,SACEC,wBAAwB,EACxBC,qBAAqB,QAChB,iDAAgD;AACvD,SAAQC,kBAAkB,QAAO,4BAA2B;AAC5D,SAAQC,KAAK,QAAO,gCAA+B;AACnD,SAAQC,mBAAmB,QAAO,4BAA2B;AAE7D,MAAMC,mBAAmBP,SAAS;AAElC,OAAO,MAAMQ,kCAAkCT;IAC7C,OAAgBU,cAAc,0CAAyC;IAEvE,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;QACA;YACEE,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AACF,WAAW;oBAAQC,MAAM;oBAASC,OAAO;gBAAO;gBACjD;oBAACF,WAAW;oBAASC,MAAM;oBAAcC,OAAO;gBAAa;gBAC7D;oBAACF,WAAW;oBAAQC,MAAM;oBAAaC,OAAO;gBAAS;aACxD;QACH;QAEA,KAAK,MAAM,EAACC,cAAc,EAAEC,QAAQ,EAAEC,KAAK,EAAEH,KAAK,EAAEI,SAAS,EAAC,IAAIb,eAAgB;YAChFK,MAAMS,MAAM,CAAC;gBAACC,IAAIJ;gBAAUK,YAAYN;gBAAgBE;gBAAOH;gBAAOI;YAAS;QACjF;QAEA,IAAI,CAACZ,GAAG,CAACI,MAAMY,MAAM;IACvB;AACF"}
1
+ {"version":3,"sources":["../../../src/commands/context/list.ts"],"sourcesContent":["import {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\n\nimport {\n MissingOrganizationError,\n resolveOrganizationId,\n} from '../../actions/context/resolveOrganizationId.js'\nimport {listKnowledgeBases} from '../../services/context.js'\nimport {Table} from '../../util/responsiveTable.js'\nimport {getOrganizationFlag} from '../../util/sharedFlags.js'\n\nconst listContextDebug = subdebug('context:list')\n\nexport class ListKnowledgeBasesCommand extends SanityCommand<typeof ListKnowledgeBasesCommand> {\n static override description = 'List knowledge bases in an organization'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List knowledge bases, selecting the organization interactively',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --organization org-abc123',\n description: 'List knowledge bases in a specific organization',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --organization org-abc123 --json',\n description: 'Output knowledge bases as JSON',\n },\n ]\n\n static override flags = {\n ...getOrganizationFlag({\n description: 'Organization to list knowledge bases for',\n semantics: 'override',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {json, organization} = this.flags\n\n let organizationId: string\n try {\n organizationId = await resolveOrganizationId({\n configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,\n flagOrganizationId: organization,\n unattended: this.isUnattended(),\n })\n } catch (error) {\n listContextDebug('Error resolving organization', error)\n this.error(getErrorMessage(error), {\n exit:\n error instanceof MissingOrganizationError\n ? exitCodes.USAGE_ERROR\n : exitCodes.RUNTIME_ERROR,\n })\n }\n\n let knowledgeBases\n try {\n knowledgeBases = await listKnowledgeBases(organizationId)\n } catch (error) {\n listContextDebug('Error listing knowledge bases', error)\n this.error(`Failed to list knowledge bases: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(knowledgeBases)\n return\n }\n\n if (knowledgeBases.length === 0) {\n this.log('No knowledge bases found')\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'title', title: 'Title'},\n {alignment: 'left', name: 'state', title: 'State'},\n {alignment: 'right', name: 'openIssues', title: 'Open issues'},\n {alignment: 'left', name: 'updatedAt', title: 'Updated'},\n ],\n })\n\n for (const {openIssueCount, publicId, state, title, updatedAt} of knowledgeBases) {\n table.addRow({id: publicId, openIssues: openIssueCount, state, title, updatedAt})\n }\n\n this.log(table.render())\n }\n}\n"],"names":["exitCodes","SanityCommand","subdebug","getErrorMessage","MissingOrganizationError","resolveOrganizationId","listKnowledgeBases","Table","getOrganizationFlag","listContextDebug","ListKnowledgeBasesCommand","description","enableJsonFlag","examples","command","flags","semantics","run","json","organization","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","isUnattended","error","exit","USAGE_ERROR","RUNTIME_ERROR","knowledgeBases","logJson","length","log","table","columns","alignment","name","title","openIssueCount","publicId","state","updatedAt","addRow","id","openIssues","render"],"mappings":"AACA,SAAQA,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AAEvD,SACEC,wBAAwB,EACx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ACF;QAEA,IAAIA,eAAeE,MAAM,KAAK,GAAG;YAC/B,IAAI,CAACC,GAAG,CAAC;YACT;QACF;QAEA,MAAMC,QAAQ,IAAI5B,MAAM;YACtB6B,SAAS;gBACP;oBAACC,WAAW;oBAAQC,MAAM;oBAAMC,OAAO;gBAAI;gBAC3C;oBAACF,WAAW;oBAAQC,MAAM;oBAASC,OAAO;gBAAO;gBACjD;oBAACF,WAAW;oBAAQC,MAAM;oBAASC,OAAO;gBAAO;gBACjD;oBAACF,WAAW;oBAASC,MAAM;oBAAcC,OAAO;gBAAa;gBAC7D;oBAACF,WAAW;oBAAQC,MAAM;oBAAaC,OAAO;gBAAS;aACxD;QACH;QAEA,KAAK,MAAM,EAACC,cAAc,EAAEC,QAAQ,EAAEC,KAAK,EAAEH,KAAK,EAAEI,SAAS,EAAC,IAAIZ,eAAgB;YAChFI,MAAMS,MAAM,CAAC;gBAACC,IAAIJ;gBAAUK,YAAYN;gBAAgBE;gBAAOH;gBAAOI;YAAS;QACjF;QAEA,IAAI,CAACT,GAAG,CAACC,MAAMY,MAAM;IACvB;AACF"}
@@ -16,6 +16,7 @@ export class DeployCommand extends SanityCommand {
16
16
  })
17
17
  };
18
18
  static description = 'Builds and deploys Sanity Studio or application to Sanity hosting';
19
+ static enableJsonFlag = true;
19
20
  static examples = [
20
21
  {
21
22
  command: '<%= config.bin %> <%= command.id %>',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/deploy.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand} from '@sanity/cli-core'\nimport {confirm} from '@sanity/cli-core/ux'\nimport {getWorkbench, resolveWorkbenchConfig} from '@sanity/workbench-cli/deploy'\n\nimport {deployApp} from '../actions/deploy/deployApp.js'\nimport {deployDebug} from '../actions/deploy/deployDebug.js'\nimport {deployStudio} from '../actions/deploy/deployStudio.js'\nimport {getAppId} from '../util/appId.js'\nimport {determineIsApp} from '../util/determineIsApp.js'\nimport {dirIsEmptyOrNonExistent} from '../util/dirIsEmptyOrNonExistent.js'\n\nexport class DeployCommand extends SanityCommand<typeof DeployCommand> {\n static override args = {\n sourceDir: Args.directory({\n description: 'Source directory',\n }),\n }\n\n static override description = 'Builds and deploys Sanity Studio or application to Sanity hosting'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Build and deploy the studio to Sanity hosting',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --no-minify --source-maps',\n description: 'Deploys non-minified build with source maps',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --schema-required',\n description:\n 'Fail fast on schema store fails - for when other services rely on the stored schema',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --external',\n description: 'Register an externally hosted studio (studioHost contains full URL)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --external --url https://apps.example.com',\n description: 'Register an externally hosted studio, served from the provided origin',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --create --title \"My App\" --yes --json',\n description:\n 'Create and deploy an App SDK app without prompts. Save application.id as deployment.appId, then omit --create on later deploys',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --create --title \"My App\" --dry-run --json',\n description: 'Preview a new App SDK deployment without creating or uploading anything',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --url my-studio --yes',\n description: 'Deploy a studio without prompts using its hostname',\n },\n ]\n\n static override flags = {\n 'auto-updates': Flags.boolean({\n allowNo: true,\n deprecated: true,\n description: 'Automatically update the studio to the latest version',\n }),\n build: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Build the studio before deploying (use --no-build to deploy existing `dist/` output)',\n }),\n create: Flags.boolean({\n description: 'Create a new App SDK app, even if the organization has other apps',\n exclusive: ['external', 'url'],\n }),\n 'dry-run': Flags.boolean({\n default: false,\n description: 'Report what would be deployed without uploading or creating anything',\n }),\n external: Flags.boolean({\n default: false,\n description: 'Register an externally hosted studio',\n exclusive: ['source-maps', 'minify'],\n }),\n json: Flags.boolean({\n char: 'j',\n default: false,\n description: 'Output the result as JSON',\n }),\n minify: Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Minify built JavaScript (use --no-minify to skip for faster builds)',\n }),\n 'schema-required': Flags.boolean({\n default: false,\n description: 'Fail if schema deployment fails',\n }),\n 'source-maps': Flags.boolean({\n default: false,\n description: 'Enable source maps for built bundles (increases size of bundle)',\n }),\n title: Flags.string({\n description:\n 'Title for a newly created application or studio. For apps, use --create to select creation when the organization already has apps',\n }),\n url: Flags.string({\n description:\n 'Studio URL for deployment. For external deploys, the full URL. For hosted studios, the hostname (e.g. \"my-studio\" or \"my-studio.sanity.studio\")',\n }),\n verbose: Flags.boolean({\n default: false,\n description: 'Enable verbose logging',\n }),\n yes: Flags.boolean({\n char: 'y',\n default: false,\n description:\n 'Unattended mode, answers \"yes\" to any \"yes/no\" prompt and otherwise uses defaults',\n }),\n }\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(DeployCommand)\n\n const cliConfig = await this.getCliConfig()\n const projectRoot = await this.getProjectRoot()\n\n const isApp = determineIsApp(cliConfig)\n\n if (flags.create) {\n if (!isApp) {\n return this.output.error(\n '--create is only supported for App SDK apps. For a studio, use --url <hostname>.',\n )\n }\n if (getAppId(cliConfig)) {\n return this.output.error(\n '--create cannot be used with a configured app ID. Omit --create to deploy to that app, or remove deployment.appId and app.id to create a new one.',\n )\n }\n if (getWorkbench(cliConfig) || resolveWorkbenchConfig(cliConfig)) {\n return this.output.error(\n '--create is not supported for this app configuration. Omit --create and run sanity deploy.',\n )\n }\n }\n\n const defaultOutputDir = path.resolve(path.join(projectRoot.directory, 'dist'))\n const sourceDir = path.resolve(process.cwd(), this.args.sourceDir || defaultOutputDir)\n\n // Skip the directory check if the studio is externally hosted\n if (this.args.sourceDir && this.args.sourceDir !== 'dist' && !flags.external) {\n let relativeOutput = path.relative(process.cwd(), sourceDir)\n if (relativeOutput[0] !== '.') {\n relativeOutput = `./${relativeOutput}`\n }\n\n if (!this.isUnattended() && !flags['dry-run']) {\n const isEmpty = await dirIsEmptyOrNonExistent(sourceDir)\n const shouldProceed =\n isEmpty ||\n (await confirm({\n default: false,\n message: `\"${relativeOutput}\" is not empty, do you want to proceed?`,\n }))\n\n if (!shouldProceed) {\n this.output.error('Cancelled.', {exit: exitCodes.RUNTIME_ERROR})\n }\n }\n\n // Keep --json's stdout clean for the payload\n if (!flags.json) this.output.log(`Building to ${relativeOutput}\\n`)\n }\n\n // Force yes downstream: build/app resolution otherwise prompts for prerelease/version choices\n const deployFlags = this.isUnattended() || flags['dry-run'] ? {...flags, yes: true} : flags\n\n if (isApp) {\n deployDebug('Deploying app')\n await deployApp({\n cliConfig,\n flags: deployFlags,\n output: this.output,\n projectRoot,\n sourceDir,\n })\n } else {\n deployDebug('Deploying studio')\n await deployStudio({\n cliConfig,\n flags: deployFlags,\n output: this.output,\n projectRoot,\n sourceDir,\n })\n }\n }\n}\n"],"names":["path","Args","Flags","exitCodes","SanityCommand","confirm","getWorkbench","resolveWorkbenchConfig","deployApp","deployDebug","deployStudio","getAppId","determineIsApp","dirIsEmptyOrNonExistent","DeployCommand","args","sourceDir","directory","description","examples","command","flags","boolean","allowNo","deprecated","build","default","create","exclusive","external","json","char","minify","title","string","url","verbose","yes","run","parse","cliConfig","getCliConfig","projectRoot","getProjectRoot","isApp","output","error","defaultOutputDir","resolve","join","process","cwd","relativeOutput","relative","isUnattended","isEmpty","shouldProceed","message","exit","RUNTIME_ERROR","log","deployFlags"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,aAAa,QAAO,mBAAkB;AACzD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,YAAY,EAAEC,sBAAsB,QAAO,+BAA8B;AAEjF,SAAQC,SAAS,QAAO,iCAAgC;AACxD,SAAQC,WAAW,QAAO,mCAAkC;AAC5D,SAAQC,YAAY,QAAO,oCAAmC;AAC9D,SAAQC,QAAQ,Q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A,iBAAiB,CAAC,EAAE,EAAEA,gBAAgB;YACxC;YAEA,IAAI,CAAC,IAAI,CAACE,YAAY,MAAM,CAACjC,KAAK,CAAC,UAAU,EAAE;gBAC7C,MAAMkC,UAAU,MAAM1C,wBAAwBG;gBAC9C,MAAMwC,gBACJD,WACC,MAAMlD,QAAQ;oBACbqB,SAAS;oBACT+B,SAAS,CAAC,CAAC,EAAEL,eAAe,uCAAuC,CAAC;gBACtE;gBAEF,IAAI,CAACI,eAAe;oBAClB,IAAI,CAACX,MAAM,CAACC,KAAK,CAAC,cAAc;wBAACY,MAAMvD,UAAUwD,aAAa;oBAAA;gBAChE;YACF;YAEA,6CAA6C;YAC7C,IAAI,CAACtC,MAAMS,IAAI,EAAE,IAAI,CAACe,MAAM,CAACe,GAAG,CAAC,CAAC,YAAY,EAAER,eAAe,EAAE,CAAC;QACpE;QAEA,8FAA8F;QAC9F,MAAMS,cAAc,IAAI,CAACP,YAAY,MAAMjC,KAAK,CAAC,UAAU,GAAG;YAAC,GAAGA,KAAK;YAAEgB,KAAK;QAAI,IAAIhB;QAEtF,IAAIuB,OAAO;YACTnC,YAAY;YACZ,MAAMD,UAAU;gBACdgC;gBACAnB,OAAOwC;gBACPhB,QAAQ,IAAI,CAACA,MAAM;gBACnBH;gBACA1B;YACF;QACF,OAAO;YACLP,YAAY;YACZ,MAAMC,aAAa;gBACjB8B;gBACAnB,OAAOwC;gBACPhB,QAAQ,IAAI,CAACA,MAAM;gBACnBH;gBACA1B;YACF;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/commands/deploy.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand} from '@sanity/cli-core'\nimport {confirm} from '@sanity/cli-core/ux'\nimport {getWorkbench, resolveWorkbenchConfig} from '@sanity/workbench-cli/deploy'\n\nimport {deployApp} from '../actions/deploy/deployApp.js'\nimport {deployDebug} from '../actions/deploy/deployDebug.js'\nimport {deployStudio} from '../actions/deploy/deployStudio.js'\nimport {getAppId} from '../util/appId.js'\nimport {determineIsApp} from '../util/determineIsApp.js'\nimport {dirIsEmptyOrNonExistent} from '../util/dirIsEmptyOrNonExistent.js'\n\nexport class DeployCommand extends SanityCommand<typeof DeployCommand> {\n static override args = {\n sourceDir: Args.directory({\n description: 'Source directory',\n }),\n }\n\n static override description = 'Builds and deploys Sanity Studio or application to Sanity hosting'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Build and deploy the studio to Sanity hosting',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --no-minify --source-maps',\n description: 'Deploys non-minified build with source maps',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --schema-required',\n description:\n 'Fail fast on schema store fails - for when other services rely on the stored schema',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --external',\n description: 'Register an externally hosted studio (studioHost contains full URL)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --external --url https://apps.example.com',\n description: 'Register an externally hosted studio, served from the provided origin',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --create --title \"My App\" --yes --json',\n description:\n 'Create and deploy an App SDK app without prompts. Save application.id as deployment.appId, then omit --create on later deploys',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --create --title \"My App\" --dry-run --json',\n description: 'Preview a new App SDK deployment without creating or uploading anything',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --url my-studio --yes',\n description: 'Deploy a studio without prompts using its hostname',\n },\n ]\n\n static override flags = {\n 'auto-updates': Flags.boolean({\n allowNo: true,\n deprecated: true,\n description: 'Automatically update the studio to the latest version',\n }),\n build: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Build the studio before deploying (use --no-build to deploy existing `dist/` output)',\n }),\n create: Flags.boolean({\n description: 'Create a new App SDK app, even if the organization has other apps',\n exclusive: ['external', 'url'],\n }),\n 'dry-run': Flags.boolean({\n default: false,\n description: 'Report what would be deployed without uploading or creating anything',\n }),\n external: Flags.boolean({\n default: false,\n description: 'Register an externally hosted studio',\n exclusive: ['source-maps', 'minify'],\n }),\n json: Flags.boolean({\n char: 'j',\n default: false,\n description: 'Output the result as JSON',\n }),\n minify: Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Minify built JavaScript (use --no-minify to skip for faster builds)',\n }),\n 'schema-required': Flags.boolean({\n default: false,\n description: 'Fail if schema deployment fails',\n }),\n 'source-maps': Flags.boolean({\n default: false,\n description: 'Enable source maps for built bundles (increases size of bundle)',\n }),\n title: Flags.string({\n description:\n 'Title for a newly created application or studio. For apps, use --create to select creation when the organization already has apps',\n }),\n url: Flags.string({\n description:\n 'Studio URL for deployment. For external deploys, the full URL. For hosted studios, the hostname (e.g. \"my-studio\" or \"my-studio.sanity.studio\")',\n }),\n verbose: Flags.boolean({\n default: false,\n description: 'Enable verbose logging',\n }),\n yes: Flags.boolean({\n char: 'y',\n default: false,\n description:\n 'Unattended mode, answers \"yes\" to any \"yes/no\" prompt and otherwise uses defaults',\n }),\n }\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(DeployCommand)\n\n const cliConfig = await this.getCliConfig()\n const projectRoot = await this.getProjectRoot()\n\n const isApp = determineIsApp(cliConfig)\n\n if (flags.create) {\n if (!isApp) {\n return this.output.error(\n '--create is only supported for App SDK apps. For a studio, use --url <hostname>.',\n )\n }\n if (getAppId(cliConfig)) {\n return this.output.error(\n '--create cannot be used with a configured app ID. Omit --create to deploy to that app, or remove deployment.appId and app.id to create a new one.',\n )\n }\n if (getWorkbench(cliConfig) || resolveWorkbenchConfig(cliConfig)) {\n return this.output.error(\n '--create is not supported for this app configuration. Omit --create and run sanity deploy.',\n )\n }\n }\n\n const defaultOutputDir = path.resolve(path.join(projectRoot.directory, 'dist'))\n const sourceDir = path.resolve(process.cwd(), this.args.sourceDir || defaultOutputDir)\n\n // Skip the directory check if the studio is externally hosted\n if (this.args.sourceDir && this.args.sourceDir !== 'dist' && !flags.external) {\n let relativeOutput = path.relative(process.cwd(), sourceDir)\n if (relativeOutput[0] !== '.') {\n relativeOutput = `./${relativeOutput}`\n }\n\n if (!this.isUnattended() && !flags['dry-run']) {\n const isEmpty = await dirIsEmptyOrNonExistent(sourceDir)\n const shouldProceed =\n isEmpty ||\n (await confirm({\n default: false,\n message: `\"${relativeOutput}\" is not empty, do you want to proceed?`,\n }))\n\n if (!shouldProceed) {\n this.output.error('Cancelled.', {exit: exitCodes.RUNTIME_ERROR})\n }\n }\n\n // Keep --json's stdout clean for the payload\n if (!flags.json) this.output.log(`Building to ${relativeOutput}\\n`)\n }\n\n // Force yes downstream: build/app resolution otherwise prompts for prerelease/version choices\n const deployFlags = this.isUnattended() || flags['dry-run'] ? {...flags, yes: true} : flags\n\n if (isApp) {\n deployDebug('Deploying app')\n await deployApp({\n cliConfig,\n flags: deployFlags,\n output: this.output,\n projectRoot,\n sourceDir,\n })\n } else {\n deployDebug('Deploying studio')\n await deployStudio({\n cliConfig,\n flags: deployFlags,\n output: this.output,\n projectRoot,\n sourceDir,\n })\n }\n }\n}\n"],"names":["path","Args","Flags","exitCodes","SanityCommand","confirm","getWorkbench","resolveWorkbenchConfig","deployApp","deployDebug","deployStudio","getAppId","determineIsApp","dirIsEmptyOrNonExistent","DeployCommand","args","sourceDir","directory","description","enableJsonFlag","examples","command","flags","boolean","allowNo","deprecated","build","default","create","exclusive","external","json","char","minify","title","string","url","verbose","yes","run","parse","cliConfig","getCliConfig","projectRoot","getProjectRoot","isApp","output","error","defaultOutputDir","resolve","join","process","cwd","relativeOutput","relative","isUnattended","isEmpty","shouldProceed","message","exit","RUNTIME_ERROR","log","deployFlags"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,aAAa,QAAO,mBAAkB;AACzD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,YAAY,EAAEC,sBAAsB,QAAO,+BAA8B;AAEjF,SAAQC,SAAS,QA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,QAAQ,EAAE;YAC5E,IAAIuB,iBAAiBrD,KAAKsD,QAAQ,CAACH,QAAQC,GAAG,IAAIpC;YAClD,IAAIqC,cAAc,CAAC,EAAE,KAAK,KAAK;gBAC7BA,iBAAiB,CAAC,EAAE,EAAEA,gBAAgB;YACxC;YAEA,IAAI,CAAC,IAAI,CAACE,YAAY,MAAM,CAACjC,KAAK,CAAC,UAAU,EAAE;gBAC7C,MAAMkC,UAAU,MAAM3C,wBAAwBG;gBAC9C,MAAMyC,gBACJD,WACC,MAAMnD,QAAQ;oBACbsB,SAAS;oBACT+B,SAAS,CAAC,CAAC,EAAEL,eAAe,uCAAuC,CAAC;gBACtE;gBAEF,IAAI,CAACI,eAAe;oBAClB,IAAI,CAACX,MAAM,CAACC,KAAK,CAAC,cAAc;wBAACY,MAAMxD,UAAUyD,aAAa;oBAAA;gBAChE;YACF;YAEA,6CAA6C;YAC7C,IAAI,CAACtC,MAAMS,IAAI,EAAE,IAAI,CAACe,MAAM,CAACe,GAAG,CAAC,CAAC,YAAY,EAAER,eAAe,EAAE,CAAC;QACpE;QAEA,8FAA8F;QAC9F,MAAMS,cAAc,IAAI,CAACP,YAAY,MAAMjC,KAAK,CAAC,UAAU,GAAG;YAAC,GAAGA,KAAK;YAAEgB,KAAK;QAAI,IAAIhB;QAEtF,IAAIuB,OAAO;YACTpC,YAAY;YACZ,MAAMD,UAAU;gBACdiC;gBACAnB,OAAOwC;gBACPhB,QAAQ,IAAI,CAACA,MAAM;gBACnBH;gBACA3B;YACF;QACF,OAAO;YACLP,YAAY;YACZ,MAAMC,aAAa;gBACjB+B;gBACAnB,OAAOwC;gBACPhB,QAAQ,IAAI,CAACA,MAAM;gBACnBH;gBACA3B;YACF;QACF;IACF;AACF"}
@@ -27,6 +27,7 @@ export class DoctorCommand extends SanityCommand {
27
27
  })
28
28
  };
29
29
  static description = 'Run diagnostics on your Sanity project';
30
+ static enableJsonFlag = true;
30
31
  static examples = [
31
32
  '<%= config.bin %> <%= command.id %>',
32
33
  {
@@ -65,7 +66,7 @@ export class DoctorCommand extends SanityCommand {
65
66
  cwd
66
67
  }, checks);
67
68
  if (flags.json) {
68
- this.output.log(JSON.stringify(results, null, 2));
69
+ this.logJson(results);
69
70
  } else {
70
71
  for (const check of results.checks){
71
72
  this.printCheck(check);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/doctor.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand} from '@sanity/cli-core'\nimport {logSymbols} from '@sanity/cli-core/ux'\n\nimport {type DoctorCheckName, doctorChecks, KNOWN_CHECKS} from '../actions/doctor/checks/index.js'\nimport {runDoctorChecks} from '../actions/doctor/runDoctorChecks.js'\nimport {\n type CheckMessage,\n type CheckResultStatus,\n type CheckResultWithMeta,\n type DoctorCheck,\n type DoctorResults,\n type MessageType,\n} from '../actions/doctor/types.js'\n\nconst STATUS_SYMBOLS: Record<CheckResultStatus, string> = {\n error: logSymbols.error,\n passed: logSymbols.success,\n warning: logSymbols.warning,\n}\n\nconst MESSAGE_SYMBOLS: Record<MessageType, string> = {\n error: logSymbols.error,\n info: logSymbols.info,\n success: logSymbols.success,\n warning: logSymbols.warning,\n}\n\nexport class DoctorCommand extends SanityCommand<typeof DoctorCommand> {\n // strict=false allows variadic args — validation is handled by getChecks().\n // options is omitted here because oclif's help formatter uses it for display,\n // but actual validation is done explicitly in getChecks() for clear error messages.\n static override args = {\n checks: Args.string({\n description: `Checks to enable (defaults to all). Valid: ${KNOWN_CHECKS.join(', ')}`,\n multiple: true,\n required: false,\n }),\n }\n\n static override description = 'Run diagnostics on your Sanity project'\n\n static override examples = [\n '<%= config.bin %> <%= command.id %>',\n {command: '<%= config.bin %> <%= command.id %> --json', description: 'Output results as JSON'},\n {\n command: '<%= config.bin %> <%= command.id %> cli',\n description: 'Only run CLI-related diagnostics',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n char: 'j',\n default: false,\n description: 'Output results as JSON',\n }),\n }\n\n // Needed for variable argument count\n static override strict = false\n\n public async run(): Promise<void> {\n const {argv, flags} = await this.parse(DoctorCommand)\n\n let checks: Array<DoctorCheck>\n try {\n checks = getChecks(argv)\n } catch (err) {\n return this.output.error(err instanceof Error ? err.message : String(err), {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n const cwd = process.cwd()\n\n if (!flags.json) {\n this.output.log('Running diagnostics...\\n')\n }\n\n const results = await runDoctorChecks({cwd}, checks)\n\n if (flags.json) {\n this.output.log(JSON.stringify(results, null, 2))\n } else {\n for (const check of results.checks) {\n this.printCheck(check)\n }\n\n this.printSummary(results.summary)\n }\n\n // Exit with error code if any checks failed\n if (results.summary.errors > 0) {\n return this.exit(exitCodes.RUNTIME_ERROR)\n }\n }\n\n private printCheck(check: CheckResultWithMeta): void {\n const symbol = STATUS_SYMBOLS[check.status]\n const title =\n check.status === 'passed'\n ? check.title\n : styleText(check.status === 'error' ? 'red' : 'yellow', check.title)\n\n this.output.log(`${symbol} ${title}`)\n\n for (const message of check.messages) {\n this.printMessage(message)\n }\n\n this.output.log('') // Empty line between checks\n }\n\n private printMessage(message: CheckMessage): void {\n const symbol = MESSAGE_SYMBOLS[message.type]\n const text =\n message.type === 'error'\n ? styleText('red', message.text)\n : message.type === 'warning'\n ? styleText('yellow', message.text)\n : message.text\n\n this.output.log(` ${symbol} ${text}`)\n\n if (message.suggestions?.length) {\n for (const suggestion of message.suggestions) {\n this.output.log(` ${styleText('dim', '→')} ${suggestion}`)\n }\n }\n }\n\n private printSummary(summary: DoctorResults['summary']): void {\n const parts: string[] = []\n\n if (summary.passed > 0) {\n parts.push(styleText('green', `${summary.passed} passed`))\n }\n if (summary.warnings > 0) {\n parts.push(\n styleText('yellow', `${summary.warnings} warning${summary.warnings === 1 ? '' : 's'}`),\n )\n }\n if (summary.errors > 0) {\n parts.push(styleText('red', `${summary.errors} error${summary.errors === 1 ? '' : 's'}`))\n }\n\n this.output.log(`Summary: ${parts.join(', ')}`)\n }\n}\n\nfunction getChecks(argv: unknown[]): Array<DoctorCheck> {\n // strict=false means oclif does NOT validate Args.string({ options }) — we must\n // validate explicitly. Filter to string args that aren't flags.\n const stringArgs = argv.filter(\n (item): item is string => typeof item === 'string' && !item.startsWith('-'),\n )\n\n const unknownChecks = stringArgs.filter(\n (item) => !(KNOWN_CHECKS as readonly string[]).includes(item),\n )\n if (unknownChecks.length > 0) {\n throw new Error(\n `Unknown check${unknownChecks.length === 1 ? '' : 's'}: ${unknownChecks.join(', ')}. Valid checks: ${KNOWN_CHECKS.join(', ')}`,\n )\n }\n\n const checkNames = stringArgs as DoctorCheckName[]\n return checkNames.length > 0\n ? checkNames.map((check) => doctorChecks[check])\n : Object.values(doctorChecks)\n}\n"],"names":["styleText","Args","Flags","exitCodes","SanityCommand","logSymbols","doctorChecks","KNOWN_CHECKS","runDoctorChecks","STATUS_SYMBOLS","error","passed","success","warning","MESSAGE_SYMBOLS","info","DoctorCommand","args","checks","string","description","join","multiple","required","examples","command","flags","json","boolean","char","default","strict","run","argv","parse","getChecks","err","output","Error","message","String","exit","USAGE_ERROR","cwd","process","log","results","JSON","stringify","check","printCheck","printSummary","summary","errors","RUNTIME_ERROR","symbol","status","title","messages","printMessage","type","text","suggestions","length","suggestion","parts","push","warnings","stringArgs","filter","item","startsWith","unknownChecks","includes","checkNames","map","Object","values"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,aAAa,QAAO,mBAAkB;AACzD,SAAQC,UAAU,QAAO,sBAAqB;AAE9C,SAA8BC,YAAY,EAAEC,YAAY,QAAO,oCAAmC;AAClG,SAAQC,eAAe,QAAO,uCAAsC;AAUpE,MAAMC,iBAAoD;IACxDC,OAAOL,WAAWK,KAAK;IACvBC,QAAQN,WAAWO,OAAO;IAC1BC,SAASR,WAAWQ,OAAO;AAC7B;AAEA,MAAMC,kBAA+C;IACnDJ,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AC2C,MAAM,IAC7C2B,OAAOC,MAAM,CAACvE;AACpB"}
1
+ {"version":3,"sources":["../../src/commands/doctor.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand} from '@sanity/cli-core'\nimport {logSymbols} from '@sanity/cli-core/ux'\n\nimport {type DoctorCheckName, doctorChecks, KNOWN_CHECKS} from '../actions/doctor/checks/index.js'\nimport {runDoctorChecks} from '../actions/doctor/runDoctorChecks.js'\nimport {\n type CheckMessage,\n type CheckResultStatus,\n type CheckResultWithMeta,\n type DoctorCheck,\n type DoctorResults,\n type MessageType,\n} from '../actions/doctor/types.js'\n\nconst STATUS_SYMBOLS: Record<CheckResultStatus, string> = {\n error: logSymbols.error,\n passed: logSymbols.success,\n warning: logSymbols.warning,\n}\n\nconst MESSAGE_SYMBOLS: Record<MessageType, string> = {\n error: logSymbols.error,\n info: logSymbols.info,\n success: logSymbols.success,\n warning: logSymbols.warning,\n}\n\nexport class DoctorCommand extends SanityCommand<typeof DoctorCommand> {\n // strict=false allows variadic args — validation is handled by getChecks().\n // options is omitted here because oclif's help formatter uses it for display,\n // but actual validation is done explicitly in getChecks() for clear error messages.\n static override args = {\n checks: Args.string({\n description: `Checks to enable (defaults to all). Valid: ${KNOWN_CHECKS.join(', ')}`,\n multiple: true,\n required: false,\n }),\n }\n\n static override description = 'Run diagnostics on your Sanity project'\n\n static override enableJsonFlag = true\n\n static override examples = [\n '<%= config.bin %> <%= command.id %>',\n {command: '<%= config.bin %> <%= command.id %> --json', description: 'Output results as JSON'},\n {\n command: '<%= config.bin %> <%= command.id %> cli',\n description: 'Only run CLI-related diagnostics',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n char: 'j',\n default: false,\n description: 'Output results as JSON',\n }),\n }\n\n // Needed for variable argument count\n static override strict = false\n\n public async run(): Promise<void> {\n const {argv, flags} = await this.parse(DoctorCommand)\n\n let checks: Array<DoctorCheck>\n try {\n checks = getChecks(argv)\n } catch (err) {\n return this.output.error(err instanceof Error ? err.message : String(err), {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n const cwd = process.cwd()\n\n if (!flags.json) {\n this.output.log('Running diagnostics...\\n')\n }\n\n const results = await runDoctorChecks({cwd}, checks)\n\n if (flags.json) {\n this.logJson(results)\n } else {\n for (const check of results.checks) {\n this.printCheck(check)\n }\n\n this.printSummary(results.summary)\n }\n\n // Exit with error code if any checks failed\n if (results.summary.errors > 0) {\n return this.exit(exitCodes.RUNTIME_ERROR)\n }\n }\n\n private printCheck(check: CheckResultWithMeta): void {\n const symbol = STATUS_SYMBOLS[check.status]\n const title =\n check.status === 'passed'\n ? check.title\n : styleText(check.status === 'error' ? 'red' : 'yellow', check.title)\n\n this.output.log(`${symbol} ${title}`)\n\n for (const message of check.messages) {\n this.printMessage(message)\n }\n\n this.output.log('') // Empty line between checks\n }\n\n private printMessage(message: CheckMessage): void {\n const symbol = MESSAGE_SYMBOLS[message.type]\n const text =\n message.type === 'error'\n ? styleText('red', message.text)\n : message.type === 'warning'\n ? styleText('yellow', message.text)\n : message.text\n\n this.output.log(` ${symbol} ${text}`)\n\n if (message.suggestions?.length) {\n for (const suggestion of message.suggestions) {\n this.output.log(` ${styleText('dim', '→')} ${suggestion}`)\n }\n }\n }\n\n private printSummary(summary: DoctorResults['summary']): void {\n const parts: string[] = []\n\n if (summary.passed > 0) {\n parts.push(styleText('green', `${summary.passed} passed`))\n }\n if (summary.warnings > 0) {\n parts.push(\n styleText('yellow', `${summary.warnings} warning${summary.warnings === 1 ? '' : 's'}`),\n )\n }\n if (summary.errors > 0) {\n parts.push(styleText('red', `${summary.errors} error${summary.errors === 1 ? '' : 's'}`))\n }\n\n this.output.log(`Summary: ${parts.join(', ')}`)\n }\n}\n\nfunction getChecks(argv: unknown[]): Array<DoctorCheck> {\n // strict=false means oclif does NOT validate Args.string({ options }) — we must\n // validate explicitly. Filter to string args that aren't flags.\n const stringArgs = argv.filter(\n (item): item is string => typeof item === 'string' && !item.startsWith('-'),\n )\n\n const unknownChecks = stringArgs.filter(\n (item) => !(KNOWN_CHECKS as readonly string[]).includes(item),\n )\n if (unknownChecks.length > 0) {\n throw new Error(\n `Unknown check${unknownChecks.length === 1 ? '' : 's'}: ${unknownChecks.join(', ')}. Valid checks: ${KNOWN_CHECKS.join(', ')}`,\n )\n }\n\n const checkNames = stringArgs as DoctorCheckName[]\n return checkNames.length > 0\n ? checkNames.map((check) => doctorChecks[check])\n : Object.values(doctorChecks)\n}\n"],"names":["styleText","Args","Flags","exitCodes","SanityCommand","logSymbols","doctorChecks","KNOWN_CHECKS","runDoctorChecks","STATUS_SYMBOLS","error","passed","success","warning","MESSAGE_SYMBOLS","info","DoctorCommand","args","checks","string","description","join","multiple","required","enableJsonFlag","examples","command","flags","json","boolean","char","default","strict","run","argv","parse","getChecks","err","output","Error","message","String","exit","USAGE_ERROR","cwd","process","log","results","logJson","check","printCheck","printSummary","summary","errors","RUNTIME_ERROR","symbol","status","title","messages","printMessage","type","text","suggestions","length","suggestion","parts","push","warnings","stringArgs","filter","item","startsWith","unknownChecks","includes","checkNames","map","Object","values"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,aAAa,QAAO,mBAAkB;AACzD,SAAQC,UAAU,QAAO,sBAAqB;AAE9C,SAA8BC,YAAY,EAAEC,YAAY,QAAO,oCAAmC;AAClG,SAAQC,eAAe,QAAO,uCAAsC;AAUpE,MAAMC,iBAAoD;IACxDC,OAAOL,WAAWK,KAAK;IACvBC,QAAQN,WAAWO,OAAO;IAC1BC,SAASR,WAAWQ,OAAO;AAC7B;AAEA,MAAMC,kBAA+C;IACnDJ,OAAOL,WAAWK,KAAK;IACvBK,MAAMV,WAAWU,IAAI;IACrBH,SAASP,WAAWO,OAAO;IAC3BC,SAASR,WAAWQ,OAAO;AAC7B;AAEA,OAAO,MAAMG,sBAAsBZ;I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AAMC,IAAI,CAAClE,UAAU,SAAS,GAAGoD,QAAQzC,MAAM,CAAC,OAAO,CAAC;QAC1D;QACA,IAAIyC,QAAQe,QAAQ,GAAG,GAAG;YACxBF,MAAMC,IAAI,CACRlE,UAAU,UAAU,GAAGoD,QAAQe,QAAQ,CAAC,QAAQ,EAAEf,QAAQe,QAAQ,KAAK,IAAI,KAAK,KAAK;QAEzF;QACA,IAAIf,QAAQC,MAAM,GAAG,GAAG;YACtBY,MAAMC,IAAI,CAAClE,UAAU,OAAO,GAAGoD,QAAQC,MAAM,CAAC,MAAM,EAAED,QAAQC,MAAM,KAAK,IAAI,KAAK,KAAK;QACzF;QAEA,IAAI,CAACf,MAAM,CAACQ,GAAG,CAAC,CAAC,SAAS,EAAEmB,MAAM5C,IAAI,CAAC,OAAO;IAChD;AACF;AAEA,SAASe,UAAUF,IAAe;IAChC,gFAAgF;IAChF,gEAAgE;IAChE,MAAMkC,aAAalC,KAAKmC,MAAM,CAC5B,CAACC,OAAyB,OAAOA,SAAS,YAAY,CAACA,KAAKC,UAAU,CAAC;IAGzE,MAAMC,gBAAgBJ,WAAWC,MAAM,CACrC,CAACC,OAAS,CAAC,AAAC/D,aAAmCkE,QAAQ,CAACH;IAE1D,IAAIE,cAAcT,MAAM,GAAG,GAAG;QAC5B,MAAM,IAAIxB,MACR,CAAC,aAAa,EAAEiC,cAAcT,MAAM,KAAK,IAAI,KAAK,IAAI,EAAE,EAAES,cAAcnD,IAAI,CAAC,MAAM,gBAAgB,EAAEd,aAAac,IAAI,CAAC,OAAO;IAElI;IAEA,MAAMqD,aAAaN;IACnB,OAAOM,WAAWX,MAAM,GAAG,IACvBW,WAAWC,GAAG,CAAC,CAAC1B,QAAU3C,YAAY,CAAC2C,MAAM,IAC7C2B,OAAOC,MAAM,CAACvE;AACpB"}
@@ -4,6 +4,7 @@ import open from 'open';
4
4
  const listOpenapiDebug = subdebug('openapi:list');
5
5
  export class ListOpenApiCommand extends SanityCommand {
6
6
  static description = 'List all available OpenAPI specifications';
7
+ static enableJsonFlag = true;
7
8
  static examples = [
8
9
  {
9
10
  command: '<%= config.bin %> <%= command.id %>',
@@ -19,9 +20,6 @@ export class ListOpenApiCommand extends SanityCommand {
19
20
  }
20
21
  ];
21
22
  static flags = {
22
- json: Flags.boolean({
23
- description: 'Output JSON'
24
- }),
25
23
  web: Flags.boolean({
26
24
  char: 'w',
27
25
  description: 'Open HTTP Reference in web browser'
@@ -46,7 +44,7 @@ export class ListOpenApiCommand extends SanityCommand {
46
44
  });
47
45
  }
48
46
  if (json) {
49
- this.log(JSON.stringify(specs, null, 2));
47
+ this.logJson(specs);
50
48
  return;
51
49
  }
52
50
  if (specs.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/openapi/list.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport open from 'open'\n\ninterface OpenAPISpec {\n description: string\n slug: string\n title: string\n}\n\nconst listOpenapiDebug = subdebug('openapi:list')\n\nexport class ListOpenApiCommand extends SanityCommand<typeof ListOpenApiCommand> {\n static override description = 'List all available OpenAPI specifications'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List all available OpenAPI specs',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --json',\n description: 'List with JSON output',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --web',\n description: 'Open HTTP Reference in browser',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n description: 'Output JSON',\n }),\n web: Flags.boolean({\n char: 'w',\n description: 'Open HTTP Reference in web browser',\n }),\n }\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(ListOpenApiCommand)\n const {json, web} = flags\n\n if (web) {\n const url = 'https://www.sanity.io/docs/http-reference'\n this.log(`Opening ${url}`)\n await open(url)\n return\n }\n\n let specs: OpenAPISpec[]\n try {\n specs = await this.getSpecs()\n } catch (error) {\n listOpenapiDebug('Error fetching OpenAPI specs', error)\n\n this.error('The OpenAPI service is currently unavailable. Please try again later.', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.log(JSON.stringify(specs, null, 2))\n return\n }\n\n if (specs.length === 0) {\n this.log('No OpenAPI specifications available.')\n return\n }\n\n // Human-readable table format\n this.log(`\\nFound ${specs.length} OpenAPI specification(s):\\n`)\n\n for (const spec of specs) {\n this.log(`Title: ${spec.title}`)\n this.log(`Slug: ${spec.slug}`)\n if (spec.description) {\n this.log(`Description: ${spec.description}`)\n }\n this.log('')\n }\n\n this.log(`Use 'sanity openapi get <slug>' to retrieve a specific specification.`)\n }\n\n private async getSpecs(): Promise<OpenAPISpec[]> {\n const response = await fetch('https://www.sanity.io/docs/api/openapi', {\n signal: AbortSignal.timeout(10_000),\n })\n\n if (response.ok) {\n const data = await response.json()\n return Array.isArray(data?.specs) ? data.specs : []\n }\n\n throw response\n }\n}\n"],"names":["Flags","exitCodes","SanityCommand","subdebug","open","listOpenapiDebug","ListOpenApiCommand","description","examples","command","flags","json","boolean","web","char","run","parse","url","log","specs","getSpecs","error","exit","RUNTIME_ERROR","JSON","stringify","length","spec","title","slug","response","fetch","signal","AbortSignal","timeout","ok","data","Array","isArray"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AACjC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,OAAOC,UAAU,OAAM;AAQvB,MAAMC,mBAAmBF,SAAS;AAElC,OAAO,MAAMG,2BAA2BJ;IACtC,OAAgBK,cAAc,4CAA2C;IAEzE,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;KACD,CAAA;IAED,OAAgBG,QAAQ;QACtBC,MAAMX,MAAMY,OAAO,CAAC;YAClBL,aAAa;QACf;QACAM,KAAKb,MAAMY,OAAO,CAAC;YACjBE,MAAM;YACNP,aAAa;QACf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SAASK,EAAE,EAAE;YACf,MAAMC,OAAO,MAAMN,SAASnB,IAAI;YAChC,OAAO0B,MAAMC,OAAO,CAACF,MAAMjB,SAASiB,KAAKjB,KAAK,GAAG,EAAE;QACrD;QAEA,MAAMW;IACR;AACF"}
1
+ {"version":3,"sources":["../../../src/commands/openapi/list.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport open from 'open'\n\ninterface OpenAPISpec {\n description: string\n slug: string\n title: string\n}\n\nconst listOpenapiDebug = subdebug('openapi:list')\n\nexport class ListOpenApiCommand extends SanityCommand<typeof ListOpenApiCommand> {\n static override description = 'List all available OpenAPI specifications'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List all available OpenAPI specs',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --json',\n description: 'List with JSON output',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --web',\n description: 'Open HTTP Reference in browser',\n },\n ]\n\n static override flags = {\n web: Flags.boolean({\n char: 'w',\n description: 'Open HTTP Reference in web browser',\n }),\n }\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(ListOpenApiCommand)\n const {json, web} = flags\n\n if (web) {\n const url = 'https://www.sanity.io/docs/http-reference'\n this.log(`Opening ${url}`)\n await open(url)\n return\n }\n\n let specs: OpenAPISpec[]\n try {\n specs = await this.getSpecs()\n } catch (error) {\n listOpenapiDebug('Error fetching OpenAPI specs', error)\n\n this.error('The OpenAPI service is currently unavailable. Please try again later.', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(specs)\n return\n }\n\n if (specs.length === 0) {\n this.log('No OpenAPI specifications available.')\n return\n }\n\n // Human-readable table format\n this.log(`\\nFound ${specs.length} OpenAPI specification(s):\\n`)\n\n for (const spec of specs) {\n this.log(`Title: ${spec.title}`)\n this.log(`Slug: ${spec.slug}`)\n if (spec.description) {\n this.log(`Description: ${spec.description}`)\n }\n this.log('')\n }\n\n this.log(`Use 'sanity openapi get <slug>' to retrieve a specific specification.`)\n }\n\n private async getSpecs(): Promise<OpenAPISpec[]> {\n const response = await fetch('https://www.sanity.io/docs/api/openapi', {\n signal: AbortSignal.timeout(10_000),\n })\n\n if (response.ok) {\n const data = await response.json()\n return Array.isArray(data?.specs) ? data.specs : []\n }\n\n throw response\n }\n}\n"],"names":["Flags","exitCodes","SanityCommand","subdebug","open","listOpenapiDebug","ListOpenApiCommand","description","enableJsonFlag","examples","command","flags","web","boolean","char","run","parse","json","url","log","specs","getSpecs","error","exit","RUNTIME_ERROR","logJson","length","spec","title","slug","response","fetch","signal","AbortSignal","timeout","ok","data","Array","isArray"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AACjC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,OAAOC,UAAU,OAAM;AAQvB,MAAMC,mBAAmBF,SAAS;AAElC,OAAO,MAAMG,2BAA2BJ;IACtC,OAAgBK,cAAc,4CAA2C;IAEzE,OAAgBC,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtBC,KAAKZ,MAAMa,OAAO,CAAC;YACjBC,MAAM;YACNP,aAAa;QACf;IACF,EAAC;IAED,MAAaQ,MAAqB;QAChC,MAAM,EAACJ,KAAK,EAAC,GAAG,MAAM,IAAI,CAACK,KAAK,CAACV;QACjC,MAAM,EAACW,IAAI,EAAEL,GAAG,EAAC,GAAGD;QAEpB,IAAIC,KAAK;YACP,MAAMM,MAAM;YACZ,IAAI,CAACC,GAAG,CAAC,CAAC,QAAQ,EAAED,KAAK;YACzB,MAAMd,KAAKc;YACX;QACF;QAEA,IAAIE;QACJ,IAAI;YACFA,QAAQ,MAAM,IAAI,CAACC,QAAQ;QAC7B,EAAE,OAAOC,OAAO;YACdjB,iBAAiB,gCAAgCiB;YAEjD,IAAI,CAACA,KAAK,CAAC,yEAAyE;gBAClFC,MAAMtB,UAAUuB,aAAa;YAC/B;QACF;QAEA,IAAIP,MAAM;YACR,IAAI,CAACQ,OAAO,CAACL;YACb;QACF;QAEA,IAAIA,MAAMM,MAAM,KAAK,GAAG;YACtB,IAAI,CAACP,GAAG,CAAC;YACT;QACF;QAEA,8BAA8B;QAC9B,IAAI,CAACA,GAAG,CAAC,CAAC,QAAQ,EAAEC,MAAMM,MAAM,CAAC,4BAA4B,CAAC;QAE9D,KAAK,MAAMC,QAAQP,MAAO;YACxB,IAAI,CAACD,GAAG,CAAC,CAAC,OAAO,EAAEQ,KAAKC,KAAK,EAAE;YAC/B,IAAI,CAACT,GAAG,CAAC,CAAC,MAAM,EAAEQ,KAAKE,IAAI,EAAE;YAC7B,IAAIF,KAAKpB,WAAW,EAAE;gBACpB,IAAI,CAACY,GAAG,CAAC,CAAC,aAAa,EAAEQ,KAAKpB,WAAW,EAAE;YAC7C;YACA,IAAI,CAACY,GAAG,CAAC;QACX;QAEA,IAAI,CAACA,GAAG,CAAC,CAAC,qEAAqE,CAAC;IAClF;IAEA,MAAcE,WAAmC;QAC/C,MAAMS,WAAW,MAAMC,MAAM,0CAA0C;YACrEC,QAAQC,YAAYC,OAAO,CAAC;QAC9B;QAEA,IAAIJ,SAASK,EAAE,EAAE;YACf,MAAMC,OAAO,MAAMN,SAASb,IAAI;YAChC,OAAOoB,MAAMC,OAAO,CAACF,MAAMhB,SAASgB,KAAKhB,KAAK,GAAG,EAAE;QACrD;QAEA,MAAMU;IACR;AACF"}
@@ -24,6 +24,7 @@ export class CreateProjectCommand extends SanityCommand {
24
24
  })
25
25
  };
26
26
  static description = 'Create a new Sanity project';
27
+ static enableJsonFlag = true;
27
28
  static examples = [
28
29
  {
29
30
  command: '<%= config.bin %> <%= command.id %>',
@@ -66,10 +67,6 @@ export class CreateProjectCommand extends SanityCommand {
66
67
  'public'
67
68
  ]
68
69
  }),
69
- json: Flags.boolean({
70
- default: false,
71
- description: 'Output in JSON format'
72
- }),
73
70
  organization: Flags.string({
74
71
  description: 'Organization to create the project in',
75
72
  helpValue: '<slug|id>'
@@ -167,13 +164,13 @@ export class CreateProjectCommand extends SanityCommand {
167
164
  return;
168
165
  } catch (error) {
169
166
  debug(`Error creating dataset: ${error}`);
170
- this.output.warn(`Project created but dataset creation failed: ${error}`);
167
+ this.output.logDiagnostic(`Warning: Project created but dataset creation failed: ${error}`);
171
168
  return;
172
169
  }
173
170
  }
174
171
  async printProjectCreationSuccess(organization, project, dataset) {
175
172
  if (this.flags.json) {
176
- this.output.log(JSON.stringify(project, null, 2));
173
+ this.logJson(project);
177
174
  return;
178
175
  }
179
176
  this.output.log(`Project created successfully!`);