@sanity/cli 7.10.0 → 7.11.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 (157) hide show
  1. package/README.md +31 -22
  2. package/dist/actions/auth/ensureAuthenticated.js +2 -0
  3. package/dist/actions/auth/ensureAuthenticated.js.map +1 -1
  4. package/dist/actions/auth/login/loginInstructions.js +19 -0
  5. package/dist/actions/auth/login/loginInstructions.js.map +1 -0
  6. package/dist/actions/dataset/resolveDataset.js +7 -1
  7. package/dist/actions/dataset/resolveDataset.js.map +1 -1
  8. package/dist/actions/deploy/deployApp.js +17 -12
  9. package/dist/actions/deploy/deployApp.js.map +1 -1
  10. package/dist/actions/deploy/deployStudio.js +2 -0
  11. package/dist/actions/deploy/deployStudio.js.map +1 -1
  12. package/dist/actions/graphql/resolveApiGeneration.js +9 -6
  13. package/dist/actions/graphql/resolveApiGeneration.js.map +1 -1
  14. package/dist/actions/init/initAction.js +23 -15
  15. package/dist/actions/init/initAction.js.map +1 -1
  16. package/dist/actions/manifest/extractCoreAppManifest.js +5 -3
  17. package/dist/actions/manifest/extractCoreAppManifest.js.map +1 -1
  18. package/dist/actions/migration/constants.js +10 -0
  19. package/dist/actions/migration/constants.js.map +1 -0
  20. package/dist/actions/migration/ensureApiVersionFormat.js +16 -0
  21. package/dist/actions/migration/ensureApiVersionFormat.js.map +1 -0
  22. package/dist/actions/migration/fileExists.js +13 -0
  23. package/dist/actions/migration/fileExists.js.map +1 -0
  24. package/dist/actions/migration/prettyMutationFormatter.js +155 -0
  25. package/dist/actions/migration/prettyMutationFormatter.js.map +1 -0
  26. package/dist/actions/migration/resolveMigrationScript.js +75 -0
  27. package/dist/actions/migration/resolveMigrationScript.js.map +1 -0
  28. package/dist/actions/migration/resolveMigrations.js +50 -0
  29. package/dist/actions/migration/resolveMigrations.js.map +1 -0
  30. package/dist/actions/migration/templates/index.js +7 -0
  31. package/dist/actions/migration/templates/index.js.map +1 -0
  32. package/dist/actions/migration/templates/minimalAdvanced.js +21 -0
  33. package/dist/actions/migration/templates/minimalAdvanced.js.map +1 -0
  34. package/dist/actions/migration/templates/minimalSimple.js +61 -0
  35. package/dist/actions/migration/templates/minimalSimple.js.map +1 -0
  36. package/dist/actions/migration/templates/renameField.js +20 -0
  37. package/dist/actions/migration/templates/renameField.js.map +1 -0
  38. package/dist/actions/migration/templates/renameType.js +19 -0
  39. package/dist/actions/migration/templates/renameType.js.map +1 -0
  40. package/dist/actions/migration/templates/stringToPTE.js +32 -0
  41. package/dist/actions/migration/templates/stringToPTE.js.map +1 -0
  42. package/dist/actions/migration/tree.js +111 -0
  43. package/dist/actions/migration/tree.js.map +1 -0
  44. package/dist/actions/preview/previewAction.js +33 -1
  45. package/dist/actions/preview/previewAction.js.map +1 -1
  46. package/dist/actions/schema/listSchemas.js +6 -4
  47. package/dist/actions/schema/listSchemas.js.map +1 -1
  48. package/dist/actions/tokens/validateRole.js +2 -1
  49. package/dist/actions/tokens/validateRole.js.map +1 -1
  50. package/dist/actions/undeploy/runUndeploy.js +13 -4
  51. package/dist/actions/undeploy/runUndeploy.js.map +1 -1
  52. package/dist/commands/backups/disable.js +5 -1
  53. package/dist/commands/backups/disable.js.map +1 -1
  54. package/dist/commands/backups/download.js +30 -6
  55. package/dist/commands/backups/download.js.map +1 -1
  56. package/dist/commands/backups/enable.js +5 -1
  57. package/dist/commands/backups/enable.js.map +1 -1
  58. package/dist/commands/backups/list.js +5 -1
  59. package/dist/commands/backups/list.js.map +1 -1
  60. package/dist/commands/cors/add.js +15 -7
  61. package/dist/commands/cors/add.js.map +1 -1
  62. package/dist/commands/cors/delete.js +6 -1
  63. package/dist/commands/cors/delete.js.map +1 -1
  64. package/dist/commands/datasets/alias/create.js +25 -18
  65. package/dist/commands/datasets/alias/create.js.map +1 -1
  66. package/dist/commands/datasets/alias/delete.js +15 -8
  67. package/dist/commands/datasets/alias/delete.js.map +1 -1
  68. package/dist/commands/datasets/alias/link.js +39 -17
  69. package/dist/commands/datasets/alias/link.js.map +1 -1
  70. package/dist/commands/datasets/alias/unlink.js +23 -2
  71. package/dist/commands/datasets/alias/unlink.js.map +1 -1
  72. package/dist/commands/datasets/copy.js +18 -2
  73. package/dist/commands/datasets/copy.js.map +1 -1
  74. package/dist/commands/datasets/create.js +8 -2
  75. package/dist/commands/datasets/create.js.map +1 -1
  76. package/dist/commands/datasets/delete.js +14 -17
  77. package/dist/commands/datasets/delete.js.map +1 -1
  78. package/dist/commands/datasets/embeddings/disable.js +3 -0
  79. package/dist/commands/datasets/embeddings/disable.js.map +1 -1
  80. package/dist/commands/datasets/embeddings/enable.js +5 -2
  81. package/dist/commands/datasets/embeddings/enable.js.map +1 -1
  82. package/dist/commands/datasets/embeddings/status.js +3 -0
  83. package/dist/commands/datasets/embeddings/status.js.map +1 -1
  84. package/dist/commands/datasets/export.js +27 -15
  85. package/dist/commands/datasets/export.js.map +1 -1
  86. package/dist/commands/datasets/import.js +3 -3
  87. package/dist/commands/datasets/import.js.map +1 -1
  88. package/dist/commands/datasets/visibility/get.js +2 -2
  89. package/dist/commands/datasets/visibility/get.js.map +1 -1
  90. package/dist/commands/datasets/visibility/set.js +2 -2
  91. package/dist/commands/datasets/visibility/set.js.map +1 -1
  92. package/dist/commands/docs/read.js +3 -3
  93. package/dist/commands/docs/read.js.map +1 -1
  94. package/dist/commands/documents/create.js +18 -13
  95. package/dist/commands/documents/create.js.map +1 -1
  96. package/dist/commands/documents/delete.js +3 -3
  97. package/dist/commands/documents/delete.js.map +1 -1
  98. package/dist/commands/documents/get.js +3 -3
  99. package/dist/commands/documents/get.js.map +1 -1
  100. package/dist/commands/documents/query.js +3 -3
  101. package/dist/commands/documents/query.js.map +1 -1
  102. package/dist/commands/documents/validate.js +29 -26
  103. package/dist/commands/documents/validate.js.map +1 -1
  104. package/dist/commands/graphql/deploy.js +20 -16
  105. package/dist/commands/graphql/deploy.js.map +1 -1
  106. package/dist/commands/graphql/undeploy.js +15 -18
  107. package/dist/commands/graphql/undeploy.js.map +1 -1
  108. package/dist/commands/hooks/delete.js +2 -2
  109. package/dist/commands/hooks/delete.js.map +1 -1
  110. package/dist/commands/hooks/logs.js +2 -2
  111. package/dist/commands/hooks/logs.js.map +1 -1
  112. package/dist/commands/login.js +2 -1
  113. package/dist/commands/login.js.map +1 -1
  114. package/dist/commands/media/create-aspect.js +20 -8
  115. package/dist/commands/media/create-aspect.js.map +1 -1
  116. package/dist/commands/media/delete-aspect.js +31 -16
  117. package/dist/commands/media/delete-aspect.js.map +1 -1
  118. package/dist/commands/media/deploy-aspect.js +10 -5
  119. package/dist/commands/media/deploy-aspect.js.map +1 -1
  120. package/dist/commands/media/export.js +9 -4
  121. package/dist/commands/media/export.js.map +1 -1
  122. package/dist/commands/media/import.js +6 -1
  123. package/dist/commands/media/import.js.map +1 -1
  124. package/dist/commands/migrations/create.js +150 -0
  125. package/dist/commands/migrations/create.js.map +1 -0
  126. package/dist/commands/migrations/list.js +64 -0
  127. package/dist/commands/migrations/list.js.map +1 -0
  128. package/dist/commands/migrations/run.js +306 -0
  129. package/dist/commands/migrations/run.js.map +1 -0
  130. package/dist/commands/preview.js +1 -0
  131. package/dist/commands/preview.js.map +1 -1
  132. package/dist/commands/projects/create.js +2 -1
  133. package/dist/commands/projects/create.js.map +1 -1
  134. package/dist/commands/schemas/delete.js +23 -2
  135. package/dist/commands/schemas/delete.js.map +1 -1
  136. package/dist/commands/schemas/deploy.js +6 -4
  137. package/dist/commands/schemas/deploy.js.map +1 -1
  138. package/dist/commands/schemas/extract.js +22 -1
  139. package/dist/commands/schemas/extract.js.map +1 -1
  140. package/dist/commands/schemas/list.js +8 -8
  141. package/dist/commands/schemas/list.js.map +1 -1
  142. package/dist/commands/tokens/{add.js → create.js} +25 -18
  143. package/dist/commands/tokens/create.js.map +1 -0
  144. package/dist/commands/tokens/delete.js +41 -23
  145. package/dist/commands/tokens/delete.js.map +1 -1
  146. package/dist/commands/undeploy.js +2 -7
  147. package/dist/commands/undeploy.js.map +1 -1
  148. package/dist/commands/users/invite.js +25 -3
  149. package/dist/commands/users/invite.js.map +1 -1
  150. package/dist/topicAliases.js +3 -0
  151. package/dist/topicAliases.js.map +1 -1
  152. package/dist/util/formatCliErrorMessages.js +5 -0
  153. package/dist/util/formatCliErrorMessages.js.map +1 -0
  154. package/oclif.config.js +5 -1
  155. package/oclif.manifest.json +326 -121
  156. package/package.json +7 -7
  157. package/dist/commands/tokens/add.js.map +0 -1
