@sanity/cli 7.5.0 → 7.7.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 (69) hide show
  1. package/README.md +6 -2
  2. package/dist/actions/build/buildApp.js +7 -183
  3. package/dist/actions/build/buildApp.js.map +1 -1
  4. package/dist/actions/build/buildStudio.js +6 -213
  5. package/dist/actions/build/buildStudio.js.map +1 -1
  6. package/dist/actions/build/shouldAutoUpdate.js +100 -22
  7. package/dist/actions/build/shouldAutoUpdate.js.map +1 -1
  8. package/dist/actions/deploy/{createStudioUserApplication.js → createUserApplication.js} +56 -5
  9. package/dist/actions/deploy/createUserApplication.js.map +1 -0
  10. package/dist/actions/deploy/deployApp.js +253 -183
  11. package/dist/actions/deploy/deployApp.js.map +1 -1
  12. package/dist/actions/deploy/deployChecks.js +284 -0
  13. package/dist/actions/deploy/deployChecks.js.map +1 -0
  14. package/dist/actions/deploy/deployRunner.js +78 -0
  15. package/dist/actions/deploy/deployRunner.js.map +1 -0
  16. package/dist/actions/deploy/deployStudio.js +200 -197
  17. package/dist/actions/deploy/deployStudio.js.map +1 -1
  18. package/dist/actions/deploy/deployStudioSchemasAndManifests.js +2 -3
  19. package/dist/actions/deploy/deployStudioSchemasAndManifests.js.map +1 -1
  20. package/dist/actions/deploy/deploymentPlan.js +117 -0
  21. package/dist/actions/deploy/deploymentPlan.js.map +1 -0
  22. package/dist/actions/deploy/findUserApplication.js +209 -0
  23. package/dist/actions/deploy/findUserApplication.js.map +1 -0
  24. package/dist/actions/deploy/resolveDeployTarget.js +185 -0
  25. package/dist/actions/deploy/resolveDeployTarget.js.map +1 -0
  26. package/dist/actions/deploy/urlUtils.js +4 -0
  27. package/dist/actions/deploy/urlUtils.js.map +1 -1
  28. package/dist/actions/dev/devAction.js +1 -1
  29. package/dist/actions/dev/devAction.js.map +1 -1
  30. package/dist/actions/dev/servers/getDevServerConfig.js +18 -6
  31. package/dist/actions/dev/servers/getDevServerConfig.js.map +1 -1
  32. package/dist/actions/dev/servers/startAppDevServer.js +1 -1
  33. package/dist/actions/dev/servers/startAppDevServer.js.map +1 -1
  34. package/dist/actions/dev/servers/startStudioDevServer.js +2 -1
  35. package/dist/actions/dev/servers/startStudioDevServer.js.map +1 -1
  36. package/dist/actions/manifest/extractCoreAppManifest.js +15 -1
  37. package/dist/actions/manifest/extractCoreAppManifest.js.map +1 -1
  38. package/dist/commands/deploy.js +31 -12
  39. package/dist/commands/deploy.js.map +1 -1
  40. package/dist/commands/dev.js +2 -1
  41. package/dist/commands/dev.js.map +1 -1
  42. package/dist/commands/init.js +2 -1
  43. package/dist/commands/init.js.map +1 -1
  44. package/dist/exports/index.d.ts +9 -0
  45. package/dist/exports/index.js +1 -8
  46. package/dist/exports/index.js.map +1 -1
  47. package/dist/server/devServer.js +27 -3
  48. package/dist/server/devServer.js.map +1 -1
  49. package/dist/services/userApplications.js.map +1 -1
  50. package/dist/util/appId.js +13 -5
  51. package/dist/util/appId.js.map +1 -1
  52. package/dist/util/compareDependencyVersions.js.map +1 -1
  53. package/dist/util/determineIsApp.js +1 -1
  54. package/dist/util/determineIsApp.js.map +1 -1
  55. package/dist/util/errorMessages.js +2 -0
  56. package/dist/util/errorMessages.js.map +1 -1
  57. package/oclif.manifest.json +223 -203
  58. package/package.json +8 -8
  59. package/dist/actions/build/handlePrereleaseVersions.js +0 -44
  60. package/dist/actions/build/handlePrereleaseVersions.js.map +0 -1
  61. package/dist/actions/deploy/createStudioUserApplication.js.map +0 -1
  62. package/dist/actions/deploy/createUserApplicationForApp.js +0 -56
  63. package/dist/actions/deploy/createUserApplicationForApp.js.map +0 -1
  64. package/dist/actions/deploy/findUserApplicationForApp.js +0 -111
  65. package/dist/actions/deploy/findUserApplicationForApp.js.map +0 -1
  66. package/dist/actions/deploy/findUserApplicationForStudio.js +0 -172
  67. package/dist/actions/deploy/findUserApplicationForStudio.js.map +0 -1
  68. package/dist/actions/deploy/viewDeployment.js +0 -32
  69. package/dist/actions/deploy/viewDeployment.js.map +0 -1
@@ -1,105 +1,69 @@
1
1
  import { basename, dirname } from 'node:path';
2
2
  import { styleText } from 'node:util';
3
3
  import { createGzip } from 'node:zlib';
4
- import { CLIError } from '@oclif/core/errors';
5
4
  import { formatSchemaValidation, SchemaExtractionError } from '@sanity/cli-build/_internal/extract';
6
- import { exitCodes, getLocalPackageVersion } from '@sanity/cli-core';
5
+ import { exitCodes } from '@sanity/cli-core';
7
6
  import { spinner } from '@sanity/cli-core/ux';
8
7
  import { getWorkbench } from '@sanity/workbench-cli/deploy';
9
8
  import { pack } from 'tar-fs';
10
9
  import { createDeployment } from '../../services/userApplications.js';
11
10
  import { getAppId } from '../../util/appId.js';
12
11
  import { NO_PROJECT_ID } from '../../util/errorMessages.js';
13
- import { getErrorMessage } from '../../util/getErrorMessage.js';
14
12
  import { buildStudio } from '../build/buildStudio.js';
15
- import { shouldAutoUpdate } from '../build/shouldAutoUpdate.js';
16
- import { checkDir } from './checkDir.js';
17
- import { createStudioUserApplication } from './createStudioUserApplication.js';
13
+ import { createStudioUserApplication } from './createUserApplication.js';
14
+ import { checkAutoUpdates, checkBuild, checkPackageVersion, checkStudioTarget, verifyOutputDir } from './deployChecks.js';
18
15
  import { deployDebug } from './deployDebug.js';
16
+ import { listDeploymentFiles } from './deploymentPlan.js';
17
+ import { runDeploy } from './deployRunner.js';
19
18
  import { deployStudioSchemasAndManifests } from './deployStudioSchemasAndManifests.js';