@@ -0,0 +1,64 @@
1
+ import { styleText } from 'node:util';
2
+ import { SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { Table } from 'console-table-printer';
4
+ import { resolveMigrations } from '../../actions/migration/resolveMigrations.js';
5
+ const listMigrationDebug = subdebug('migration:list');
6
+ export class ListMigrationCommand extends SanityCommand {
7
+ static description = 'List available migrations';
8
+ static examples = [
9
+ {
10
+ command: '<%= config.bin %> <%= command.id %>',
11
+ description: 'List all available migrations in the project'
12
+ }
13
+ ];
14
+ static hiddenAliases = [
15
+ 'migration:list'
16
+ ];
17
+ async run() {
18
+ const { directory: workDir } = await this.getProjectRoot();
19
+ try {
20
+ const migrations = await resolveMigrations(workDir);
21
+ if (migrations.length === 0) {
22
+ this.log('No migrations found in migrations folder of the project');
23
+ this.log(`\nRun ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`);
24
+ return;
25
+ }
26
+ const table = new Table({
27
+ columns: [
28
+ {
29
+ alignment: 'left',
30
+ name: 'id',
31
+ title: 'ID'
32
+ },
33
+ {
34
+ alignment: 'left',
35
+ name: 'title',
36
+ title: 'Title'
37
+ }
38
+ ],
39
+ title: `Found ${migrations.length} migrations in project`
40
+ });
41
+ for (const definedMigration of migrations){
42
+ table.addRow({
43
+ id: definedMigration.id,
44
+ title: definedMigration.migration.title
45
+ });
46
+ }
47
+ table.printTable();
48
+ this.log('\nRun `sanity migration run <ID>` to run a migration');
49
+ listMigrationDebug(`Successfully listed ${migrations.length} migrations`);
50
+ } catch (error) {
51
+ if (error.code === 'ENOENT') {
52
+ this.log('No migrations folder found in the project');
53
+ this.log(`\nRun ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`);
54
+ return;
55
+ }
56
+ listMigrationDebug('Failed to list migrations:', error);
57
+ this.error(`List migrations failed: ${error instanceof Error ? error.message : String(error)}`, {
58
+ exit: 1
59
+ });
60
+ }
61
+ }
62
+ }
63
+
64
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/commands/migrations/list.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {Table} from 'console-table-printer'\n\nimport {resolveMigrations} from '../../actions/migration/resolveMigrations.js'\n\nconst listMigrationDebug = subdebug('migration:list')\n\nexport class ListMigrationCommand extends SanityCommand<typeof ListMigrationCommand> {\n static override description = 'List available migrations'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List all available migrations in the project',\n },\n ]\n\n static override hiddenAliases = ['migration:list']\n\n public async run(): Promise<void> {\n const {directory: workDir} = await this.getProjectRoot()\n\n try {\n const migrations = await resolveMigrations(workDir)\n\n if (migrations.length === 0) {\n this.log('No migrations found in migrations folder of the project')\n this.log(\n `\\nRun ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\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 ],\n title: `Found ${migrations.length} migrations in project`,\n })\n\n for (const definedMigration of migrations) {\n table.addRow({id: definedMigration.id, title: definedMigration.migration.title})\n }\n table.printTable()\n this.log('\\nRun `sanity migration run <ID>` to run a migration')\n listMigrationDebug(`Successfully listed ${migrations.length} migrations`)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n this.log('No migrations folder found in the project')\n this.log(\n `\\nRun ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\n return\n }\n listMigrationDebug('Failed to list migrations:', error)\n this.error(\n `List migrations failed: ${error instanceof Error ? error.message : String(error)}`,\n {\n exit: 1,\n },\n )\n }\n }\n}\n"],"names":["styleText","SanityCommand","subdebug","Table","resolveMigrations","listMigrationDebug","ListMigrationCommand","description","examples","command","hiddenAliases","run","directory","workDir","getProjectRoot","migrations","length","log","table","columns","alignment","name","title","definedMigration","addRow","id","migration","printTable","error","code","Error","message","String","exit"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxD,SAAQC,KAAK,QAAO,wBAAuB;AAE3C,SAAQC,iBAAiB,QAAO,+CAA8C;AAE9E,MAAMC,qBAAqBH,SAAS;AAEpC,OAAO,MAAMI,6BAA6BL;IACxC,OAAgBM,cAAc,4BAA2B;IAEzD,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTF,aAAa;QACf;KACD,CAAA;IAED,OAAgBG,gBAAgB;QAAC;KAAiB,CAAA;IAElD,MAAaC,MAAqB;QAChC,MAAM,EAACC,WAAWC,OAAO,EAAC,GAAG,MAAM,IAAI,CAACC,cAAc;QAEtD,IAAI;YACF,MAAMC,aAAa,MAAMX,kBAAkBS;YAE3C,IAAIE,WAAWC,MAAM,KAAK,GAAG;gBAC3B,IAAI,CAACC,GAAG,CAAC;gBACT,IAAI,CAACA,GAAG,CACN,CAAC,MAAM,EAAEjB,UAAU,SAAS,oCAAoC,0BAA0B,CAAC;gBAE7F;YACF;YAEA,MAAMkB,QAAQ,IAAIf,MAAM;gBACtBgB,SAAS;oBACP;wBAACC,WAAW;wBAAQC,MAAM;wBAAMC,OAAO;oBAAI;oBAC3C;wBAACF,WAAW;wBAAQC,MAAM;wBAASC,OAAO;oBAAO;iBAClD;gBACDA,OAAO,CAAC,MAAM,EAAEP,WAAWC,MAAM,CAAC,sBAAsB,CAAC;YAC3D;YAEA,KAAK,MAAMO,oBAAoBR,WAAY;gBACzCG,MAAMM,MAAM,CAAC;oBAACC,IAAIF,iBAAiBE,EAAE;oBAAEH,OAAOC,iBAAiBG,SAAS,CAACJ,KAAK;gBAAA;YAChF;YACAJ,MAAMS,UAAU;YAChB,IAAI,CAACV,GAAG,CAAC;YACTZ,mBAAmB,CAAC,oBAAoB,EAAEU,WAAWC,MAAM,CAAC,WAAW,CAAC;QAC1E,EAAE,OAAOY,OAAO;YACd,IAAI,AAACA,MAAgCC,IAAI,KAAK,UAAU;gBACtD,IAAI,CAACZ,GAAG,CAAC;gBACT,IAAI,CAACA,GAAG,CACN,CAAC,MAAM,EAAEjB,UAAU,SAAS,oCAAoC,0BAA0B,CAAC;gBAE7F;YACF;YACAK,mBAAmB,8BAA8BuB;YACjD,IAAI,CAACA,KAAK,CACR,CAAC,wBAAwB,EAAEA,iBAAiBE,QAAQF,MAAMG,OAAO,GAAGC,OAAOJ,QAAQ,EACnF;gBACEK,MAAM;YACR;QAEJ;IACF;AACF"}
@@ -0,0 +1,306 @@
1
+ import path from 'node:path';
2
+ import { styleText } from 'node:util';
3
+ import { Args, Flags } from '@oclif/core';
4
+ import { getProjectCliClient, SanityCommand, subdebug } from '@sanity/cli-core';
5
+ import { confirm, spinner } from '@sanity/cli-core/ux';
6
+ import { DEFAULT_MUTATION_CONCURRENCY, dryRun, MAX_MUTATION_CONCURRENCY, run } from '@sanity/migrate';
7
+ import { Table } from 'console-table-printer';
8
+ import { DEFAULT_API_VERSION, MIGRATIONS_DIRECTORY } from '../../actions/migration/constants.js';
9
+ import { ensureApiVersionFormat } from '../../actions/migration/ensureApiVersionFormat.js';
10
+ import { prettyFormat } from '../../actions/migration/prettyMutationFormatter.js';
11
+ import { resolveMigrations } from '../../actions/migration/resolveMigrations.js';
12
+ import { isLoadableMigrationScript, resolveMigrationScript } from '../../actions/migration/resolveMigrationScript.js';
13
+ const runMigrationDebug = subdebug('migration:run');
14
+ export class RunMigrationCommand extends SanityCommand {
15
+ static args = {
16
+ id: Args.string({
17
+ description: 'ID',
18
+ required: false
19
+ })
20
+ };
21
+ static description = 'Run a migration against a dataset';
22
+ static examples = [
23
+ {
24
+ command: '<%= config.bin %> <%= command.id %> <id>',
25
+ description: 'dry run the migration'
26
+ },
27
+ {
28
+ command: '<%= config.bin %> <%= command.id %> <id> --no-dry-run --project xyz --dataset staging',
29
+ description: 'execute the migration against a dataset'
30
+ },
31
+ {
32
+ command: '<%= config.bin %> <%= command.id %> <id> --from-export=production.tar.gz --no-dry-run --project xyz --dataset staging',
33
+ description: 'execute the migration using a dataset export as the source'
34
+ }
35
+ ];
36
+ static flags = {
37
+ 'api-version': Flags.string({
38
+ description: `API version to use when migrating. Defaults to ${DEFAULT_API_VERSION}.`
39
+ }),
40
+ concurrency: Flags.integer({
41
+ default: DEFAULT_MUTATION_CONCURRENCY,
42
+ description: `How many mutation requests to run in parallel. Must be between 1 and ${MAX_MUTATION_CONCURRENCY}. Default: ${DEFAULT_MUTATION_CONCURRENCY}.`
43
+ }),
44
+ confirm: Flags.boolean({
45
+ allowNo: true,
46
+ default: true,
47
+ description: 'Prompt for confirmation before running the migration (default: true). Use --no-confirm to skip.'
48
+ }),
49
+ dataset: Flags.string({
50
+ description: 'Dataset to migrate. Defaults to the dataset configured in your Sanity CLI config.'
51
+ }),
52
+ 'dry-run': Flags.boolean({
53
+ allowNo: true,
54
+ default: true,
55
+ description: 'By default the migration runs in dry mode. Use --no-dry-run to migrate dataset.'
56
+ }),
57
+ 'from-export': Flags.string({
58
+ description: 'Use a local dataset export as source for migration instead of calling the Sanity API. Note: this is only supported for dry runs.'
59
+ }),
60
+ progress: Flags.boolean({
61
+ allowNo: true,
62
+ default: true,
63
+ description: 'Display progress during migration (default: true). Use --no-progress to hide output.'
64
+ }),
65
+ project: Flags.string({
66
+ description: 'Project ID of the dataset to migrate. Defaults to the projectId configured in your Sanity CLI config.'
67
+ })
68
+ };
69
+ static hiddenAliases = [
70
+ 'migration:run'
71
+ ];
72
+ async run() {
73
+ const { args, flags } = await this.parse(RunMigrationCommand);
74
+ const { directory: workDir } = await this.getProjectRoot();
75
+ const id = args.id;
76
+ const migrationsDirectoryPath = path.join(workDir, MIGRATIONS_DIRECTORY);
77
+ // Listing migrations (no id given) only needs a project root, mirroring
78
+ // `sanity migrations list` — it must not require api.projectId/dataset.
79
+ if (!id) {
80
+ this.warn(styleText('red', 'Error: Migration ID must be provided'));
81
+ let migrations = [];
82
+ try {
83
+ migrations = await resolveMigrations(workDir);
84
+ } catch (error) {
85
+ // A missing migrations folder is expected for a fresh project; surface
86
+ // any other failure (e.g. a syntax error in a migration file).
87
+ if (error.code !== 'ENOENT') {
88
+ this.error(`Failed to list migrations: ${error instanceof Error ? error.message : String(error)}`, {
89
+ exit: 1
90
+ });
91
+ }
92
+ }
93
+ if (migrations.length === 0) {
94
+ this.log('\nNo migrations found in the project');
95
+ this.log(`Run ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`);
96
+ this.exit(1);
97
+ }
98
+ const table = new Table({
99
+ columns: [
100
+ {
101
+ alignment: 'left',
102
+ name: 'id',
103
+ title: 'ID'
104
+ },
105
+ {
106
+ alignment: 'left',
107
+ name: 'title',
108
+ title: 'Title'
109
+ }
110
+ ],
111
+ title: `Migrations found in project`
112
+ });
113
+ for (const definedMigration of migrations){
114
+ table.addRow({
115
+ id: definedMigration.id,
116
+ title: definedMigration.migration.title
117
+ });
118
+ }
119
+ table.printTable();
120
+ this.log('\nRun `sanity migration run <ID>` to run a migration');
121
+ this.exit(1);
122
+ }
123
+ const cliConfig = await this.getCliConfig();
124
+ const projectId = await this.getProjectId({
125
+ deprecatedFlagName: 'project'
126
+ });
127
+ const datasetFromConfig = cliConfig.api?.dataset;
128
+ const fromExport = flags['from-export'];
129
+ const dry = flags['dry-run'];
130
+ const dataset = flags.dataset;
131
+ const project = flags.project;
132
+ const apiVersion = ensureApiVersionFormat(flags['api-version'] ?? DEFAULT_API_VERSION);
133
+ if (dataset && !project || project && !dataset) {
134
+ this.error('If either --dataset or --project is provided, both must be provided', {
135
+ exit: 1
136
+ });
137
+ }
138
+ if (!project && !projectId) {
139
+ this.error('sanity.cli.js does not contain a project identifier ("api.projectId") and no --project option was provided.', {
140
+ exit: 1
141
+ });
142
+ }
143
+ if (!dataset && !datasetFromConfig) {
144
+ this.error('sanity.cli.js does not contain a dataset identifier ("api.dataset") and no --dataset option was provided.', {
145
+ exit: 1
146
+ });
147
+ }
148
+ const candidates = await resolveMigrationScript(workDir, id);
149
+ const resolvedScripts = candidates.filter((candidate)=>isLoadableMigrationScript(candidate));
150
+ if (resolvedScripts.length > 1) {
151
+ // todo: consider prompt user about which one to run? note: it's likely a mistake if multiple files resolve to the same name
152
+ this.error(`Found multiple migrations for "${id}" in ${styleText('cyan', migrationsDirectoryPath)}: \n - ${candidates.map((candidate)=>path.relative(migrationsDirectoryPath, candidate.absolutePath)).join('\n - ')}`, {
153
+ exit: 1
154
+ });
155
+ }
156
+ const script = resolvedScripts[0];
157
+ if (!script) {
158
+ this.error(`No migration found for "${id}" in ${styleText('cyan', migrationsDirectoryPath)}. Make sure that the migration file exists and exports a valid migration as its default export.\n
159
+ Tried the following files:\n - ${candidates.map((candidate)=>path.relative(migrationsDirectoryPath, candidate.absolutePath)).join('\n - ')}`, {
160
+ exit: 1
161
+ });
162
+ }
163
+ const mod = script.mod;
164
+ if ('up' in mod || 'down' in mod) {
165
+ // todo: consider adding support for up/down as separate named exports
166
+ // For now, make sure we reserve the names for future use
167
+ this.error('Named "up"/"down" migration exports are not supported at this time, please export your migration as the default export', {
168
+ exit: 1
169
+ });
170
+ }
171
+ const migration = mod.default;
172
+ if (fromExport && !dry) {
173
+ this.error('Can only dry run migrations from a dataset export file', {
174
+ exit: 1
175
+ });
176
+ }
177
+ const concurrency = flags.concurrency;
178
+ if (concurrency !== undefined) {
179
+ if (concurrency > MAX_MUTATION_CONCURRENCY) {
180
+ this.error(`Concurrency exceeds the maximum allowed value of ${MAX_MUTATION_CONCURRENCY}`, {
181
+ exit: 1
182
+ });
183
+ }
184
+ if (concurrency < 1) {
185
+ this.error(`Concurrency must be a positive number, got ${concurrency}`, {
186
+ exit: 1
187
+ });
188
+ }
189
+ }
190
+ const projectClient = await getProjectCliClient({
191
+ apiVersion,
192
+ projectId: project ?? projectId,
193
+ requireUser: true
194
+ });
195
+ const projectConfig = projectClient.config();
196
+ const apiConfig = {
197
+ apiHost: projectConfig.apiHost,
198
+ apiVersion,
199
+ dataset: dataset ?? datasetFromConfig,
200
+ projectId: project ?? projectId,
201
+ token: projectConfig.token
202
+ };
203
+ if (dry) {
204
+ await this.dryRunHandler(id, migration, apiConfig, fromExport);
205
+ return;
206
+ }
207
+ this.log(`\n${styleText([
208
+ 'yellow',
209
+ 'bold'
210
+ ], 'Note: During migrations, your webhooks stay active.')}`);
211
+ this.log(`To adjust them, launch the management interface with ${styleText('cyan', 'sanity manage')}, navigate to the API settings, and toggle the webhooks before and after the migration as needed.\n`);
212
+ if (flags.confirm) {
213
+ await this.promptConfirmMigrate(apiConfig);
214
+ }
215
+ const spin = spinner(`Running migration "${id}"`).start();
216
+ try {
217
+ await run({
218
+ api: apiConfig,
219
+ concurrency,
220
+ onProgress: this.createProgress(spin, flags, id, dry, apiConfig, migration)
221
+ }, migration);
222
+ } finally{
223
+ spin.stop();
224
+ }
225
+ }
226
+ createProgress(progressSpinner, flags, id, dry, apiConfig, migration) {
227
+ return function onProgress(progress) {
228
+ if (!flags.progress) {
229
+ progressSpinner.stop();
230
+ return;
231
+ }
232
+ if (progress.done) {
233
+ progressSpinner.text = `Migration "${id}" completed.
234
+
235
+ Project id: ${styleText('bold', apiConfig.projectId)}
236
+ Dataset: ${styleText('bold', apiConfig.dataset)}
237
+
238
+ ${progress.documents} documents processed.
239
+ ${progress.mutations} mutations generated.
240
+ ${styleText('green', String(progress.completedTransactions.length))} transactions committed.`;
241
+ progressSpinner.stopAndPersist({
242
+ symbol: styleText('green', '✔')
243
+ });
244
+ return;
245
+ }
246
+ for (const transaction of [
247
+ null,
248
+ ...progress.currentTransactions
249
+ ]){
250
+ progressSpinner.text = `Running migration "${id}" ${dry ? 'in dry mode...' : '...'}
251
+
252
+ Project id: ${styleText('bold', apiConfig.projectId)}
253
+ Dataset: ${styleText('bold', apiConfig.dataset)}
254
+ Document type: ${styleText('bold', migration.documentTypes?.join(',') ?? '')}
255
+
256
+ ${progress.documents} documents processed…
257
+ ${progress.mutations} mutations generated…
258
+ ${styleText('blue', String(progress.pending))} requests pending…
259
+ ${styleText('green', String(progress.completedTransactions.length))} transactions committed.
260
+
261
+ ${transaction && !progress.done ? `» ${prettyFormat({
262
+ indentSize: 2,
263
+ migration,
264
+ subject: transaction
265
+ })}` : ''}`;
266
+ }
267
+ };
268
+ }
269
+ async dryRunHandler(id, migration, apiConfig, fromExport) {
270
+ this.log(`Running migration "${id}" in dry mode`);
271
+ if (fromExport) {
272
+ this.log(`Using export ${styleText('cyan', fromExport)}`);
273
+ }
274
+ this.log();
275
+ this.log(`Project id: ${styleText('bold', apiConfig.projectId)}`);
276
+ this.log(`Dataset: ${styleText('bold', apiConfig.dataset)}`);
277
+ for await (const mutation of dryRun({
278
+ api: apiConfig,
279
+ exportPath: fromExport
280
+ }, migration)){
281
+ if (!mutation) continue;
282
+ this.log();
283
+ this.log(prettyFormat({
284
+ migration,
285
+ subject: mutation
286
+ }));
287
+ }
288
+ }
289
+ async promptConfirmMigrate(apiConfig) {
290
+ const response = await confirm({
291
+ message: `This migration will run on the ${styleText([
292
+ 'yellow',
293
+ 'bold'
294
+ ], apiConfig.dataset)} dataset in ${styleText([
295
+ 'yellow',
296
+ 'bold'
297
+ ], apiConfig.projectId)} project. Are you sure?`
298
+ });
299
+ if (!response) {
300
+ runMigrationDebug('User aborted migration');
301
+ this.exit(1);
302
+ }
303
+ }
304
+ }
305
+
306
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/commands/migrations/run.ts"],"sourcesContent":["import path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {confirm, spinner} from '@sanity/cli-core/ux'\nimport {\n type APIConfig,\n DEFAULT_MUTATION_CONCURRENCY,\n dryRun,\n MAX_MUTATION_CONCURRENCY,\n type Migration,\n type MigrationProgress,\n run,\n} from '@sanity/migrate'\nimport {Table} from 'console-table-printer'\n\nimport {DEFAULT_API_VERSION, MIGRATIONS_DIRECTORY} from '../../actions/migration/constants.js'\nimport {ensureApiVersionFormat} from '../../actions/migration/ensureApiVersionFormat.js'\nimport {prettyFormat} from '../../actions/migration/prettyMutationFormatter.js'\nimport {resolveMigrations} from '../../actions/migration/resolveMigrations.js'\nimport {\n isLoadableMigrationScript,\n resolveMigrationScript,\n} from '../../actions/migration/resolveMigrationScript.js'\n\nconst runMigrationDebug = subdebug('migration:run')\n\nexport type RunMigrationFlags = RunMigrationCommand['flags']\n\nexport class RunMigrationCommand extends SanityCommand<typeof RunMigrationCommand> {\n static override args = {\n id: Args.string({\n description: 'ID',\n required: false,\n }),\n }\n\n static override description = 'Run a migration against a dataset'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> <id>',\n description: 'dry run the migration',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> <id> --no-dry-run --project xyz --dataset staging',\n description: 'execute the migration against a dataset',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> <id> --from-export=production.tar.gz --no-dry-run --project xyz --dataset staging',\n description: 'execute the migration using a dataset export as the source',\n },\n ]\n\n static override flags = {\n 'api-version': Flags.string({\n description: `API version to use when migrating. Defaults to ${DEFAULT_API_VERSION}.`,\n }),\n concurrency: Flags.integer({\n default: DEFAULT_MUTATION_CONCURRENCY,\n description: `How many mutation requests to run in parallel. Must be between 1 and ${MAX_MUTATION_CONCURRENCY}. Default: ${DEFAULT_MUTATION_CONCURRENCY}.`,\n }),\n confirm: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Prompt for confirmation before running the migration (default: true). Use --no-confirm to skip.',\n }),\n dataset: Flags.string({\n description:\n 'Dataset to migrate. Defaults to the dataset configured in your Sanity CLI config.',\n }),\n 'dry-run': Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'By default the migration runs in dry mode. Use --no-dry-run to migrate dataset.',\n }),\n 'from-export': Flags.string({\n description:\n 'Use a local dataset export as source for migration instead of calling the Sanity API. Note: this is only supported for dry runs.',\n }),\n progress: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Display progress during migration (default: true). Use --no-progress to hide output.',\n }),\n project: Flags.string({\n description:\n 'Project ID of the dataset to migrate. Defaults to the projectId configured in your Sanity CLI config.',\n }),\n }\n\n static override hiddenAliases = ['migration:run']\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(RunMigrationCommand)\n const {directory: workDir} = await this.getProjectRoot()\n const id = args.id\n const migrationsDirectoryPath = path.join(workDir, MIGRATIONS_DIRECTORY)\n\n // Listing migrations (no id given) only needs a project root, mirroring\n // `sanity migrations list` — it must not require api.projectId/dataset.\n if (!id) {\n this.warn(styleText('red', 'Error: Migration ID must be provided'))\n\n let migrations: Awaited<ReturnType<typeof resolveMigrations>> = []\n try {\n migrations = await resolveMigrations(workDir)\n } catch (error) {\n // A missing migrations folder is expected for a fresh project; surface\n // any other failure (e.g. a syntax error in a migration file).\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n this.error(\n `Failed to list migrations: ${error instanceof Error ? error.message : String(error)}`,\n {exit: 1},\n )\n }\n }\n\n if (migrations.length === 0) {\n this.log('\\nNo migrations found in the project')\n this.log(\n `Run ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\n this.exit(1)\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'title', title: 'Title'},\n ],\n title: `Migrations found in project`,\n })\n\n for (const definedMigration of migrations) {\n table.addRow({id: definedMigration.id, title: definedMigration.migration.title})\n }\n table.printTable()\n this.log('\\nRun `sanity migration run <ID>` to run a migration')\n\n this.exit(1)\n }\n\n const cliConfig = await this.getCliConfig()\n const projectId = await this.getProjectId({deprecatedFlagName: 'project'})\n const datasetFromConfig = cliConfig.api?.dataset\n\n const fromExport = flags['from-export']\n const dry = flags['dry-run']\n const dataset = flags.dataset\n const project = flags.project\n const apiVersion = ensureApiVersionFormat(flags['api-version'] ?? DEFAULT_API_VERSION)\n\n if ((dataset && !project) || (project && !dataset)) {\n this.error('If either --dataset or --project is provided, both must be provided', {exit: 1})\n }\n\n if (!project && !projectId) {\n this.error(\n 'sanity.cli.js does not contain a project identifier (\"api.projectId\") and no --project option was provided.',\n {exit: 1},\n )\n }\n\n if (!dataset && !datasetFromConfig) {\n this.error(\n 'sanity.cli.js does not contain a dataset identifier (\"api.dataset\") and no --dataset option was provided.',\n {exit: 1},\n )\n }\n\n const candidates = await resolveMigrationScript(workDir, id)\n const resolvedScripts = candidates.filter((candidate) => isLoadableMigrationScript(candidate))\n\n if (resolvedScripts.length > 1) {\n // todo: consider prompt user about which one to run? note: it's likely a mistake if multiple files resolve to the same name\n this.error(\n `Found multiple migrations for \"${id}\" in ${styleText('cyan', migrationsDirectoryPath)}: \\n - ${candidates\n .map((candidate) => path.relative(migrationsDirectoryPath, candidate.absolutePath))\n .join('\\n - ')}`,\n {exit: 1},\n )\n }\n\n const script = resolvedScripts[0]\n if (!script) {\n this.error(\n `No migration found for \"${id}\" in ${styleText('cyan', migrationsDirectoryPath)}. Make sure that the migration file exists and exports a valid migration as its default export.\\n\n Tried the following files:\\n - ${candidates\n .map((candidate) => path.relative(migrationsDirectoryPath, candidate.absolutePath))\n .join('\\n - ')}`,\n {exit: 1},\n )\n }\n\n const mod = script.mod\n if ('up' in mod || 'down' in mod) {\n // todo: consider adding support for up/down as separate named exports\n // For now, make sure we reserve the names for future use\n this.error(\n 'Named \"up\"/\"down\" migration exports are not supported at this time, please export your migration as the default export',\n {\n exit: 1,\n },\n )\n }\n\n const migration: Migration = mod.default\n\n if (fromExport && !dry) {\n this.error('Can only dry run migrations from a dataset export file', {exit: 1})\n }\n\n const concurrency = flags.concurrency\n if (concurrency !== undefined) {\n if (concurrency > MAX_MUTATION_CONCURRENCY) {\n this.error(`Concurrency exceeds the maximum allowed value of ${MAX_MUTATION_CONCURRENCY}`, {\n exit: 1,\n })\n }\n\n if (concurrency < 1) {\n this.error(`Concurrency must be a positive number, got ${concurrency}`, {exit: 1})\n }\n }\n\n const projectClient = await getProjectCliClient({\n apiVersion,\n projectId: (project ?? projectId)!,\n requireUser: true,\n })\n const projectConfig = projectClient.config()\n\n const apiConfig: APIConfig = {\n apiHost: projectConfig.apiHost,\n apiVersion,\n dataset: (dataset ?? datasetFromConfig)!,\n projectId: (project ?? projectId)!,\n token: projectConfig.token!,\n } as const\n if (dry) {\n await this.dryRunHandler(id, migration, apiConfig, fromExport)\n return\n }\n\n this.log(\n `\\n${styleText(['yellow', 'bold'], 'Note: During migrations, your webhooks stay active.')}`,\n )\n this.log(\n `To adjust them, launch the management interface with ${styleText('cyan', 'sanity manage')}, navigate to the API settings, and toggle the webhooks before and after the migration as needed.\\n`,\n )\n\n if (flags.confirm) {\n await this.promptConfirmMigrate(apiConfig)\n }\n\n const spin = spinner(`Running migration \"${id}\"`).start()\n try {\n await run(\n {\n api: apiConfig,\n concurrency,\n onProgress: this.createProgress(spin, flags, id, dry, apiConfig, migration),\n },\n migration,\n )\n } finally {\n spin.stop()\n }\n }\n\n private createProgress(\n progressSpinner: ReturnType<typeof spinner>,\n flags: RunMigrationFlags,\n id: string,\n dry: boolean,\n apiConfig: APIConfig,\n migration: Migration,\n ) {\n return function onProgress(progress: MigrationProgress) {\n if (!flags.progress) {\n progressSpinner.stop()\n return\n }\n if (progress.done) {\n progressSpinner.text = `Migration \"${id}\" completed.\n\n Project id: ${styleText('bold', apiConfig.projectId)}\n Dataset: ${styleText('bold', apiConfig.dataset)}\n\n ${progress.documents} documents processed.\n ${progress.mutations} mutations generated.\n ${styleText('green', String(progress.completedTransactions.length))} transactions committed.`\n progressSpinner.stopAndPersist({symbol: styleText('green', '✔')})\n return\n }\n\n for (const transaction of [null, ...progress.currentTransactions]) {\n progressSpinner.text = `Running migration \"${id}\" ${dry ? 'in dry mode...' : '...'}\n\n Project id: ${styleText('bold', apiConfig.projectId)}\n Dataset: ${styleText('bold', apiConfig.dataset)}\n Document type: ${styleText('bold', migration.documentTypes?.join(',') ?? '')}\n\n ${progress.documents} documents processed…\n ${progress.mutations} mutations generated…\n ${styleText('blue', String(progress.pending))} requests pending…\n ${styleText('green', String(progress.completedTransactions.length))} transactions committed.\n\n ${\n transaction && !progress.done\n ? `» ${prettyFormat({indentSize: 2, migration, subject: transaction})}`\n : ''\n }`\n }\n }\n }\n\n private async dryRunHandler(\n id: string,\n migration: Migration,\n apiConfig: APIConfig,\n fromExport: string | undefined,\n ) {\n this.log(`Running migration \"${id}\" in dry mode`)\n\n if (fromExport) {\n this.log(`Using export ${styleText('cyan', fromExport)}`)\n }\n\n this.log()\n this.log(`Project id: ${styleText('bold', apiConfig.projectId)}`)\n this.log(`Dataset: ${styleText('bold', apiConfig.dataset)}`)\n\n for await (const mutation of dryRun({api: apiConfig, exportPath: fromExport}, migration)) {\n if (!mutation) continue\n this.log()\n this.log(\n prettyFormat({\n migration,\n subject: mutation,\n }),\n )\n }\n }\n\n private async promptConfirmMigrate(apiConfig: APIConfig) {\n const response = await confirm({\n message: `This migration will run on the ${styleText(\n ['yellow', 'bold'],\n apiConfig.dataset,\n )} dataset in ${styleText(['yellow', 'bold'], apiConfig.projectId)} project. Are you sure?`,\n })\n\n if (!response) {\n runMigrationDebug('User aborted migration')\n this.exit(1)\n }\n }\n}\n"],"names":["path","styleText","Args","Flags","getProjectCliClient","SanityCommand","subdebug","confirm","spinner","DEFAULT_MUTATION_CONCURRENCY","dryRun","MAX_MUTATION_CONCURRENCY","run","Table","DEFAULT_API_VERSION","MIGRATIONS_DIRECTORY","ensureApiVersionFormat","prettyFormat","resolveMigrations","isLoadableMigrationScript","resolveMigrationScript","runMigrationDebug","RunMigrationCommand","args","id","string","description","required","examples","command","flags","concurrency","integer","default","boolean","allowNo","dataset","progress","project","hiddenAliases","parse","directory","workDir","getProjectRoot","migrationsDirectoryPath","join","warn","migrations","error","code","Error","message","String","exit","length","log","table","columns","alignment","name","title","definedMigration","addRow","migration","printTable","cliConfig","getCliConfig","projectId","getProjectId","deprecatedFlagName","datasetFromConfig","api","fromExport","dry","apiVersion","candidates","resolvedScripts","filter","candidate","map","relative","absolutePath","script","mod","undefined","projectClient","requireUser","projectConfig","config","apiConfig","apiHost","token","dryRunHandler","promptConfirmMigrate","spin","start","onProgress","createProgress","stop","progressSpinner","done","text","documents","mutations","completedTransactions","stopAndPersist","symbol","transaction","currentTransactions","documentTypes","pending","indentSize","subject","mutation","exportPath","response"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAC7E,SAAQC,OAAO,EAAEC,OAAO,QAAO,sBAAqB;AACpD,SAEEC,4BAA4B,EAC5BC,MAAM,EACNC,wBAAwB,EAGxBC,GAAG,QACE,kBAAiB;AACxB,SAAQC,KAAK,QAAO,wBAAuB;AAE3C,SAAQC,mBAAmB,EAAEC,oBAAoB,QAAO,uCAAsC;AAC9F,SAAQC,sBAAsB,QAAO,oDAAmD;AACxF,SAAQC,YAAY,QAAO,qDAAoD;AAC/E,SAAQC,iBAAiB,QAAO,+CAA8C;AAC9E,SACEC,yBAAyB,EACzBC,sBAAsB,QACjB,oDAAmD;AAE1D,MAAMC,oBAAoBf,SAAS;AAInC,OAAO,MAAMgB,4BAA4BjB;IACvC,OAAgBkB,OAAO;QACrBC,IAAItB,KAAKuB,MAAM,CAAC;YACdC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,oCAAmC;IAEjE,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;Q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 export class PreviewCommand extends SanityCommand {
39
39
  cliConfig,
40
40
  flags,
41
41
  outDir,
42
+ output: this.output,
42
43
  workDir
43
44
  });
44
45
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/preview.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {Args, Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\n\nimport {previewAction} from '../actions/preview/previewAction.js'\nimport {type PreviewServer} from '../server/previewServer.js'\n\nexport const previewDebug = subdebug('preview')\n\nexport class PreviewCommand extends SanityCommand<typeof PreviewCommand> {\n static override args = {\n outputDir: Args.directory({description: 'Output directory'}),\n }\n\n static override deprecateAliases = true\n\n static override description = 'Start a local server to preview a production build'\n\n static override examples = [\n '<%= config.bin %> <%= command.id %> --host=0.0.0.0',\n '<%= config.bin %> <%= command.id %> --port=1942',\n '<%= config.bin %> <%= command.id %> some/build-output-dir',\n ]\n\n static override flags = {\n host: Flags.string({\n description: 'Local network interface to listen on (default: localhost)',\n }),\n port: Flags.string({\n description: 'TCP port to start server on (default: 3333)',\n }),\n }\n static override hiddenAliases: string[] = ['start']\n\n public async run(): Promise<PreviewServer | void> {\n const {args, flags} = await this.parse(PreviewCommand)\n\n const workDir = (await this.getProjectRoot()).directory\n const cliConfig = await this.getCliConfig()\n\n const {outputDir} = args\n\n const defaultRootDir = path.resolve(path.join(workDir, 'dist'))\n const outDir = path.resolve(outputDir || defaultRootDir)\n\n try {\n return await previewAction({cliConfig, flags, outDir, workDir})\n } catch (error: unknown) {\n const suggestions =\n error instanceof Error && error.name === 'BUILD_NOT_FOUND'\n ? [\n '`sanity build` to create a production build',\n '`sanity dev` to run a development server',\n ]\n : undefined\n\n const message = error instanceof Error ? error.message : String(error)\n this.output.error(`Failed to start preview server: ${message}`, {\n exit: 1,\n suggestions,\n })\n }\n }\n}\n"],"names":["path","Args","Flags","SanityCommand","subdebug","previewAction","previewDebug","PreviewCommand","args","outputDir","directory","description","deprecateAliases","examples","flags","host","string","port","hiddenAliases","run","parse","workDir","getProjectRoot","cliConfig","getCliConfig","defaultRootDir","resolve","join","outDir","error","suggestions","Error","name","undefined","message","String","output","exit"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAExD,SAAQC,aAAa,QAAO,sCAAqC;AAGjE,OAAO,MAAMC,eAAeF,SAAS,WAAU;AAE/C,OAAO,MAAMG,uBAAuBJ;IAClC,OAAgBK,OAAO;QACrBC,WAAWR,KAAKS,SAAS,CAAC;YAACC,aAAa;QAAkB;IAC5D,EAAC;IAED,OAAgBC,mBAAmB,KAAI;IAEvC,OAAgBD,cAAc,qDAAoD;IAElF,OAAgBE,WAAW;QACzB;QACA;QACA;KACD,CAAA;IAED,OAAgBC,QAAQ;QACtBC,MAAMb,MAAMc,MAAM,CAAC;YACjBL,aAAa;QACf;QACAM,MAAMf,MAAMc,MAAM,CAAC;YACjBL,aAAa;QACf;IACF,EAAC;IACD,OAAgBO,gBAA0B;QAAC;KAAQ,CAAA;IAEnD,MAAaC,MAAqC;QAChD,MAAM,EAACX,IAAI,EAAEM,KAAK,EAAC,GAAG,MAAM,IAAI,CAACM,KAAK,CAACb;QAEvC,MAAMc,UAAU,AAAC,CAAA,MAAM,IAAI,CAACC,cAAc,EAAC,EAAGZ,SAAS;QACvD,MAAMa,YAAY,MAAM,IAAI,CAACC,YAAY;QAEzC,MAAM,EAACf,SAAS,EAAC,GAAGD;QAEpB,MAAMiB,iBAAiBzB,KAAK0B,OAAO,CAAC1B,KAAK2B,IAAI,CAACN,SAAS;QACvD,MAAMO,SAAS5B,KAAK0B,OAAO,CAACjB,aAAagB;QAEzC,IAAI;YACF,OAAO,MAAMpB,cAAc;gBAACkB;gBAAWT;gBAAOc;gBAAQP;YAAO;QAC/D,EAAE,OAAOQ,OAAgB;YACvB,MAAMC,cACJD,iBAAiBE,SAASF,MAAMG,IAAI,KAAK,oBACrC;gBACE;gBACA;aACD,GACDC;YAEN,MAAMC,UAAUL,iBAAiBE,QAAQF,MAAMK,OAAO,GAAGC,OAAON;YAChE,IAAI,CAACO,MAAM,CAACP,KAAK,CAAC,CAAC,gCAAgC,EAAEK,SAAS,EAAE;gBAC9DG,MAAM;gBACNP;YACF;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/commands/preview.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {Args, Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\n\nimport {previewAction} from '../actions/preview/previewAction.js'\nimport {type PreviewServer} from '../server/previewServer.js'\n\nexport const previewDebug = subdebug('preview')\n\nexport class PreviewCommand extends SanityCommand<typeof PreviewCommand> {\n static override args = {\n outputDir: Args.directory({description: 'Output directory'}),\n }\n\n static override deprecateAliases = true\n\n static override description = 'Start a local server to preview a production build'\n\n static override examples = [\n '<%= config.bin %> <%= command.id %> --host=0.0.0.0',\n '<%= config.bin %> <%= command.id %> --port=1942',\n '<%= config.bin %> <%= command.id %> some/build-output-dir',\n ]\n\n static override flags = {\n host: Flags.string({\n description: 'Local network interface to listen on (default: localhost)',\n }),\n port: Flags.string({\n description: 'TCP port to start server on (default: 3333)',\n }),\n }\n static override hiddenAliases: string[] = ['start']\n\n public async run(): Promise<PreviewServer | {close: () => Promise<void>} | void> {\n const {args, flags} = await this.parse(PreviewCommand)\n\n const workDir = (await this.getProjectRoot()).directory\n const cliConfig = await this.getCliConfig()\n\n const {outputDir} = args\n\n const defaultRootDir = path.resolve(path.join(workDir, 'dist'))\n const outDir = path.resolve(outputDir || defaultRootDir)\n\n try {\n return await previewAction({cliConfig, flags, outDir, output: this.output, workDir})\n } catch (error: unknown) {\n const suggestions =\n error instanceof Error && error.name === 'BUILD_NOT_FOUND'\n ? [\n '`sanity build` to create a production build',\n '`sanity dev` to run a development server',\n ]\n : undefined\n\n const message = error instanceof Error ? error.message : String(error)\n this.output.error(`Failed to start preview server: ${message}`, {\n exit: 1,\n suggestions,\n })\n }\n }\n}\n"],"names":["path","Args","Flags","SanityCommand","subdebug","previewAction","previewDebug","PreviewCommand","args","outputDir","directory","description","deprecateAliases","examples","flags","host","string","port","hiddenAliases","run","parse","workDir","getProjectRoot","cliConfig","getCliConfig","defaultRootDir","resolve","join","outDir","output","error","suggestions","Error","name","undefined","message","String","exit"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAExD,SAAQC,aAAa,QAAO,sCAAqC;AAGjE,OAAO,MAAMC,eAAeF,SAAS,WAAU;AAE/C,OAAO,MAAMG,uBAAuBJ;IAClC,OAAgBK,OAAO;QACrBC,WAAWR,KAAKS,SAAS,CAAC;YAACC,aAAa;QAAkB;IAC5D,EAAC;IAED,OAAgBC,mBAAmB,KAAI;IAEvC,OAAgBD,cAAc,qDAAoD;IAElF,OAAgBE,WAAW;QACzB;QACA;QACA;KACD,CAAA;IAED,OAAgBC,QAAQ;QACtBC,MAAMb,MAAMc,MAAM,CAAC;YACjBL,aAAa;QACf;QACAM,MAAMf,MAAMc,MAAM,CAAC;YACjBL,aAAa;QACf;IACF,EAAC;IACD,OAAgBO,gBAA0B;QAAC;KAAQ,CAAA;IAEnD,MAAaC,MAAoE;QAC/E,MAAM,EAACX,IAAI,EAAEM,KAAK,EAAC,GAAG,MAAM,IAAI,CAACM,KAAK,CAACb;QAEvC,MAAMc,UAAU,AAAC,CAAA,MAAM,IAAI,CAACC,cAAc,EAAC,EAAGZ,SAAS;QACvD,MAAMa,YAAY,MAAM,IAAI,CAACC,YAAY;QAEzC,MAAM,EAACf,SAAS,EAAC,GAAGD;QAEpB,MAAMiB,iBAAiBzB,KAAK0B,OAAO,CAAC1B,KAAK2B,IAAI,CAACN,SAAS;QACvD,MAAMO,SAAS5B,KAAK0B,OAAO,CAACjB,aAAagB;QAEzC,IAAI;YACF,OAAO,MAAMpB,cAAc;gBAACkB;gBAAWT;gBAAOc;gBAAQC,QAAQ,IAAI,CAACA,MAAM;gBAAER;YAAO;QACpF,EAAE,OAAOS,OAAgB;YACvB,MAAMC,cACJD,iBAAiBE,SAASF,MAAMG,IAAI,KAAK,oBACrC;gBACE;gBACA;aACD,GACDC;YAEN,MAAMC,UAAUL,iBAAiBE,QAAQF,MAAMK,OAAO,GAAGC,OAAON;YAChE,IAAI,CAACD,MAAM,CAACC,KAAK,CAAC,CAAC,gCAAgC,EAAEK,SAAS,EAAE;gBAC9DE,MAAM;gBACNN;YACF;QACF;IACF;AACF"}
@@ -1,5 +1,6 @@
1
1
  import { Args, Flags } from '@oclif/core';
2
2
  import { CLIError } from '@oclif/core/errors';
3
+ import { exitCodes } from '@sanity/cli-core';
3
4
  import { subdebug } from '@sanity/cli-core/debug';
4
5
  import { SanityCommand } from '@sanity/cli-core/SanityCommand';
5
6
  import { confirm, spinner } from '@sanity/cli-core/ux';
@@ -52,7 +53,7 @@ export class CreateProjectCommand extends SanityCommand {
52
53
  const datasetNameError = validateDatasetName(input);
53
54
  if (datasetNameError) {
54
55
  throw new CLIError(datasetNameError, {
55
- exit: 2
56
+ exit: exitCodes.USAGE_ERROR
56
57
  });
57
58
  }
58
59
  return input;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/projects/create.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {CLIError} from '@oclif/core/errors'\nimport {subdebug} from '@sanity/cli-core/debug'\nimport {SanityCommand} from '@sanity/cli-core/SanityCommand'\nimport {confirm, spinner} from '@sanity/cli-core/ux'\nimport {type DatasetResponse} from '@sanity/client'\n\nimport {createDataset} from '../../actions/dataset/create.js'\nimport {validateDatasetName} from '../../actions/dataset/validateDatasetName.js'\nimport {getOrganization} from '../../actions/organizations/getOrganization.js'\nimport {getManageUrl} from '../../actions/projects/getManageUrl.js'\nimport {promptForDatasetName} from '../../prompts/promptForDatasetName.js'\nimport {promptForDefaultConfig} from '../../prompts/promptForDefaultConfig.js'\nimport {promptForProjectName} from '../../prompts/promptForProjectName.js'\nimport {listDatasets} from '../../services/datasets.js'\nimport {getProjectFeatures} from '../../services/getProjectFeatures.js'\nimport {\n type OrganizationCreateResponse,\n type ProjectOrganization,\n} from '../../services/organizations.js'\nimport {createProject, type CreateProjectResult} from '../../services/projects.js'\nimport {getCliUser} from '../../services/user.js'\n\nconst debug = subdebug('projects:create')\n\nexport class CreateProjectCommand extends SanityCommand<typeof CreateProjectCommand> {\n static override args = {\n projectName: Args.string({\n description: 'Name of the project to create',\n required: false,\n }),\n }\n\n static override description = 'Create a new Sanity project'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Interactively create a project',\n },\n {\n command: '<%= config.bin %> <%= command.id %> \"My New Project\"',\n description: 'Create a project named \"My New Project\"',\n },\n {\n command: '<%= config.bin %> <%= command.id %> \"My Project\" --organization=my-org',\n description: 'Create a project in a specific organization',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> \"My Project\" --dataset=staging --dataset-visibility=private',\n description: 'Create a project with a private dataset named \"staging\"',\n },\n {\n command: '<%= config.bin %> <%= command.id %> \"CI Project\" --yes --json',\n description: 'Create a project non-interactively with JSON output',\n },\n ]\n\n static override flags = {\n dataset: Flags.string({\n description: 'Create a dataset. Prompts for visibility unless specified or --yes used',\n parse: async (input) => {\n const datasetNameError = validateDatasetName(input)\n if (datasetNameError) {\n throw new CLIError(datasetNameError, {exit: 2})\n }\n\n return input\n },\n }),\n 'dataset-visibility': Flags.string({\n description: 'Dataset visibility: public or private',\n options: ['private', 'public'],\n }),\n json: Flags.boolean({\n default: false,\n description: 'Output in JSON format',\n }),\n organization: Flags.string({\n description: 'Organization to create the project in',\n helpValue: '<slug|id>',\n }),\n yes: Flags.boolean({\n char: 'y',\n default: false,\n description:\n 'Skip prompts and use defaults (project: \"My Sanity Project\", dataset: production, visibility: public)',\n }),\n }\n\n static override hiddenAliases: string[] = ['project:create']\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(CreateProjectCommand)\n const {projectName} = args\n const {dataset, 'dataset-visibility': datasetVisibility, organization, yes} = flags\n const user = await getCliUser()\n\n const finalProjectName =\n projectName ||\n (yes || this.isUnattended() ? 'My Sanity Project' : await promptForProjectName())\n\n debug('Creating project with options: %O', {\n dataset,\n datasetVisibility,\n organizationId: organization,\n projectName,\n unattended: yes,\n })\n\n let chosenOrganization: OrganizationCreateResponse | ProjectOrganization | undefined\n try {\n chosenOrganization = await getOrganization({\n isUnattended: this.isUnattended(),\n output: this.output,\n requestedId: organization,\n user,\n })\n } catch (error) {\n const errorText = organization\n ? `Failed to retrieve organization ${organization}`\n : 'Failed to retrieve an organization'\n return this.output.error(`${errorText}: ${error}`, {exit: 1})\n }\n\n const spin = spinner('Creating project').start()\n let newProject\n try {\n newProject = await createProject({\n displayName: finalProjectName,\n metadata: {\n integration: 'cli',\n },\n organizationId: chosenOrganization?.id,\n })\n spin.succeed('Project created successfully')\n } catch (error) {\n spin.fail()\n debug(`Failed to create project: ${error}`)\n return this.output.error(`Failed to create project: ${error}`, {exit: 1})\n }\n\n let newDataset: DatasetResponse | undefined\n // If dataset name specified, or in attended mode (to prompt for dataset name), create a dataset.\n if (dataset || !this.isUnattended()) {\n newDataset = await this.handleDatasetCreation(\n newProject.projectId,\n dataset,\n datasetVisibility,\n )\n }\n\n this.printProjectCreationSuccess(chosenOrganization, newProject, newDataset)\n }\n\n private async handleDatasetCreation(\n projectId: string,\n datasetFromFlag?: string,\n datasetVisibility?: string,\n ): Promise<DatasetResponse | undefined> {\n try {\n let datasetName: string | undefined = datasetFromFlag\n const existingDatasets = await listDatasets(projectId)\n const existingDatasetNames = existingDatasets.map((ds) => ds.name)\n\n // Prompt for dataset in interactive mode if not provided\n if (!datasetName && !this.isUnattended()) {\n const wantsDataset = await confirm({\n default: true,\n message: 'Would you like to create a dataset?',\n })\n\n if (wantsDataset) {\n const defaultConfig = await promptForDefaultConfig()\n\n datasetName = defaultConfig\n ? 'production'\n : await promptForDatasetName({}, existingDatasetNames)\n }\n }\n\n // Create dataset if we have a name\n if (datasetName) {\n const projectFeatures = await getProjectFeatures(projectId)\n return await createDataset({\n datasetName,\n isUnattended: this.isUnattended(),\n output: this.output,\n projectFeatures,\n projectId,\n silent: this.flags.json,\n visibility: datasetVisibility,\n })\n }\n\n return\n } catch (error) {\n debug(`Error creating dataset: ${error}`)\n this.output.warn(`Project created but dataset creation failed: ${error}`)\n return\n }\n }\n\n private async printProjectCreationSuccess(\n organization: OrganizationCreateResponse | ProjectOrganization | undefined,\n project: CreateProjectResult,\n dataset: DatasetResponse | undefined,\n ) {\n if (this.flags.json) {\n this.output.log(JSON.stringify(project, null, 2))\n return\n }\n\n this.output.log(`Project created successfully!`)\n this.output.log(`ID: ${project.projectId}`)\n this.output.log(`Name: ${project.displayName}`)\n this.output.log(`Organization: ${organization?.name || 'Personal'}`)\n\n if (dataset) {\n this.output.log(`Dataset: ${dataset.datasetName} (${dataset.aclMode})`)\n }\n\n this.output.log(``)\n this.output.log(`Manage your project: ${getManageUrl(project.projectId)}`)\n }\n}\n"],"names":["Args","Flags","CLIError","subdebug","SanityCommand","confirm","spinner","createDataset","validateDatasetName","getOrganization","getManageUrl","promptForDatasetName","promptForDefaultConfig","promptForProjectName","listDatasets","getProjectFeatures","createProject","getCliUser","debug","CreateProjectCommand","args","projectName","string","description","required","examples","command","flags","dataset","parse","input","datasetNameError","exit","options","json","boolean","default","organization","helpValue","yes","char","hiddenAliases","run","datasetVisibility","user","finalProjectName","isUnattended","organizationId","unattended","chosenOrganization","output","requestedId","error","errorText","spin","start","newProject","displayName","metadata","integration","id","succeed","fail","newDataset","handleDatasetCreation","projectId","printProjectCreationSuccess","datasetFromFlag","datasetName","existingDatasets","existingDatasetNames","map","ds","name","wantsDataset","message","defaultConfig","projectFeatures","silent","visibility","warn","project","log","JSON","stringify","aclMode"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,K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EA;QACF,EAAE,OAAOS,OAAO;YACdlC,MAAM,CAAC,wBAAwB,EAAEkC,OAAO;YACxC,IAAI,CAACF,MAAM,CAAC8B,IAAI,CAAC,CAAC,6CAA6C,EAAE5B,OAAO;YACxE;QACF;IACF;IAEA,MAAcc,4BACZ7B,YAA0E,EAC1E4C,OAA4B,EAC5BrD,OAAoC,EACpC;QACA,IAAI,IAAI,CAACD,KAAK,CAACO,IAAI,EAAE;YACnB,IAAI,CAACgB,MAAM,CAACgC,GAAG,CAACC,KAAKC,SAAS,CAACH,SAAS,MAAM;YAC9C;QACF;QAEA,IAAI,CAAC/B,MAAM,CAACgC,GAAG,CAAC,CAAC,6BAA6B,CAAC;QAC/C,IAAI,CAAChC,MAAM,CAACgC,GAAG,CAAC,CAAC,IAAI,EAAED,QAAQhB,SAAS,EAAE;QAC1C,IAAI,CAACf,MAAM,CAACgC,GAAG,CAAC,CAAC,MAAM,EAAED,QAAQxB,WAAW,EAAE;QAC9C,IAAI,CAACP,MAAM,CAACgC,GAAG,CAAC,CAAC,cAAc,EAAE7C,cAAcoC,QAAQ,YAAY;QAEnE,IAAI7C,SAAS;YACX,IAAI,CAACsB,MAAM,CAACgC,GAAG,CAAC,CAAC,SAAS,EAAEtD,QAAQwC,WAAW,CAAC,EAAE,EAAExC,QAAQyD,OAAO,CAAC,CAAC,CAAC;QACxE;QAEA,IAAI,CAACnC,MAAM,CAACgC,GAAG,CAAC,EAAE;QAClB,IAAI,CAAChC,MAAM,CAACgC,GAAG,CAAC,CAAC,qBAAqB,EAAExE,aAAauE,QAAQhB,SAAS,GAAG;IAC3E;AACF"}
1
+ {"version":3,"sources":["../../../src/commands/projects/create.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {CLIError} from '@oclif/core/errors'\nimport {exitCodes} from '@sanity/cli-core'\nimport {subdebug} from '@sanity/cli-core/debug'\nimport {SanityCommand} from '@sanity/cli-core/SanityCommand'\nimport {confirm, spinner} from '@sanity/cli-core/ux'\nimport {type DatasetResponse} from '@sanity/client'\n\nimport {createDataset} from '../../actions/dataset/create.js'\nimport {validateDatasetName} from '../../actions/dataset/validateDatasetName.js'\nimport {getOrganization} from '../../actions/organizations/getOrganization.js'\nimport {getManageUrl} from '../../actions/projects/getManageUrl.js'\nimport {promptForDatasetName} from '../../prompts/promptForDatasetName.js'\nimport {promptForDefaultConfig} from '../../prompts/promptForDefaultConfig.js'\nimport {promptForProjectName} from '../../prompts/promptForProjectName.js'\nimport {listDatasets} from '../../services/datasets.js'\nimport {getProjectFeatures} from '../../services/getProjectFeatures.js'\nimport {\n type OrganizationCreateResponse,\n type ProjectOrganization,\n} from '../../services/organizations.js'\nimport {createProject, type CreateProjectResult} from '../../services/projects.js'\nimport {getCliUser} from '../../services/user.js'\n\nconst debug = subdebug('projects:create')\n\nexport class CreateProjectCommand extends SanityCommand<typeof CreateProjectCommand> {\n static override args = {\n projectName: Args.string({\n description: 'Name of the project to create',\n required: false,\n }),\n }\n\n static override description = 'Create a new Sanity project'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Interactively create a project',\n },\n {\n command: '<%= config.bin %> <%= command.id %> \"My New Project\"',\n description: 'Create a project named \"My New Project\"',\n },\n {\n command: '<%= config.bin %> <%= command.id %> \"My Project\" --organization=my-org',\n description: 'Create a project in a specific organization',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> \"My Project\" --dataset=staging --dataset-visibility=private',\n description: 'Create a project with a private dataset named \"staging\"',\n },\n {\n command: '<%= config.bin %> <%= command.id %> \"CI Project\" --yes --json',\n description: 'Create a project non-interactively with JSON output',\n },\n ]\n\n static override flags = {\n dataset: Flags.string({\n description: 'Create a dataset. Prompts for visibility unless specified or --yes used',\n parse: async (input) => {\n const datasetNameError = validateDatasetName(input)\n if (datasetNameError) {\n throw new CLIError(datasetNameError, {exit: exitCodes.USAGE_ERROR})\n }\n\n return input\n },\n }),\n 'dataset-visibility': Flags.string({\n description: 'Dataset visibility: public or private',\n options: ['private', 'public'],\n }),\n json: Flags.boolean({\n default: false,\n description: 'Output in JSON format',\n }),\n organization: Flags.string({\n description: 'Organization to create the project in',\n helpValue: '<slug|id>',\n }),\n yes: Flags.boolean({\n char: 'y',\n default: false,\n description:\n 'Skip prompts and use defaults (project: \"My Sanity Project\", dataset: production, visibility: public)',\n }),\n }\n\n static override hiddenAliases: string[] = ['project:create']\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(CreateProjectCommand)\n const {projectName} = args\n const {dataset, 'dataset-visibility': datasetVisibility, organization, yes} = flags\n const user = await getCliUser()\n\n const finalProjectName =\n projectName ||\n (yes || this.isUnattended() ? 'My Sanity Project' : await promptForProjectName())\n\n debug('Creating project with options: %O', {\n dataset,\n datasetVisibility,\n organizationId: organization,\n projectName,\n unattended: yes,\n })\n\n let chosenOrganization: OrganizationCreateResponse | ProjectOrganization | undefined\n try {\n chosenOrganization = await getOrganization({\n isUnattended: this.isUnattended(),\n output: this.output,\n requestedId: organization,\n user,\n })\n } catch (error) {\n const errorText = organization\n ? `Failed to retrieve organization ${organization}`\n : 'Failed to retrieve an organization'\n return this.output.error(`${errorText}: ${error}`, {exit: 1})\n }\n\n const spin = spinner('Creating project').start()\n let newProject\n try {\n newProject = await createProject({\n displayName: finalProjectName,\n metadata: {\n integration: 'cli',\n },\n organizationId: chosenOrganization?.id,\n })\n spin.succeed('Project created successfully')\n } catch (error) {\n spin.fail()\n debug(`Failed to create project: ${error}`)\n return this.output.error(`Failed to create project: ${error}`, {exit: 1})\n }\n\n let newDataset: DatasetResponse | undefined\n // If dataset name specified, or in attended mode (to prompt for dataset name), create a dataset.\n if (dataset || !this.isUnattended()) {\n newDataset = await this.handleDatasetCreation(\n newProject.projectId,\n dataset,\n datasetVisibility,\n )\n }\n\n this.printProjectCreationSuccess(chosenOrganization, newProject, newDataset)\n }\n\n private async handleDatasetCreation(\n projectId: string,\n datasetFromFlag?: string,\n datasetVisibility?: string,\n ): Promise<DatasetResponse | undefined> {\n try {\n let datasetName: string | undefined = datasetFromFlag\n const existingDatasets = await listDatasets(projectId)\n const existingDatasetNames = existingDatasets.map((ds) => ds.name)\n\n // Prompt for dataset in interactive mode if not provided\n if (!datasetName && !this.isUnattended()) {\n const wantsDataset = await confirm({\n default: true,\n message: 'Would you like to create a dataset?',\n })\n\n if (wantsDataset) {\n const defaultConfig = await promptForDefaultConfig()\n\n datasetName = defaultConfig\n ? 'production'\n : await promptForDatasetName({}, existingDatasetNames)\n }\n }\n\n // Create dataset if we have a name\n if (datasetName) {\n const projectFeatures = await getProjectFeatures(projectId)\n return await createDataset({\n datasetName,\n isUnattended: this.isUnattended(),\n output: this.output,\n projectFeatures,\n projectId,\n silent: this.flags.json,\n visibility: datasetVisibility,\n })\n }\n\n return\n } catch (error) {\n debug(`Error creating dataset: ${error}`)\n this.output.warn(`Project created but dataset creation failed: ${error}`)\n return\n }\n }\n\n private async printProjectCreationSuccess(\n organization: OrganizationCreateResponse | ProjectOrganization | undefined,\n project: CreateProjectResult,\n dataset: DatasetResponse | undefined,\n ) {\n if (this.flags.json) {\n this.output.log(JSON.stringify(project, null, 2))\n return\n }\n\n this.output.log(`Project created successfully!`)\n this.output.log(`ID: ${project.projectId}`)\n this.output.log(`Name: ${project.displayName}`)\n this.output.log(`Organization: ${organization?.name || 'Personal'}`)\n\n if (dataset) {\n this.output.log(`Dataset: ${dataset.datasetName} (${dataset.aclMode})`)\n }\n\n this.output.log(``)\n this.output.log(`Manage your project: ${getManageUrl(project.projectId)}`)\n }\n}\n"],"names":["Args","Flags","CLIError","exitCodes","subdebug","SanityCommand","confirm","spinner","createDataset","validateDatasetName","getOrganization","getManageUrl","promptForDatasetName","promptForDefaultConfig","promptForProjectName","listDatasets","getProjectFeatures","createProject","getCliUser","debug","CreateProjectCommand","args","projectName","string","description","required","examples","command","flags","dataset","parse","input","datasetNameError","exit","USAGE_ERROR","options","json","boolean","default","organization","helpValue","yes","char","hiddenAliases","run","datasetVisibility","user","finalProjectName","isUnattended","organizationId","unattended","chosenOrganization","output","requestedId","error","errorText","spin","start","newProject","displayName","metadata","integration","id","succeed","fail","newDataset","handleDatasetCreation","projectId","printProjectCreationSuccess","datasetFromFlag","datasetName","existingDatasets","existingDatasetNames","map","ds","name","wantsDataset","message","defaultConfig","projectFeatures","silent","visibility","warn","project","log","JSON","stringify","aclMode"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,QAAQ,QAAO,qBAAoB;AAC3C,SAAQC,SAAS,QAAO,mBAAkB;AAC1C,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,aAAa,QAAO,iCAAgC;AAC5D,SAAQC,OAAO,EAAEC,OAAO,QAAO,sBAAqB;AAGpD,SAAQC,aAAa,QAAO,kCAAiC;AAC7D,SAAQC,mBAAmB,QAAO,+CAA8C;AAChF,SAAQC,eAAe,QAAO,iDAAgD;AAC9E,SAAQC,YAAY,QAAO,yCAAwC;AACnE,SAAQC,oBAAoB,QAAO,wCAAuC;AAC1E,SAAQC,sBAAsB,QAAO,0CAAyC;AAC9E,SAAQC,oBAAoB,QAAO,wCAAuC;AAC1E,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAAQC,kBAAkB,QAAO,uCAAsC;AAKvE,SAAQC,aAAa,QAAiC,6BAA4B;AAClF,SAAQC,UAAU,QAAO,yBAAwB;AAEjD,MAAMC,QAAQf,SAAS;AAEvB,OAAO,MAAMgB,6BAA6Bf;IACxC,OAAgBgB,OAAO;QACrBC,aAAatB,KAAKuB,MAAM,CAAC;YACvBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,8BAA6B;IAE3D,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAA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,CAAC,qBAAqB,EAAEzE,aAAawE,QAAQhB,SAAS,GAAG;IAC3E;AACF"}
@@ -1,6 +1,7 @@
1
1
  import { Flags } from '@oclif/core';
2
2
  import { CLIError } from '@oclif/core/errors';
3
- import { SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
4
+ import { confirm } from '@sanity/cli-core/ux';
4
5
  import { deleteSchemaAction } from '../../actions/schema/deleteSchemaAction.js';
5
6
  import { parseIds } from '../../actions/schema/utils/schemaStoreValidation.js';
6
7
  import { promptForProject } from '../../prompts/promptForProject.js';
@@ -45,6 +46,11 @@ export class DeleteSchemaCommand extends SanityCommand {
45
46
  verbose: Flags.boolean({
46
47
  default: false,
47
48
  description: 'Enable verbose logging'
49
+ }),
50
+ yes: Flags.boolean({
51
+ char: 'y',
52
+ default: false,
53
+ description: 'Delete schemas without prompting for confirmation'
48
54
  })
49
55
  };
50
56
  static hiddenAliases = [
@@ -52,9 +58,24 @@ export class DeleteSchemaCommand extends SanityCommand {
52
58
  ];
53
59
  async run() {
54
60
  const { flags } = await this.parse(DeleteSchemaCommand);
55
- const { dataset } = flags;
61
+ const { dataset, yes } = flags;
56
62
  deleteSchemaDebug('Running schema delete with flags: %O', flags);
57
63
  const ids = parseIds(flags.ids);
64
+ if (!yes && this.isUnattended()) {
65
+ this.error('Schema deletion requires confirmation. Pass `--yes` to delete the schemas.', {
66
+ exit: exitCodes.USAGE_ERROR
67
+ });
68
+ }
69
+ if (!yes) {
70
+ const confirmed = await confirm({
71
+ default: false,
72
+ message: `Delete ${ids.length} schema${ids.length === 1 ? '' : 's'}?`
73
+ });
74
+ if (!confirmed) {
75
+ this.log('Schema deletion cancelled');
76
+ this.exit(exitCodes.USER_ABORT);
77
+ }
78
+ }
58
79
  try {
59
80
  const workDir = await this.getProjectRoot();
60
81
  const projectId = await this.getProjectId({