20
- import { findUserApplicationForStudio } from './findUserApplicationForStudio.js';
21
- import { normalizeUrl, validateUrl } from './urlUtils.js';
22
- export async function deployStudio(options) {
23
- const { cliConfig, flags, output, projectRoot, sourceDir } = options;
24
- const workbench = getWorkbench(cliConfig);
25
- const workDir = projectRoot.directory;
26
- const configPath = projectRoot.path;
27
- const appId = getAppId(cliConfig);
19
+ import { findUserApplicationForStudio } from './findUserApplication.js';
20
+ const STUDIO_PACKAGE = 'sanity';
21
+ export function deployStudio(options) {
22
+ return runDeploy(options, {
23
+ listFiles: ({ flags, projectRoot, sourceDir })=>flags.external ? Promise.resolve([]) : listDeploymentFiles(sourceDir, projectRoot.directory),
24
+ run: runStudioDeployment,
25
+ type: 'studio'
26
+ });
27
+ }
28
+ /** Validates the deploy, extracts and uploads the schema, and ships the build. */ async function runStudioDeployment(options, reporter) {
29
+ const { cliConfig, flags, output, sourceDir } = options;
30
+ const workDir = options.projectRoot.directory;
31
+ const isExternal = !!flags.external;
32
+ const isWorkbenchApp = getWorkbench(cliConfig) !== null;
28
33
  const projectId = cliConfig.api?.projectId;
29
- const installedSanityVersion = await getLocalPackageVersion('sanity', workDir);
30
- const isAutoUpdating = shouldAutoUpdate({
34
+ const dryRun = !!flags['dry-run'];
35
+ const isAutoUpdating = checkAutoUpdates(reporter, {
31
36
  cliConfig,
32
- flags,
33
- output
37
+ flags
34
38
  });
35
- const isExternal = !!flags.external;
36
- const urlType = isExternal ? 'external' : 'internal';
37
- // Federated (`unstable_defineApp`) applications integrate through Sanity's
38
- // build and hosting pipeline, which `--external` skips. Fail before any
39
- // prompts or API calls.
40
- if (isExternal && workbench) {
41
- output.error('Deploying a federated application to an external host is not yet supported. ' + 'Remove the `--external` flag to deploy to Sanity hosting.', {
42
- exit: exitCodes.USAGE_ERROR
39
+ if (isExternal && isWorkbenchApp) {
40
+ // A federated app deploys through Sanity's build/hosting pipeline, which
41
+ // --external skips.
42
+ reporter.report({
43
+ exitCode: exitCodes.USAGE_ERROR,
44
+ message: 'Deploying a federated application to an external host is not yet supported',
45
+ solution: 'Remove the --external flag to deploy to Sanity hosting',
46
+ status: 'fail'
43
47
  });
44
- return;
45
48
  }
46
- // Resolve the app host from --url flag (takes precedence) or studioHost config
47
- const appHost = resolveAppHost({
48
- flags,
49
- isExternal,
50
- output,
51
- studioHost: cliConfig.studioHost
49
+ const version = await checkPackageVersion(reporter, {
50
+ moduleName: STUDIO_PACKAGE,
51
+ workDir
52
52
  });
53
- if (!installedSanityVersion) {
54
- output.error(`Failed to find installed sanity version`, {
55
- exit: 1
56
- });
57
- return;
58
- }
59
- if (!projectId) {
60
- output.error(NO_PROJECT_ID, {
61
- exit: 1
62
- });
63
- return;
64
- }
65
- let spin = spinner('Verifying local content');
66
- try {
67
- let userApplication = await findUserApplicationForStudio({
68
- appHost,
69
- appId,
70
- output,
71
- projectId,
72
- unattended: !!flags.yes,
73
- urlType
74
- });
75
- if (!userApplication) {
76
- if (flags.yes) {
77
- const flagHint = isExternal ? 'Use --url to specify the external studio URL' : 'Use --url to specify the studio hostname';
78
- output.error(`Cannot prompt for ${isExternal ? 'external studio URL' : 'studio hostname'} in unattended mode. ${flagHint}.`, {
79
- exit: exitCodes.USAGE_ERROR
80
- });
81
- return;
82
- }
83
- if (isExternal) {
84
- output.log('Your project has not been registered with an external studio URL.');
85
- output.log('Please enter the full URL where your studio is hosted.');
86
- } else {
87
- output.log('Your project has not been assigned a studio hostname.');
88
- output.log('To deploy your Sanity Studio to our hosted sanity.studio service,');
89
- output.log('you will need one. Please enter the subdomain you want to use.');
90
- }
91
- userApplication = await createStudioUserApplication({
92
- projectId,
93
- urlType
94
- });
95
- deployDebug('Created user application', userApplication);
96
- }
97
- deployDebug('Found user application', userApplication);
98
- // Always build the project, unless --no-build is passed or --external is passed
99
- const shouldBuild = flags.build && !isExternal;
100
- if (shouldBuild) {
101
- deployDebug(`Building studio`);
102
- await buildStudio({
53
+ reporter.report(projectId ? {
54
+ message: `Project: ${projectId}`,
55
+ status: 'pass'
56
+ } : {
57
+ message: NO_PROJECT_ID,
58
+ solution: 'Add `api.projectId` to sanity.cli.ts',
59
+ status: 'fail'
60
+ });
61
+ const application = await resolveStudioApplication(options, {
62
+ dryRun,
63
+ reporter
64
+ });
65
+ await checkBuild(reporter, {
66
+ build: ()=>buildStudio({
103
67
  autoUpdatesEnabled: isAutoUpdating,
104
68
  calledFromDeploy: true,
105
69
  cliConfig,
@@ -107,136 +71,175 @@ export async function deployStudio(options) {
107
71
  outDir: sourceDir,
108
72
  output,
109
73
  workDir
110
- });
74
+ }),
75
+ skipReason: studioBuildSkipReason({
76
+ build: flags.build,
77
+ isExternal
78
+ }),
79
+ successMessage: 'Studio built'
80
+ });
81
+ if (!isExternal) {
82
+ await verifyOutputDir({
83
+ isWorkbenchApp,
84
+ reporter,
85
+ sourceDir
86
+ });
87
+ }
88
+ // Dry run stops here — everything below mutates.
89
+ if (dryRun) return;
90
+ // A real deploy has already exited if anything failed; landing here without a
91
+ // resolved application or version means the deploy target was never resolved.
92
+ if (!application || !version) return;
93
+ const studioManifest = await uploadStudioSchema(options, {
94
+ isExternal
95
+ });
96
+ const location = await shipStudioDeployment({
97
+ application,
98
+ isAutoUpdating,
99
+ isExternal,
100
+ options,
101
+ studioManifest,
102
+ version
103
+ });
104
+ return {
105
+ applicationType: 'studio',
106
+ applicationVersion: version,
107
+ target: {
108
+ applicationId: application.id,
109
+ title: application.title ?? null,
110
+ url: location
111
111
  }
112
- let studioManifest = null;
113
- try {
114
- studioManifest = await deployStudioSchemasAndManifests({
115
- configPath,
116
- isExternal,
117
- outPath: `${sourceDir}/static`,
118
- projectId,
119
- schemaRequired: flags['schema-required'],
120
- verbose: flags.verbose,
121
- workDir
122
- });
123
- } catch (error) {
124
- deployDebug('Error deploying studio schemas and manifests', error);
125
- if (error instanceof SchemaExtractionError) {
126
- output.error(formatSchemaValidation(error.validation || []), {
127
- exit: 1
128
- });
129
- }
130
- output.error(`Error deploying studio schemas and manifests: ${error}`, {
131
- exit: 1
132
- });
112
+ };
113
+ }
114
+ /**
115
+ * Finds the application a real deploy targets, registering a studio host when
116
+ * none is configured. A dry run resolves and reports the target read-only instead.
117
+ */ async function resolveStudioApplication(options, { dryRun, reporter }) {
118
+ const { cliConfig, flags, output } = options;
119
+ const isExternal = !!flags.external;
120
+ // Sets the title on a newly registered studio; blank falls back to undefined
121
+ const title = flags.title?.trim() || undefined;
122
+ if (dryRun) {
123
+ await checkStudioTarget(reporter, {
124
+ appId: getAppId(cliConfig),
125
+ isExternal,
126
+ projectId: cliConfig.api?.projectId,
127
+ studioHost: cliConfig.studioHost,
128
+ title,
129
+ urlFlag: flags.url
130
+ });
131
+ return null;
132
+ }
133
+ const projectId = cliConfig.api?.projectId ?? '';
134
+ let application = await findUserApplicationForStudio({
135
+ appId: getAppId(cliConfig),
136
+ isExternal,
137
+ output,
138
+ projectId,
139
+ studioHost: cliConfig.studioHost,
140
+ title,
141
+ unattended: !!flags.yes,
142
+ urlFlag: flags.url
143
+ });
144
+ if (!application) {
145
+ if (isExternal) {
146
+ output.log('Your project has not been registered with an external studio URL.');
147
+ output.log('Please enter the full URL where your studio is hosted.');
148
+ } else {
149
+ output.log('Your project has not been assigned a studio hostname.');
150
+ output.log('To deploy your Sanity Studio to our hosted sanity.studio service,');
151
+ output.log('you will need one. Please enter the subdomain you want to use.');
133
152
  }
134
- if (!studioManifest) {
135
- output.error('Failed to generate studio manifest. Please check your schemas and manifests.', {
153
+ application = await createStudioUserApplication({
154
+ projectId,
155
+ title,
156
+ urlType: isExternal ? 'external' : 'internal'
157
+ });
158
+ deployDebug('Created user application', application);
159
+ }
160
+ deployDebug('Found user application', application);
161
+ return application;
162
+ }
163
+ /** Extracts the studio schema and manifest and uploads them to the schema store. */ async function uploadStudioSchema(options, { isExternal }) {
164
+ const { cliConfig, flags, output, projectRoot, sourceDir } = options;
165
+ let studioManifest = null;
166
+ try {
167
+ studioManifest = await deployStudioSchemasAndManifests({
168
+ configPath: projectRoot.path,
169
+ isExternal,
170
+ outPath: `${sourceDir}/static`,
171
+ projectId: cliConfig.api?.projectId ?? '',
172
+ schemaRequired: flags['schema-required'],
173
+ verbose: flags.verbose,
174
+ workDir: projectRoot.directory
175
+ }, output);
176
+ } catch (error) {
177
+ deployDebug('Error deploying studio schemas and manifests', error);
178
+ if (error instanceof SchemaExtractionError) {
179
+ output.error(formatSchemaValidation(error.validation || []), {
136
180
  exit: 1
137
181
  });
138
182
  }
139
- let tarball;
140
- if (!isExternal) {
141
- // Ensure that the directory exists, is a directory and seems to have valid content
142
- spin = spin.start();
143
- try {
144
- await (workbench ? workbench.checkBuiltOutput(sourceDir) : checkDir(sourceDir));
145
- spin.succeed();
146
- } catch (err) {
147
- spin.fail();
148
- deployDebug('Error checking directory', err);
149
- output.error(getErrorMessage(err), {
150
- exit: 1
151
- });
152
- }
153
- // Create a tarball of the given directory
154
- const parentDir = dirname(sourceDir);
155
- const base = basename(sourceDir);
156
- tarball = pack(parentDir, {
157
- entries: [
158
- base
159
- ]
160
- }).pipe(createGzip());
161
- }
162
- spin = spinner(isExternal ? 'Registering studio' : 'Deploying to sanity.studio').start();
163
- const { location } = await createDeployment({
164
- applicationId: userApplication.id,
183
+ output.error(`Error deploying studio schemas and manifests: ${error}`, {
184
+ exit: 1
185
+ });
186
+ }
187
+ if (!studioManifest) {
188
+ output.error('Failed to generate studio manifest. Please check your schemas and manifests.', {
189
+ exit: 1
190
+ });
191
+ }
192
+ return studioManifest;
193
+ }
194
+ async function shipStudioDeployment({ application, isAutoUpdating, isExternal, options, studioManifest, version }) {
195
+ const { cliConfig, output, sourceDir } = options;
196
+ let tarball;
197
+ if (!isExternal) {
198
+ tarball = pack(dirname(sourceDir), {
199
+ entries: [
200
+ basename(sourceDir)
201
+ ]
202
+ }).pipe(createGzip());
203
+ }
204
+ const spin = spinner(isExternal ? 'Registering studio' : 'Deploying to sanity.studio').start();
205
+ let location;
206
+ try {
207
+ ;
208
+ ({ location } = await createDeployment({
209
+ applicationId: application.id,
165
210
  isApp: false,
166
211
  isAutoUpdating,
167
212
  manifest: studioManifest,
168
- projectId,
213
+ projectId: cliConfig.api?.projectId,
169
214
  tarball,
170
- version: installedSanityVersion
171
- });
172
- spin.succeed();
173
- if (isExternal) {
174
- output.log(`\nSuccess! Studio registered`);
175
- } else {
176
- output.log(`\nSuccess! Studio deployed to ${styleText('cyan', location)}`);
177
- }
178
- if (!appId) {
179
- const example = `Example:
215
+ version
216
+ }));
217
+ } catch (error) {
218
+ spin.fail();
219
+ throw error;
220
+ }
221
+ spin.succeed();
222
+ const named = application.title ? ` — "${application.title}"` : '';
223
+ output.log(isExternal ? `\nSuccess! Studio registered${named}` : `\nSuccess! Studio deployed to ${styleText('cyan', location)}${named}`);
224
+ if (getAppId(cliConfig)) return location;
225
+ const example = `Example:
180
226
  export default defineCliConfig({
181
227
  //…
182
228
  deployment: {
183
- ${styleText('cyan', `appId: '${userApplication.id}'`)},
229
+ ${styleText('cyan', `appId: '${application.id}'`)},
184
230
  },
185
231
  //…
186
232
  })`;
187
- output.log(`\nAdd ${styleText('cyan', `appId: '${userApplication.id}'`)}`);
188
- output.log(`to the \`deployment\` section in sanity.cli.js or sanity.cli.ts`);
189
- output.log(`to avoid prompting for application id on next deploy.`);
190
- output.log(`\n${example}`);
191
- }
192
- } catch (error) {
193
- // if the error is a CLIError, we can just output the message and preserve its exit code
194
- if (error instanceof CLIError) {
195
- output.error(error.message, {
196
- exit: error.oclif?.exit ?? exitCodes.RUNTIME_ERROR
197
- });
198
- return;
199
- }
200
- spin.fail();
201
- deployDebug('Error deploying studio', error);
202
- output.error(`Error deploying studio: ${error}`, {
203
- exit: 1
204
- });
205
- }
233
+ output.log(`\nAdd ${styleText('cyan', `appId: '${application.id}'`)}`);
234
+ output.log(`to the \`deployment\` section in sanity.cli.js or sanity.cli.ts`);
235
+ output.log(`to avoid prompting for application id on next deploy.`);
236
+ output.log(`\n${example}`);
237
+ return location;
206
238
  }
207
- function resolveAppHost({ flags, isExternal, output, studioHost }) {
208
- const url = flags.url;
209
- if (!url) {
210
- return studioHost;
211
- }
212
- if (isExternal) {
213
- const normalized = normalizeUrl(url);
214
- const validation = validateUrl(normalized);
215
- if (validation !== true) {
216
- output.error(validation, {
217
- exit: exitCodes.USAGE_ERROR
218
- });
219
- return undefined;
220
- }
221
- return normalized;
222
- }
223
- // For internal deploys, strip protocol prefix and .sanity.studio suffix if present
224
- const hostname = url.replace(/^https?:\/\//i, '').replace(/\.sanity\.studio\/?$/i, '');
225
- // If the result still looks like a URL (contains dots), the user likely meant --external
226
- if (hostname.includes('.')) {
227
- output.error(`"${hostname}" does not look like a sanity.studio hostname. Did you mean to use --external?`, {
228
- exit: exitCodes.USAGE_ERROR
229
- });
230
- return undefined;
231
- }
232
- // Validate hostname characters (alphanumeric and hyphens only)
233
- if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(hostname)) {
234
- output.error(`Invalid studio hostname "${hostname}". Hostnames can only contain letters, numbers, and hyphens.`, {
235
- exit: exitCodes.USAGE_ERROR
236
- });
237
- return undefined;
238
- }
239
- return hostname;
239
+ function studioBuildSkipReason({ build, isExternal }) {
240
+ if (isExternal) return 'Build skipped for externally hosted studios';
241
+ if (!build) return 'Build skipped (--no-build) — validating existing output directory';
242
+ return;
240
243
  }
241
244
 
242
245
  //# sourceMappingURL=deployStudio.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/deploy/deployStudio.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {styleText} from 'node:util'\nimport {createGzip, type Gzip} from 'node:zlib'\n\nimport {CLIError} from '@oclif/core/errors'\nimport {formatSchemaValidation, SchemaExtractionError} from '@sanity/cli-build/_internal/extract'\nimport {exitCodes, getLocalPackageVersion, type Output} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {getWorkbench} from '@sanity/workbench-cli/deploy'\nimport {type StudioManifest} from 'sanity'\nimport {pack} from 'tar-fs'\n\nimport {createDeployment} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {NO_PROJECT_ID} from '../../util/errorMessages.js'\nimport {getErrorMessage} from '../../util/getErrorMessage.js'\nimport {buildStudio} from '../build/buildStudio.js'\nimport {shouldAutoUpdate} from '../build/shouldAutoUpdate.js'\nimport {checkDir} from './checkDir.js'\nimport {createStudioUserApplication} from './createStudioUserApplication.js'\nimport {deployDebug} from './deployDebug.js'\nimport {deployStudioSchemasAndManifests} from './deployStudioSchemasAndManifests.js'\nimport {findUserApplicationForStudio} from './findUserApplicationForStudio.js'\nimport {type DeployAppOptions} from './types.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\nexport async function deployStudio(options: DeployAppOptions) {\n const {cliConfig, flags, output, projectRoot, sourceDir} = options\n const workbench = getWorkbench(cliConfig)\n\n const workDir = projectRoot.directory\n const configPath = projectRoot.path\n\n const appId = getAppId(cliConfig)\n const projectId = cliConfig.api?.projectId\n const installedSanityVersion = await getLocalPackageVersion('sanity', workDir)\n const isAutoUpdating = shouldAutoUpdate({cliConfig, flags, output})\n\n const isExternal = !!flags.external\n const urlType: 'external' | 'internal' = isExternal ? 'external' : 'internal'\n\n // Federated (`unstable_defineApp`) applications integrate through Sanity's\n // build and hosting pipeline, which `--external` skips. Fail before any\n // prompts or API calls.\n if (isExternal && workbench) {\n output.error(\n 'Deploying a federated application to an external host is not yet supported. ' +\n 'Remove the `--external` flag to deploy to Sanity hosting.',\n {exit: exitCodes.USAGE_ERROR},\n )\n return\n }\n\n // Resolve the app host from --url flag (takes precedence) or studioHost config\n const appHost = resolveAppHost({flags, isExternal, output, studioHost: cliConfig.studioHost})\n\n if (!installedSanityVersion) {\n output.error(`Failed to find installed sanity version`, {exit: 1})\n return\n }\n\n if (!projectId) {\n output.error(NO_PROJECT_ID, {exit: 1})\n return\n }\n\n let spin = spinner('Verifying local content')\n\n try {\n let userApplication = await findUserApplicationForStudio({\n appHost,\n appId,\n output,\n projectId,\n unattended: !!flags.yes,\n urlType,\n })\n\n if (!userApplication) {\n if (flags.yes) {\n const flagHint = isExternal\n ? 'Use --url to specify the external studio URL'\n : 'Use --url to specify the studio hostname'\n output.error(\n `Cannot prompt for ${isExternal ? 'external studio URL' : 'studio hostname'} in unattended mode. ${flagHint}.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n return\n }\n\n if (isExternal) {\n output.log('Your project has not been registered with an external studio URL.')\n output.log('Please enter the full URL where your studio is hosted.')\n } else {\n output.log('Your project has not been assigned a studio hostname.')\n output.log('To deploy your Sanity Studio to our hosted sanity.studio service,')\n output.log('you will need one. Please enter the subdomain you want to use.')\n }\n\n userApplication = await createStudioUserApplication({projectId, urlType})\n\n deployDebug('Created user application', userApplication)\n }\n\n deployDebug('Found user application', userApplication)\n\n // Always build the project, unless --no-build is passed or --external is passed\n const shouldBuild = flags.build && !isExternal\n if (shouldBuild) {\n deployDebug(`Building studio`)\n await buildStudio({\n autoUpdatesEnabled: isAutoUpdating,\n calledFromDeploy: true,\n cliConfig,\n flags,\n outDir: sourceDir,\n output,\n workDir,\n })\n }\n\n let studioManifest: StudioManifest | null = null\n try {\n studioManifest = await deployStudioSchemasAndManifests({\n configPath,\n isExternal,\n outPath: `${sourceDir}/static`,\n projectId,\n schemaRequired: flags['schema-required'],\n verbose: flags.verbose,\n workDir,\n })\n } catch (error) {\n deployDebug('Error deploying studio schemas and manifests', error)\n if (error instanceof SchemaExtractionError) {\n output.error(formatSchemaValidation(error.validation || []), {exit: 1})\n }\n output.error(`Error deploying studio schemas and manifests: ${error}`, {exit: 1})\n }\n\n if (!studioManifest) {\n output.error('Failed to generate studio manifest. Please check your schemas and manifests.', {\n exit: 1,\n })\n }\n\n let tarball: Gzip | undefined\n\n if (!isExternal) {\n // Ensure that the directory exists, is a directory and seems to have valid content\n spin = spin.start()\n try {\n await (workbench ? workbench.checkBuiltOutput(sourceDir) : checkDir(sourceDir))\n spin.succeed()\n } catch (err) {\n spin.fail()\n deployDebug('Error checking directory', err)\n output.error(getErrorMessage(err), {exit: 1})\n }\n\n // Create a tarball of the given directory\n const parentDir = dirname(sourceDir)\n const base = basename(sourceDir)\n tarball = pack(parentDir, {entries: [base]}).pipe(createGzip())\n }\n\n spin = spinner(isExternal ? 'Registering studio' : 'Deploying to sanity.studio').start()\n\n const {location} = await createDeployment({\n applicationId: userApplication.id,\n isApp: false,\n isAutoUpdating,\n manifest: studioManifest,\n projectId,\n tarball,\n version: installedSanityVersion,\n })\n\n spin.succeed()\n\n if (isExternal) {\n output.log(`\\nSuccess! Studio registered`)\n } else {\n output.log(`\\nSuccess! Studio deployed to ${styleText('cyan', location)}`)\n }\n\n if (!appId) {\n const example = `Example:\nexport default defineCliConfig({\n //…\n deployment: {\n ${styleText('cyan', `appId: '${userApplication.id}'`)},\n },\n //…\n})`\n output.log(`\\nAdd ${styleText('cyan', `appId: '${userApplication.id}'`)}`)\n output.log(`to the \\`deployment\\` section in sanity.cli.js or sanity.cli.ts`)\n output.log(`to avoid prompting for application id on next deploy.`)\n output.log(`\\n${example}`)\n }\n } catch (error) {\n // if the error is a CLIError, we can just output the message and preserve its exit code\n if (error instanceof CLIError) {\n output.error(error.message, {exit: error.oclif?.exit ?? exitCodes.RUNTIME_ERROR})\n return\n }\n\n spin.fail()\n deployDebug('Error deploying studio', error)\n output.error(`Error deploying studio: ${error}`, {exit: 1})\n }\n}\n\nfunction resolveAppHost({\n flags,\n isExternal,\n output,\n studioHost,\n}: {\n flags: DeployAppOptions['flags']\n isExternal: boolean\n output: Output\n studioHost: string | undefined\n}): string | undefined {\n const url = flags.url\n if (!url) {\n return studioHost\n }\n\n if (isExternal) {\n const normalized = normalizeUrl(url)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n output.error(validation, {exit: exitCodes.USAGE_ERROR})\n return undefined\n }\n return normalized\n }\n\n // For internal deploys, strip protocol prefix and .sanity.studio suffix if present\n const hostname = url.replace(/^https?:\\/\\//i, '').replace(/\\.sanity\\.studio\\/?$/i, '')\n\n // If the result still looks like a URL (contains dots), the user likely meant --external\n if (hostname.includes('.')) {\n output.error(\n `\"${hostname}\" does not look like a sanity.studio hostname. Did you mean to use --external?`,\n {exit: exitCodes.USAGE_ERROR},\n )\n return undefined\n }\n\n // Validate hostname characters (alphanumeric and hyphens only)\n if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(hostname)) {\n output.error(\n `Invalid studio hostname \"${hostname}\". Hostnames can only contain letters, numbers, and hyphens.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n return undefined\n }\n\n return hostname\n}\n"],"names":["basename","dirname","styleText","createGzip","CLIError","formatSchemaValidation","SchemaExtractionError","exitCodes","getLocalPackageVersion","spinner","getWorkbench","pack","createDeployment","getAppId","NO_PROJECT_ID","getErrorMessage","buildStudio","shouldAutoUpdate","checkDir","createStudioUserApplication","deployDebug","deployStudioSchemasAndManifests","findUserApplicationForStudio","normalizeUrl","validateUrl","deployStudio","options","cliConfig","flags","output","projectRoot","sourceDir","workbench","workDir","directory","configPath","path","appId","projectId","api","installedSanityVersion","isAutoUpdating","isExternal","external","urlType","error","exit","USAGE_ERROR","appHost","resolveAppHost","studioHost","spin","userApplication","unattended","yes","flagHint","log","shouldBuild","build","autoUpdatesEnabled","calledFromDeploy","outDir","studioManifest","outPath","schemaRequired","verbose","validation","tarball","start","checkBuiltOutput","succeed","err","fail","parentDir","base","entries","pipe","location","applicationId","id","isApp","manifest","version","example","message","oclif","RUNTIME_ERROR","url","normalized","undefined","hostname","replace","includes","test"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,SAAS,QAAO,YAAW;AACnC,SAAQC,UAAU,QAAkB,YAAW;AAE/C,SAAQC,QAAQ,QAAO,qBAAoB;AAC3C,SAAQC,sBAAsB,EAAEC,qBAAqB,QAAO,sCAAqC;AACjG,SAAQC,SAAS,EAAEC,sBAAsB,QAAoB,mBAAkB;AAC/E,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,YAAY,QAAO,+BAA8B;AAEzD,SAAQC,IAAI,QAAO,SAAQ;AAE3B,SAAQC,gBAAgB,QAAO,qCAAoC;AACnE,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,aAAa,QAAO,8BAA6B;AACzD,SAAQC,eAAe,QAAO,gCAA+B;AAC7D,SAAQC,WAAW,QAAO,0BAAyB;AACnD,SAAQC,gBAAgB,QAAO,+BAA8B;AAC7D,SAAQC,QAAQ,QAAO,gBAAe;AACtC,SAAQC,2BAA2B,QAAO,mCAAkC;AAC5E,SAAQC,WAAW,QAAO,mB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;IAEA,+DAA+D;IAC/D,IAAI,CAAC,mCAAmCI,IAAI,CAACH,WAAW;QACtD7D,OAAOgB,KAAK,CACV,CAAC,yBAAyB,EAAE6C,SAAS,4DAA4D,CAAC,EAClG;YAAC5C,MAAMvC,UAAUwC,WAAW;QAAA;QAE9B,OAAO0C;IACT;IAEA,OAAOC;AACT"}
1
+ {"version":3,"sources":["../../../src/actions/deploy/deployStudio.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {styleText} from 'node:util'\nimport {createGzip, type Gzip} from 'node:zlib'\n\nimport {formatSchemaValidation, SchemaExtractionError} from '@sanity/cli-build/_internal/extract'\nimport {exitCodes} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {getWorkbench} from '@sanity/workbench-cli/deploy'\nimport {type StudioManifest} from 'sanity'\nimport {pack} from 'tar-fs'\n\nimport {createDeployment, type UserApplication} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {NO_PROJECT_ID} from '../../util/errorMessages.js'\nimport {buildStudio} from '../build/buildStudio.js'\nimport {createStudioUserApplication} from './createUserApplication.js'\nimport {\n checkAutoUpdates,\n checkBuild,\n checkPackageVersion,\n type CheckReporter,\n checkStudioTarget,\n verifyOutputDir,\n} from './deployChecks.js'\nimport {deployDebug} from './deployDebug.js'\nimport {listDeploymentFiles} from './deploymentPlan.js'\nimport {type DeployResult, runDeploy} from './deployRunner.js'\nimport {deployStudioSchemasAndManifests} from './deployStudioSchemasAndManifests.js'\nimport {findUserApplicationForStudio} from './findUserApplication.js'\nimport {type DeployAppOptions} from './types.js'\n\nconst STUDIO_PACKAGE = 'sanity'\n\nexport function deployStudio(options: DeployAppOptions): Promise<void> {\n return runDeploy(options, {\n listFiles: ({flags, projectRoot, sourceDir}) =>\n flags.external ? Promise.resolve([]) : listDeploymentFiles(sourceDir, projectRoot.directory),\n run: runStudioDeployment,\n type: 'studio',\n })\n}\n\n/** Validates the deploy, extracts and uploads the schema, and ships the build. */\nasync function runStudioDeployment(\n options: DeployAppOptions,\n reporter: CheckReporter,\n): Promise<DeployResult | void> {\n const {cliConfig, flags, output, sourceDir} = options\n const workDir = options.projectRoot.directory\n const isExternal = !!flags.external\n const isWorkbenchApp = getWorkbench(cliConfig) !== null\n const projectId = cliConfig.api?.projectId\n const dryRun = !!flags['dry-run']\n\n const isAutoUpdating = checkAutoUpdates(reporter, {cliConfig, flags})\n\n if (isExternal && isWorkbenchApp) {\n // A federated app deploys through Sanity's build/hosting pipeline, which\n // --external skips.\n reporter.report({\n exitCode: exitCodes.USAGE_ERROR,\n message: 'Deploying a federated application to an external host is not yet supported',\n solution: 'Remove the --external flag to deploy to Sanity hosting',\n status: 'fail',\n })\n }\n\n const version = await checkPackageVersion(reporter, {\n moduleName: STUDIO_PACKAGE,\n workDir,\n })\n\n reporter.report(\n projectId\n ? {message: `Project: ${projectId}`, status: 'pass'}\n : {\n message: NO_PROJECT_ID,\n solution: 'Add `api.projectId` to sanity.cli.ts',\n status: 'fail',\n },\n )\n\n const application = await resolveStudioApplication(options, {dryRun, reporter})\n\n await checkBuild(reporter, {\n build: () =>\n buildStudio({\n autoUpdatesEnabled: isAutoUpdating,\n calledFromDeploy: true,\n cliConfig,\n flags,\n outDir: sourceDir,\n output,\n workDir,\n }),\n skipReason: studioBuildSkipReason({build: flags.build, isExternal}),\n successMessage: 'Studio built',\n })\n\n if (!isExternal) {\n await verifyOutputDir({isWorkbenchApp, reporter, sourceDir})\n }\n\n // Dry run stops here — everything below mutates.\n if (dryRun) return\n\n // A real deploy has already exited if anything failed; landing here without a\n // resolved application or version means the deploy target was never resolved.\n if (!application || !version) return\n\n const studioManifest = await uploadStudioSchema(options, {isExternal})\n const location = await shipStudioDeployment({\n application,\n isAutoUpdating,\n isExternal,\n options,\n studioManifest,\n version,\n })\n\n return {\n applicationType: 'studio',\n applicationVersion: version,\n target: {applicationId: application.id, title: application.title ?? null, url: location},\n }\n}\n\n/**\n * Finds the application a real deploy targets, registering a studio host when\n * none is configured. A dry run resolves and reports the target read-only instead.\n */\nasync function resolveStudioApplication(\n options: DeployAppOptions,\n {dryRun, reporter}: {dryRun: boolean; reporter: CheckReporter},\n): Promise<UserApplication | null> {\n const {cliConfig, flags, output} = options\n const isExternal = !!flags.external\n // Sets the title on a newly registered studio; blank falls back to undefined\n const title = flags.title?.trim() || undefined\n\n if (dryRun) {\n await checkStudioTarget(reporter, {\n appId: getAppId(cliConfig),\n isExternal,\n projectId: cliConfig.api?.projectId,\n studioHost: cliConfig.studioHost,\n title,\n urlFlag: flags.url,\n })\n return null\n }\n\n const projectId = cliConfig.api?.projectId ?? ''\n let application = await findUserApplicationForStudio({\n appId: getAppId(cliConfig),\n isExternal,\n output,\n projectId,\n studioHost: cliConfig.studioHost,\n title,\n unattended: !!flags.yes,\n urlFlag: flags.url,\n })\n\n if (!application) {\n if (isExternal) {\n output.log('Your project has not been registered with an external studio URL.')\n output.log('Please enter the full URL where your studio is hosted.')\n } else {\n output.log('Your project has not been assigned a studio hostname.')\n output.log('To deploy your Sanity Studio to our hosted sanity.studio service,')\n output.log('you will need one. Please enter the subdomain you want to use.')\n }\n\n application = await createStudioUserApplication({\n projectId,\n title,\n urlType: isExternal ? 'external' : 'internal',\n })\n deployDebug('Created user application', application)\n }\n\n deployDebug('Found user application', application)\n return application\n}\n\n/** Extracts the studio schema and manifest and uploads them to the schema store. */\nasync function uploadStudioSchema(\n options: DeployAppOptions,\n {isExternal}: {isExternal: boolean},\n): Promise<StudioManifest | null> {\n const {cliConfig, flags, output, projectRoot, sourceDir} = options\n\n let studioManifest: StudioManifest | null = null\n try {\n studioManifest = await deployStudioSchemasAndManifests(\n {\n configPath: projectRoot.path,\n isExternal,\n outPath: `${sourceDir}/static`,\n projectId: cliConfig.api?.projectId ?? '',\n schemaRequired: flags['schema-required'],\n verbose: flags.verbose,\n workDir: projectRoot.directory,\n },\n output,\n )\n } catch (error) {\n deployDebug('Error deploying studio schemas and manifests', error)\n if (error instanceof SchemaExtractionError) {\n output.error(formatSchemaValidation(error.validation || []), {exit: 1})\n }\n output.error(`Error deploying studio schemas and manifests: ${error}`, {exit: 1})\n }\n\n if (!studioManifest) {\n output.error('Failed to generate studio manifest. Please check your schemas and manifests.', {\n exit: 1,\n })\n }\n\n return studioManifest\n}\n\nasync function shipStudioDeployment({\n application,\n isAutoUpdating,\n isExternal,\n options,\n studioManifest,\n version,\n}: {\n application: UserApplication\n isAutoUpdating: boolean\n isExternal: boolean\n options: DeployAppOptions\n studioManifest: StudioManifest | null\n version: string\n}): Promise<string> {\n const {cliConfig, output, sourceDir} = options\n\n let tarball: Gzip | undefined\n if (!isExternal) {\n tarball = pack(dirname(sourceDir), {entries: [basename(sourceDir)]}).pipe(createGzip())\n }\n\n const spin = spinner(isExternal ? 'Registering studio' : 'Deploying to sanity.studio').start()\n let location: string\n try {\n ;({location} = await createDeployment({\n applicationId: application.id,\n isApp: false,\n isAutoUpdating,\n manifest: studioManifest,\n projectId: cliConfig.api?.projectId,\n tarball,\n version,\n }))\n } catch (error) {\n spin.fail()\n throw error\n }\n spin.succeed()\n\n const named = application.title ? ` — \"${application.title}\"` : ''\n output.log(\n isExternal\n ? `\\nSuccess! Studio registered${named}`\n : `\\nSuccess! Studio deployed to ${styleText('cyan', location)}${named}`,\n )\n\n if (getAppId(cliConfig)) return location\n\n const example = `Example:\nexport default defineCliConfig({\n //…\n deployment: {\n ${styleText('cyan', `appId: '${application.id}'`)},\n },\n //…\n})`\n output.log(`\\nAdd ${styleText('cyan', `appId: '${application.id}'`)}`)\n output.log(`to the \\`deployment\\` section in sanity.cli.js or sanity.cli.ts`)\n output.log(`to avoid prompting for application id on next deploy.`)\n output.log(`\\n${example}`)\n\n return location\n}\n\nfunction studioBuildSkipReason({build, isExternal}: {build: boolean; isExternal: boolean}) {\n if (isExternal) return 'Build skipped for externally hosted studios'\n if (!build) return 'Build skipped (--no-build) — validating existing output directory'\n return\n}\n"],"names":["basename","dirname","styleText","createGzip","formatSchemaValidation","SchemaExtractionError","exitCodes","spinner","getWorkbench","pack","createDeployment","getAppId","NO_PROJECT_ID","buildStudio","createStudioUserApplication","checkAutoUpdates","checkBuild","checkPackageVersion","checkStudioTarget","verifyOutputDir","deployDebug","listDeploymentFiles","runDeploy","deployStudioSchemasAndManifests","findUserApplicationForStudio","STUDIO_PACKAGE","deployStudio","options","listFiles","flags","projectRoot","sourceDir","external","Promise","resolve","directory","run","runStudioDeployment","type","reporter","cliConfig","output","workDir","isExternal","isWorkbenchApp","projectId","api","dryRun","isAutoUpdating","report","exitCode","USAGE_ERROR","message","solution","status","version","moduleName","application","resolveStudioApplication","build","autoUpdatesEnabled","calledFromDeploy","outDir","skipReason","studioBuildSkipReason","successMessage","studioManifest","uploadStudioSchema","location","shipStudioDeployment","applicationType","applicationVersion","target","applicationId","id","title","url","trim","undefined","appId","studioHost","urlFlag","unattended","yes","log","urlType","configPath","path","outPath","schemaRequired","verbose","error","validation","exit","tarball","entries","pipe","spin","start","isApp","manifest","fail","succeed","named","example"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,SAAS,QAAO,YAAW;AACnC,SAAQC,UAAU,QAAkB,YAAW;AAE/C,SAAQC,sBAAsB,EAAEC,qBAAqB,QAAO,sCAAqC;AACjG,SAAQC,SAAS,QAAO,mBAAkB;AAC1C,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,YAAY,QAAO,+BAA8B;AAEzD,SAAQC,IAAI,QAAO,SAAQ;AAE3B,SAAQC,gBAAgB,QAA6B,qCAAoC;AACzF,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,aAAa,QAAO,8BAA6B;AACzD,SAAQC,WAAW,QAAO,0BAAyB;AACnD,SAAQC,2BAA2B,QAAO,6BAA4B;AACtE,SACEC,gBAAgB,EAChBC,UAAU,EACVC,mBAAmB,EAEnBC,iBAAiB,EACjBC,eAAe,QACV,oBAAmB;AAC1B,SAAQC,WAAW,QAAO,mBAAkB;AA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AE,CAAC,CAAC,CAAC,EAAE;;;EAGpD,CAAC;IACDjC,OAAO2C,GAAG,CAAC,CAAC,MAAM,EAAElF,UAAU,QAAQ,CAAC,QAAQ,EAAEuD,YAAYiB,EAAE,CAAC,CAAC,CAAC,GAAG;IACrEjC,OAAO2C,GAAG,CAAC,CAAC,+DAA+D,CAAC;IAC5E3C,OAAO2C,GAAG,CAAC,CAAC,qDAAqD,CAAC;IAClE3C,OAAO2C,GAAG,CAAC,CAAC,EAAE,EAAEoB,SAAS;IAEzB,OAAOpC;AACT;AAEA,SAASJ,sBAAsB,EAACL,KAAK,EAAEhB,UAAU,EAAwC;IACvF,IAAIA,YAAY,OAAO;IACvB,IAAI,CAACgB,OAAO,OAAO;IACnB;AACF"}
@@ -1,5 +1,4 @@
1
1
  import { styleText } from 'node:util';
2
- import { ux } from '@oclif/core/ux';
3
2
  import { SchemaDeploy, SchemaExtractionError } from '@sanity/cli-build/_internal/extract';
4
3
  import { getCliTelemetry, studioWorkerTask, subdebug } from '@sanity/cli-core';
5
4
  const debug = subdebug('deployStudioSchemasAndManifests');
@@ -7,7 +6,7 @@ const debug = subdebug('deployStudioSchemasAndManifests');
7
6
  * 1. Extracts the create manifest in dist/static (automatically deployed with studio)
8
7
  * 2. Deploys the schemas to /schemas endpoint
9
8
  * 3. Creates a studio manifest, uploads it to user application and lexicon
10
- */ export async function deployStudioSchemasAndManifests(options) {
9
+ */ export async function deployStudioSchemasAndManifests(options, output) {
11
10
  const { configPath, isExternal, outPath, projectId, schemaRequired, verbose, workDir } = options;
12
11
  const trace = getCliTelemetry().trace(SchemaDeploy, {
13
12
  // If the studio is externally hosted, we don't need to extract the manifest
@@ -43,7 +42,7 @@ const debug = subdebug('deployStudioSchemasAndManifests');
43
42
  throw new SchemaExtractionError(result.error, result.validation);
44
43
  }
45
44
  trace.complete();
46
- ux.stdout(`${styleText('gray', '↳ List deployed schemas with:')} ${styleText('cyan', 'sanity schema list')}`);
45
+ output.log(`${styleText('gray', '↳ List deployed schemas with:')} ${styleText('cyan', 'sanity schema list')}`);
47
46
  return result.studioManifest;
48
47
  } catch (err) {
49
48
  trace.error(err);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/deploy/deployStudioSchemasAndManifests.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {ux} from '@oclif/core/ux'\nimport {SchemaDeploy, SchemaExtractionError} from '@sanity/cli-build/_internal/extract'\nimport {getCliTelemetry, studioWorkerTask, subdebug} from '@sanity/cli-core'\nimport {type SchemaValidationProblemGroup} from '@sanity/types'\nimport {type StudioManifest} from 'sanity'\n\nimport {type DeployStudioSchemasAndManifestsWorkerData} from './types.js'\n\ntype DeployStudioSchemasAndManifestsWorkerMessage =\n | {\n error: string\n type: 'error'\n validation?: SchemaValidationProblemGroup[]\n }\n | {\n studioManifest: StudioManifest | null\n type: 'success'\n }\n\nconst debug = subdebug('deployStudioSchemasAndManifests')\n\n/**\n * 1. Extracts the create manifest in dist/static (automatically deployed with studio)\n * 2. Deploys the schemas to /schemas endpoint\n * 3. Creates a studio manifest, uploads it to user application and lexicon\n */\nexport async function deployStudioSchemasAndManifests(\n options: DeployStudioSchemasAndManifestsWorkerData,\n): Promise<StudioManifest | null> {\n const {configPath, isExternal, outPath, projectId, schemaRequired, verbose, workDir} = options\n\n const trace = getCliTelemetry().trace(SchemaDeploy, {\n // If the studio is externally hosted, we don't need to extract the manifest\n extractManifest: !isExternal,\n manifestDir: outPath,\n schemaRequired,\n })\n\n try {\n trace.start()\n const result = await studioWorkerTask<DeployStudioSchemasAndManifestsWorkerMessage>(\n new URL('deployStudioSchemasAndManifests.worker.js', import.meta.url),\n {\n env: {\n ...process.env,\n // Workers don't inherit TTY state — propagate color support from parent\n ...(process.stdout.isTTY && !process.env.NO_COLOR ? {FORCE_COLOR: '1'} : {}),\n },\n name: 'deployStudioSchemasAndManifests',\n studioRootPath: workDir,\n workerData: {\n configPath,\n isExternal,\n outPath,\n projectId,\n schemaRequired,\n verbose,\n workDir,\n } satisfies DeployStudioSchemasAndManifestsWorkerData,\n },\n )\n\n debug('Result %o', result)\n\n // If the schema is required, we throw an error\n if (result.type === 'error') {\n throw new SchemaExtractionError(result.error, result.validation)\n }\n\n trace.complete()\n ux.stdout(\n `${styleText('gray', '↳ List deployed schemas with:')} ${styleText('cyan', 'sanity schema list')}`,\n )\n return result.studioManifest\n } catch (err) {\n trace.error(err)\n throw err\n }\n}\n"],"names":["styleText","ux","SchemaDeploy","SchemaExtractionError","getCliTelemetry","studioWorkerTask","subdebug","debug","deployStudioSchemasAndManifests","options","configPath","isExternal","outPath","projectId","schemaRequired","verbose","workDir","trace","extractManifest","manifestDir","start","result","URL","url","env","process","stdout","isTTY","NO_COLOR","FORCE_COLOR","name","studioRootPath","workerData","type","error","validation","complete","studioManifest","err"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,EAAE,QAAO,iBAAgB;AACjC,SAAQC,YAAY,EAAEC,qBAAqB,QAAO,sCAAqC;AACvF,SAAQC,eAAe,EAAEC,gBAAgB,EAAEC,QAAQ,QAAO,mBAAkB;AAiB5E,MAAMC,QAAQD,SAAS;AAEvB;;;;CAIC,GACD,OAAO,eAAeE,gCACpBC,OAAkD;IAElD,MAAM,EAACC,UAAU,EAAEC,UAAU,EAAEC,OAAO,EAAEC,SAAS,EAAEC,cAAc,EAAEC,OAAO,EAAEC,OAAO,EAAC,GAAGP;IAEvF,MAAMQ,QAAQb,kBAAkBa,KAAK,CAACf,cAAc;QAClD,4EAA4E;QAC5EgB,iBAAiB,CAACP;QAClBQ,aAAaP;QACbE;IACF;IAEA,IAAI;QACFG,MAAMG,KAAK;QACX,MAAMC,SAAS,MAAMhB,iBACnB,IAAIiB,IAAI,6CAA6C,YAAYC,GAAG,GACpE;YACEC,KAAK;gBACH,GAAGC,QAAQD,GAAG;gBACd,wEAAwE;gBACxE,GAAIC,QAAQC,MAAM,CAACC,KAAK,IAAI,CAACF,QAAQD,GAAG,CAACI,QAAQ,GAAG;oBAACC,aAAa;gBAAG,IAAI,CAAC,CAAC;YAC7E;YACAC,MAAM;YACNC,gBAAgBf;YAChBgB,YAAY;gBACVtB;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;YACF;QACF;QAGFT,MAAM,aAAac;QAEnB,+CAA+C;QAC/C,IAAIA,OAAOY,IAAI,KAAK,SAAS;YAC3B,MAAM,IAAI9B,sBAAsBkB,OAAOa,KAAK,EAAEb,OAAOc,UAAU;QACjE;QAEAlB,MAAMmB,QAAQ;QACdnC,GAAGyB,MAAM,CACP,GAAG1B,UAAU,QAAQ,iCAAiC,CAAC,EAAEA,UAAU,QAAQ,uBAAuB;QAEpG,OAAOqB,OAAOgB,cAAc;IAC9B,EAAE,OAAOC,KAAK;QACZrB,MAAMiB,KAAK,CAACI;QACZ,MAAMA;IACR;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/deploy/deployStudioSchemasAndManifests.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {SchemaDeploy, SchemaExtractionError} from '@sanity/cli-build/_internal/extract'\nimport {getCliTelemetry, type Output, studioWorkerTask, subdebug} from '@sanity/cli-core'\nimport {type SchemaValidationProblemGroup} from '@sanity/types'\nimport {type StudioManifest} from 'sanity'\n\nimport {type DeployStudioSchemasAndManifestsWorkerData} from './types.js'\n\ntype DeployStudioSchemasAndManifestsWorkerMessage =\n | {\n error: string\n type: 'error'\n validation?: SchemaValidationProblemGroup[]\n }\n | {\n studioManifest: StudioManifest | null\n type: 'success'\n }\n\nconst debug = subdebug('deployStudioSchemasAndManifests')\n\n/**\n * 1. Extracts the create manifest in dist/static (automatically deployed with studio)\n * 2. Deploys the schemas to /schemas endpoint\n * 3. Creates a studio manifest, uploads it to user application and lexicon\n */\nexport async function deployStudioSchemasAndManifests(\n options: DeployStudioSchemasAndManifestsWorkerData,\n output: Output,\n): Promise<StudioManifest | null> {\n const {configPath, isExternal, outPath, projectId, schemaRequired, verbose, workDir} = options\n\n const trace = getCliTelemetry().trace(SchemaDeploy, {\n // If the studio is externally hosted, we don't need to extract the manifest\n extractManifest: !isExternal,\n manifestDir: outPath,\n schemaRequired,\n })\n\n try {\n trace.start()\n const result = await studioWorkerTask<DeployStudioSchemasAndManifestsWorkerMessage>(\n new URL('deployStudioSchemasAndManifests.worker.js', import.meta.url),\n {\n env: {\n ...process.env,\n // Workers don't inherit TTY state — propagate color support from parent\n ...(process.stdout.isTTY && !process.env.NO_COLOR ? {FORCE_COLOR: '1'} : {}),\n },\n name: 'deployStudioSchemasAndManifests',\n studioRootPath: workDir,\n workerData: {\n configPath,\n isExternal,\n outPath,\n projectId,\n schemaRequired,\n verbose,\n workDir,\n } satisfies DeployStudioSchemasAndManifestsWorkerData,\n },\n )\n\n debug('Result %o', result)\n\n // If the schema is required, we throw an error\n if (result.type === 'error') {\n throw new SchemaExtractionError(result.error, result.validation)\n }\n\n trace.complete()\n output.log(\n `${styleText('gray', '↳ List deployed schemas with:')} ${styleText('cyan', 'sanity schema list')}`,\n )\n return result.studioManifest\n } catch (err) {\n trace.error(err)\n throw err\n }\n}\n"],"names":["styleText","SchemaDeploy","SchemaExtractionError","getCliTelemetry","studioWorkerTask","subdebug","debug","deployStudioSchemasAndManifests","options","output","configPath","isExternal","outPath","projectId","schemaRequired","verbose","workDir","trace","extractManifest","manifestDir","start","result","URL","url","env","process","stdout","isTTY","NO_COLOR","FORCE_COLOR","name","studioRootPath","workerData","type","error","validation","complete","log","studioManifest","err"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,YAAY,EAAEC,qBAAqB,QAAO,sCAAqC;AACvF,SAAQC,eAAe,EAAeC,gBAAgB,EAAEC,QAAQ,QAAO,mBAAkB;AAiBzF,MAAMC,QAAQD,SAAS;AAEvB;;;;CAIC,GACD,OAAO,eAAeE,gCACpBC,OAAkD,EAClDC,MAAc;IAEd,MAAM,EAACC,UAAU,EAAEC,UAAU,EAAEC,OAAO,EAAEC,SAAS,EAAEC,cAAc,EA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