@sanity/cli 6.6.0 → 6.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.
- package/README.md +12 -4
- package/dist/actions/auth/login/login.js +4 -1
- package/dist/actions/auth/login/login.js.map +1 -1
- package/dist/actions/build/buildApp.js +4 -5
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStaticFiles.js +12 -4
- package/dist/actions/build/buildStaticFiles.js.map +1 -1
- package/dist/actions/build/buildStudio.js +6 -14
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/{getStudioEnvironmentVariables.js → getEnvironmentVariables.js} +15 -19
- package/dist/actions/build/getEnvironmentVariables.js.map +1 -0
- package/dist/actions/deploy/deployStudio.js +1 -2
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/deploy/deployStudioSchemasAndManifests.js +1 -2
- package/dist/actions/deploy/deployStudioSchemasAndManifests.js.map +1 -1
- package/dist/actions/deploy/deployStudioSchemasAndManifests.worker.js +1 -1
- package/dist/actions/deploy/deployStudioSchemasAndManifests.worker.js.map +1 -1
- package/dist/actions/dev/startStudioDevServer.js +1 -1
- package/dist/actions/dev/startStudioDevServer.js.map +1 -1
- package/dist/actions/documents/validateDocuments.worker.js +1 -2
- package/dist/actions/documents/validateDocuments.worker.js.map +1 -1
- package/dist/actions/graphql/SchemaError.js +1 -1
- package/dist/actions/graphql/SchemaError.js.map +1 -1
- package/dist/actions/init/initAction.js +32 -1
- package/dist/actions/init/initAction.js.map +1 -1
- package/dist/actions/init/scaffoldTemplate.js +32 -18
- package/dist/actions/init/scaffoldTemplate.js.map +1 -1
- package/dist/actions/init/templates/index.js +2 -0
- package/dist/actions/init/templates/index.js.map +1 -1
- package/dist/actions/init/templates/pageBuilder.js +32 -0
- package/dist/actions/init/templates/pageBuilder.js.map +1 -0
- package/dist/actions/init/types.js +2 -1
- package/dist/actions/init/types.js.map +1 -1
- package/dist/actions/manifest/extractManifest.js +1 -1
- package/dist/actions/manifest/extractManifest.js.map +1 -1
- package/dist/actions/manifest/extractManifest.worker.js +1 -1
- package/dist/actions/manifest/extractManifest.worker.js.map +1 -1
- package/dist/actions/mcp/editorConfigs.js +51 -11
- package/dist/actions/mcp/editorConfigs.js.map +1 -1
- package/dist/actions/mcp/promptForMCPSetup.js +16 -11
- package/dist/actions/mcp/promptForMCPSetup.js.map +1 -1
- package/dist/actions/mcp/setupMCP.js +180 -61
- package/dist/actions/mcp/setupMCP.js.map +1 -1
- package/dist/actions/mcp/types.js.map +1 -1
- package/dist/actions/schema/deploySchemas.js +1 -1
- package/dist/actions/schema/deploySchemas.js.map +1 -1
- package/dist/actions/schema/extractSanityWorkspace.worker.js +1 -1
- package/dist/actions/schema/extractSanityWorkspace.worker.js.map +1 -1
- package/dist/actions/schema/extractSchema.js +1 -4
- package/dist/actions/schema/extractSchema.js.map +1 -1
- package/dist/actions/schema/extractSchemaWatcher.js +1 -4
- package/dist/actions/schema/extractSchemaWatcher.js.map +1 -1
- package/dist/actions/schema/getExtractOptions.js +8 -18
- package/dist/actions/schema/getExtractOptions.js.map +1 -1
- package/dist/actions/schema/types.js +0 -6
- package/dist/actions/schema/types.js.map +1 -1
- package/dist/actions/schema/validateAction.js +1 -1
- package/dist/actions/schema/validateAction.js.map +1 -1
- package/dist/actions/schema/validateSchema.worker.js +1 -2
- package/dist/actions/schema/validateSchema.worker.js.map +1 -1
- package/dist/actions/schema/watchExtractSchema.js +1 -1
- package/dist/actions/schema/watchExtractSchema.js.map +1 -1
- package/dist/actions/skills/readSkillState.js +54 -0
- package/dist/actions/skills/readSkillState.js.map +1 -0
- package/dist/actions/skills/setupSkills.js +73 -0
- package/dist/actions/skills/setupSkills.js.map +1 -0
- package/dist/commands/build.js +9 -22
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/cors/add.js +5 -5
- package/dist/commands/cors/add.js.map +1 -1
- package/dist/commands/datasets/export.js +9 -0
- package/dist/commands/datasets/export.js.map +1 -1
- package/dist/commands/docs/read.js +33 -12
- package/dist/commands/docs/read.js.map +1 -1
- package/dist/commands/init.js +12 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/manifest/extract.js +1 -2
- package/dist/commands/manifest/extract.js.map +1 -1
- package/dist/commands/mcp/configure.js +2 -1
- package/dist/commands/mcp/configure.js.map +1 -1
- package/dist/commands/schemas/deploy.js +1 -2
- package/dist/commands/schemas/deploy.js.map +1 -1
- package/dist/exports/_internal.d.ts +2 -1
- package/dist/exports/_internal.js +1 -1
- package/dist/exports/_internal.js.map +1 -1
- package/dist/server/devServer.js +25 -4
- package/dist/server/devServer.js.map +1 -1
- package/dist/server/previewServer.js +1 -1
- package/dist/server/previewServer.js.map +1 -1
- package/dist/services/mcp.js +1 -1
- package/dist/services/mcp.js.map +1 -1
- package/dist/telemetry/init.telemetry.js.map +1 -1
- package/oclif.manifest.json +134 -118
- package/package.json +15 -16
- package/templates/page-builder/README.md +9 -0
- package/templates/page-builder/schemaTypes/hero.js +31 -0
- package/templates/page-builder/schemaTypes/index.js +19 -0
- package/templates/page-builder/static/.gitkeep +0 -0
- package/dist/actions/build/buildDebug.js +0 -4
- package/dist/actions/build/buildDebug.js.map +0 -1
- package/dist/actions/build/buildVendorDependencies.js +0 -149
- package/dist/actions/build/buildVendorDependencies.js.map +0 -1
- package/dist/actions/build/checkStudioDependencyVersions.js +0 -155
- package/dist/actions/build/checkStudioDependencyVersions.js.map +0 -1
- package/dist/actions/build/createExternalFromImportMap.js +0 -11
- package/dist/actions/build/createExternalFromImportMap.js.map +0 -1
- package/dist/actions/build/decorateIndexWithAutoGeneratedWarning.js +0 -13
- package/dist/actions/build/decorateIndexWithAutoGeneratedWarning.js.map +0 -1
- package/dist/actions/build/decorateIndexWithBridgeScript.js +0 -17
- package/dist/actions/build/decorateIndexWithBridgeScript.js.map +0 -1
- package/dist/actions/build/decorateIndexWithStagingScript.js +0 -16
- package/dist/actions/build/decorateIndexWithStagingScript.js.map +0 -1
- package/dist/actions/build/getAppEnvVars.js +0 -9
- package/dist/actions/build/getAppEnvVars.js.map +0 -1
- package/dist/actions/build/getEntryModule.js +0 -46
- package/dist/actions/build/getEntryModule.js.map +0 -1
- package/dist/actions/build/getPossibleDocumentComponentLocations.js +0 -11
- package/dist/actions/build/getPossibleDocumentComponentLocations.js.map +0 -1
- package/dist/actions/build/getStudioEnvVars.js +0 -9
- package/dist/actions/build/getStudioEnvVars.js.map +0 -1
- package/dist/actions/build/getStudioEnvironmentVariables.js.map +0 -1
- package/dist/actions/build/getViteConfig.js +0 -219
- package/dist/actions/build/getViteConfig.js.map +0 -1
- package/dist/actions/build/normalizeBasePath.js +0 -9
- package/dist/actions/build/normalizeBasePath.js.map +0 -1
- package/dist/actions/build/renderDocument.js +0 -50
- package/dist/actions/build/renderDocument.js.map +0 -1
- package/dist/actions/build/renderDocument.worker.js +0 -9
- package/dist/actions/build/renderDocument.worker.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js +0 -79
- package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js +0 -61
- package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js +0 -165
- package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/components/Favicons.js +0 -28
- package/dist/actions/build/renderDocumentWorker/components/Favicons.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js +0 -178
- package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/components/NoJavascript.js +0 -51
- package/dist/actions/build/renderDocumentWorker/components/NoJavascript.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js +0 -41
- package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js +0 -55
- package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js +0 -31
- package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js +0 -30
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/types.js +0 -5
- package/dist/actions/build/renderDocumentWorker/types.js.map +0 -1
- package/dist/actions/build/writeSanityRuntime.js +0 -64
- package/dist/actions/build/writeSanityRuntime.js.map +0 -1
- package/dist/actions/docs/normalizeDocsPath.js +0 -15
- package/dist/actions/docs/normalizeDocsPath.js.map +0 -1
- package/dist/actions/schema/extractSanitySchema.worker.js +0 -33
- package/dist/actions/schema/extractSanitySchema.worker.js.map +0 -1
- package/dist/actions/schema/formatSchemaValidation.js +0 -78
- package/dist/actions/schema/formatSchemaValidation.js.map +0 -1
- package/dist/actions/schema/matchSchemaPattern.js +0 -22
- package/dist/actions/schema/matchSchemaPattern.js.map +0 -1
- package/dist/actions/schema/runSchemaExtraction.js +0 -39
- package/dist/actions/schema/runSchemaExtraction.js.map +0 -1
- package/dist/actions/schema/utils/SchemaExtractionError.js +0 -10
- package/dist/actions/schema/utils/SchemaExtractionError.js.map +0 -1
- package/dist/actions/schema/utils/extractValidationFromSchemaError.js +0 -12
- package/dist/actions/schema/utils/extractValidationFromSchemaError.js.map +0 -1
- package/dist/constants.js +0 -8
- package/dist/constants.js.map +0 -1
- package/dist/server/vite/plugin-sanity-build-entries.js +0 -67
- package/dist/server/vite/plugin-sanity-build-entries.js.map +0 -1
- package/dist/server/vite/plugin-sanity-favicons.js +0 -72
- package/dist/server/vite/plugin-sanity-favicons.js.map +0 -1
- package/dist/server/vite/plugin-sanity-runtime-rewrite.js +0 -18
- package/dist/server/vite/plugin-sanity-runtime-rewrite.js.map +0 -1
- package/dist/server/vite/plugin-schema-extraction.js +0 -201
- package/dist/server/vite/plugin-schema-extraction.js.map +0 -1
- package/dist/telemetry/build.telemetry.js +0 -13
- package/dist/telemetry/build.telemetry.js.map +0 -1
- package/dist/telemetry/extractSchema.telemetry.js +0 -18
- package/dist/telemetry/extractSchema.telemetry.js.map +0 -1
- package/dist/util/getWorkspace.js +0 -18
- package/dist/util/getWorkspace.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/types.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/types.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\n/**\n * Contains debug information about the serialized schema.\n *\n * @internal\n **/\nexport type SerializedSchemaDebug = {\n hoisted: Record<string, SerializedTypeDebug>\n parent?: SerializedSchemaDebug\n size: number\n types: Record<string, SerializedTypeDebug>\n}\n\n/**\n * Contains debug information about a serialized type.\n *\n * @internal\n **/\nexport type SerializedTypeDebug = {\n extends: string\n fields?: Record<string, SerializedTypeDebug>\n of?: Record<string, SerializedTypeDebug>\n size: number\n}\n\nexport const uniqWorkspaceWorkerDataSchema = z.object({\n configPath: z.string(),\n dataset: z.optional(z.string()),\n})\n\nexport type UniqWorkspaceWorkerData = z.infer<typeof uniqWorkspaceWorkerDataSchema>\n\nexport const extractWorkspaceWorkerData = z.object({\n configPath: z.string(),\n workDir: z.string(),\n})\n\nexport type ExtractWorkspaceWorkerData = z.infer<typeof extractWorkspaceWorkerData>\n"],"names":["z","uniqWorkspaceWorkerDataSchema","object","configPath","string","dataset","optional","extractWorkspaceWorkerData","workDir"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AA0B1B,OAAO,MAAMC,gCAAgCD,EAAEE,MAAM,CAAC;IACpDC,YAAYH,EAAEI,MAAM;IACpBC,SAASL,EAAEM,QAAQ,CAACN,EAAEI,MAAM;AAC9B,GAAE;AAIF,OAAO,MAAMG,6BAA6BP,EAAEE,MAAM,CAAC;IACjDC,YAAYH,EAAEI,MAAM;IACpBI,SAASR,EAAEI,MAAM;AACnB,GAAE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { formatSchemaValidation, getAggregatedSeverity } from '@sanity/cli-build/_internal/extract';
|
|
2
3
|
import { studioWorkerTask } from '@sanity/cli-core';
|
|
3
4
|
import { logSymbols, spinner } from '@sanity/cli-core/ux';
|
|
4
|
-
import { formatSchemaValidation, getAggregatedSeverity } from './formatSchemaValidation.js';
|
|
5
5
|
import { generateMetafile } from './metafile.js';
|
|
6
6
|
export async function validateAction(options) {
|
|
7
7
|
const { debugMetafilePath, format, level, output, workDir, workspace } = options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/validateAction.ts"],"sourcesContent":["import {writeFileSync} from 'node:fs'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/validateAction.ts"],"sourcesContent":["import {writeFileSync} from 'node:fs'\n\nimport {formatSchemaValidation, getAggregatedSeverity} from '@sanity/cli-build/_internal/extract'\nimport {Output, studioWorkerTask} from '@sanity/cli-core'\nimport {logSymbols, spinner} from '@sanity/cli-core/ux'\n\nimport {generateMetafile} from './metafile.js'\nimport {\n type ValidateSchemaWorkerData,\n type ValidateSchemaWorkerResult,\n} from './validateSchema.worker.js'\n\ninterface Options {\n output: Output\n workDir: string\n\n debugMetafilePath?: string\n format?: string\n level?: 'error' | 'warning'\n workspace?: string\n}\n\nexport async function validateAction(options: Options): Promise<void> {\n const {debugMetafilePath, format, level, output, workDir, workspace} = options\n\n let spin\n\n if (format === 'pretty') {\n spin = spinner(\n workspace ? `Validating schema from workspace '${workspace}'…` : 'Validating schema…',\n ).start()\n }\n\n const {serializedDebug, validation} = await studioWorkerTask<ValidateSchemaWorkerResult>(\n new URL('validateSchema.worker.js', import.meta.url),\n {\n name: 'validateSchema',\n studioRootPath: workDir,\n workerData: {\n debugSerialize: Boolean(debugMetafilePath),\n level,\n workDir,\n workspace: workspace,\n } satisfies ValidateSchemaWorkerData,\n },\n )\n\n const problems = validation.flatMap((group) => group.problems)\n const errorCount = problems.filter((problem) => problem.severity === 'error').length\n const warningCount = problems.filter((problem) => problem.severity === 'warning').length\n\n const overallSeverity = getAggregatedSeverity(validation)\n const didFail = overallSeverity === 'error'\n\n if (debugMetafilePath && !didFail) {\n if (!serializedDebug) throw new Error('serializedDebug should always be produced')\n const metafile = generateMetafile(serializedDebug)\n writeFileSync(debugMetafilePath, JSON.stringify(metafile), 'utf8')\n }\n\n switch (format) {\n case 'json': {\n output.log(JSON.stringify(validation))\n break\n }\n case 'ndjson': {\n for (const group of validation) {\n output.log(JSON.stringify(group))\n }\n break\n }\n default: {\n spin?.succeed('Validated schema')\n output.log(`\\nValidation results:`)\n output.log(\n `${logSymbols.error} Errors: ${errorCount.toLocaleString('en-US')} error${\n errorCount === 1 ? '' : 's'\n }`,\n )\n if (level !== 'error') {\n output.log(\n `${logSymbols.warning} Warnings: ${warningCount.toLocaleString('en-US')} warning${\n warningCount === 1 ? '' : 's'\n }`,\n )\n }\n output.log()\n\n output.log(formatSchemaValidation(validation))\n\n if (debugMetafilePath) {\n output.log()\n if (didFail) {\n output.log(`${logSymbols.info} Metafile not written due to validation errors`)\n } else {\n output.log(`${logSymbols.info} Metafile written to: ${debugMetafilePath}`)\n output.log(` This can be analyzed at https://esbuild.github.io/analyze/`)\n }\n }\n }\n }\n\n if (didFail) {\n throw new Error('Schema validation failed')\n }\n}\n"],"names":["writeFileSync","formatSchemaValidation","getAggregatedSeverity","studioWorkerTask","logSymbols","spinner","generateMetafile","validateAction","options","debugMetafilePath","format","level","output","workDir","workspace","spin","start","serializedDebug","validation","URL","url","name","studioRootPath","workerData","debugSerialize","Boolean","problems","flatMap","group","errorCount","filter","problem","severity","length","warningCount","overallSeverity","didFail","Error","metafile","JSON","stringify","log","succeed","error","toLocaleString","warning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,CAACF,KAAKC,SAAS,CAACtB;gBAC1B;YACF;QACA,KAAK;YAAU;gBACb,KAAK,MAAMU,SAASV,WAAY;oBAC9BN,OAAO6B,GAAG,CAACF,KAAKC,SAAS,CAACZ;gBAC5B;gBACA;YACF;QACA;YAAS;gBACPb,MAAM2B,QAAQ;gBACd9B,OAAO6B,GAAG,CAAC,CAAC,qBAAqB,CAAC;gBAClC7B,OAAO6B,GAAG,CACR,GAAGrC,WAAWuC,KAAK,CAAC,WAAW,EAAEd,WAAWe,cAAc,CAAC,SAAS,MAAM,EACxEf,eAAe,IAAI,KAAK,KACxB;gBAEJ,IAAIlB,UAAU,SAAS;oBACrBC,OAAO6B,GAAG,CACR,GAAGrC,WAAWyC,OAAO,CAAC,WAAW,EAAEX,aAAaU,cAAc,CAAC,SAAS,QAAQ,EAC9EV,iBAAiB,IAAI,KAAK,KAC1B;gBAEN;gBACAtB,OAAO6B,GAAG;gBAEV7B,OAAO6B,GAAG,CAACxC,uBAAuBiB;gBAElC,IAAIT,mBAAmB;oBACrBG,OAAO6B,GAAG;oBACV,IAAIL,SAAS;wBACXxB,OAAO6B,GAAG,CAAC,GAAGrC,WAAW0C,IAAI,CAAC,8CAA8C,CAAC;oBAC/E,OAAO;wBACLlC,OAAO6B,GAAG,CAAC,GAAGrC,WAAW0C,IAAI,CAAC,sBAAsB,EAAErC,mBAAmB;wBACzEG,OAAO6B,GAAG,CAAC,CAAC,4DAA4D,CAAC;oBAC3E;gBACF;YACF;IACF;IAEA,IAAIL,SAAS;QACX,MAAM,IAAIC,MAAM;IAClB;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
2
|
-
import { findStudioConfigPath, getStudioWorkspaces } from '@sanity/cli-core';
|
|
2
|
+
import { findStudioConfigPath, getStudioWorkspaces, getWorkspace } from '@sanity/cli-core';
|
|
3
3
|
import { DescriptorConverter } from '@sanity/schema/_internal';
|
|
4
|
-
import { getWorkspace } from '../../util/getWorkspace.js';
|
|
5
4
|
import { isSchemaError } from '../../util/isSchemaError.js';
|
|
6
5
|
const { debugSerialize, level = 'warning', workDir, workspace: workspaceName } = workerData;
|
|
7
6
|
async function main() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/validateSchema.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {findStudioConfigPath, getStudioWorkspaces} from '@sanity/cli-core'\nimport {\n type EncodableObject,\n type EncodableValue,\n type SetSynchronization,\n} from '@sanity/descriptors'\nimport {DescriptorConverter} from '@sanity/schema/_internal'\nimport {\n type Schema,\n type SchemaValidationProblem,\n type SchemaValidationProblemGroup,\n} from '@sanity/types'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/validateSchema.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {findStudioConfigPath, getStudioWorkspaces, getWorkspace} from '@sanity/cli-core'\nimport {\n type EncodableObject,\n type EncodableValue,\n type SetSynchronization,\n} from '@sanity/descriptors'\nimport {DescriptorConverter} from '@sanity/schema/_internal'\nimport {\n type Schema,\n type SchemaValidationProblem,\n type SchemaValidationProblemGroup,\n} from '@sanity/types'\n\nimport {isSchemaError} from '../../util/isSchemaError.js'\nimport {type SerializedSchemaDebug, type SerializedTypeDebug} from './types.js'\n\n/** @internal */\nexport interface ValidateSchemaWorkerData {\n workDir: string\n\n debugSerialize?: boolean\n level?: SchemaValidationProblem['severity']\n workspace?: string\n}\n\n/** @internal */\nexport interface ValidateSchemaWorkerResult {\n validation: SchemaValidationProblemGroup[]\n\n serializedDebug?: SerializedSchemaDebug\n}\n\nconst {\n debugSerialize,\n level = 'warning',\n workDir,\n workspace: workspaceName,\n} = workerData as ValidateSchemaWorkerData\n\nasync function main() {\n if (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n }\n\n try {\n const configPath = await findStudioConfigPath(workDir)\n const workspaces = await getStudioWorkspaces(configPath)\n const workspace = getWorkspace(workspaces, workspaceName)\n const schema = workspace.schema\n parentPort?.postMessage(await resultFromSchema(schema))\n } catch (err: unknown) {\n if (isSchemaError(err)) {\n parentPort?.postMessage(await resultFromSchema(err.schema))\n return\n }\n\n throw err\n }\n}\n\nasync function resultFromSchema(schema: Schema): Promise<ValidateSchemaWorkerResult> {\n let serializedDebug: ValidateSchemaWorkerResult['serializedDebug']\n\n if (debugSerialize) {\n const conv = new DescriptorConverter()\n const set = await conv.get(schema)\n serializedDebug = getSerializedSchemaDebug(set)\n }\n\n const validation = schema._validation ?? []\n\n const result: ValidateSchemaWorkerResult = {\n serializedDebug,\n validation: validation\n .map((group) => ({\n ...group,\n problems: group.problems.filter((problem) =>\n level === 'error' ? problem.severity === 'error' : true,\n ),\n }))\n .filter((group) => group.problems.length),\n }\n\n return result\n}\n\nfunction getSerializedSchemaDebug(set: SetSynchronization<string>): SerializedSchemaDebug {\n let size = 0\n const types: Record<string, SerializedTypeDebug> = {}\n const hoisted: Record<string, SerializedTypeDebug> = {}\n\n for (const [id, value] of Object.entries(set.objectValues)) {\n const descType = typeof value.type === 'string' ? value.type : '<unknown>'\n switch (descType) {\n case 'sanity.schema.hoisted': {\n const key = typeof value.key === 'string' ? value.key : id\n // The `hoisted` can technically hoist _anything_,\n // but we detect the common case of field + array element.\n if (isEncodableObject(value.value) && isEncodableObject(value.value.typeDef)) {\n const debug = getSerializedTypeDebug(value.value.typeDef)\n hoisted[key] = debug\n size += debug.size\n }\n break\n }\n case 'sanity.schema.namedType': {\n const typeName = typeof value.name === 'string' ? value.name : id\n if (isEncodableObject(value.typeDef)) {\n const debug = getSerializedTypeDebug(value.typeDef)\n types[typeName] = debug\n size += debug.size\n }\n break\n }\n default:\n }\n size += JSON.stringify(value).length\n }\n\n return {\n hoisted,\n size,\n types,\n }\n}\n\nfunction isEncodableObject(val: EncodableValue | undefined): val is EncodableObject {\n return typeof val === 'object' && val !== null && !Array.isArray(val)\n}\n\nfunction getSerializedTypeDebug(typeDef: EncodableObject): SerializedTypeDebug {\n const ext = typeof typeDef.extends === 'string' ? typeDef.extends : '<unknown>'\n let fields: SerializedTypeDebug['fields']\n let of: SerializedTypeDebug['of']\n\n if (Array.isArray(typeDef.fields)) {\n fields = {}\n\n for (const field of typeDef.fields) {\n if (!isEncodableObject(field)) continue\n const name = field.name\n const fieldTypeDef = field.typeDef\n if (typeof name !== 'string' || !isEncodableObject(fieldTypeDef)) continue\n\n fields[name] = getSerializedTypeDebug(fieldTypeDef)\n }\n }\n\n if (Array.isArray(typeDef.of)) {\n of = {}\n\n for (const field of typeDef.of) {\n if (!isEncodableObject(field)) continue\n const name = field.name\n const arrayTypeDef = field.typeDef\n if (typeof name !== 'string' || !isEncodableObject(arrayTypeDef)) continue\n\n of[name] = getSerializedTypeDebug(arrayTypeDef)\n }\n }\n\n return {\n extends: ext,\n fields,\n of,\n size: JSON.stringify(typeDef).length,\n }\n}\n\nawait main()\n"],"names":["isMainThread","parentPort","workerData","findStudioConfigPath","getStudioWorkspaces","getWorkspace","DescriptorConverter","isSchemaError","debugSerialize","level","workDir","workspace","workspaceName","main","Error","configPath","workspaces","schema","postMessage","resultFromSchema","err","serializedDebug","conv","set","get","getSerializedSchemaDebug","validation","_validation","result","map","group","problems","filter","problem","severity","length","size","types","hoisted","id","value","Object","entries","objectValues","descType","type","key","isEncodableObject","typeDef","debug","getSerializedTypeDebug","typeName","name","JSON","stringify","val","Array","isArray","ext","extends","fields","of","field","fieldTypeDef","arrayTypeDef"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,oBAAoB,EAAEC,mBAAmB,EAAEC,YAAY,QAAO,mBAAkB;AAMxF,SAAQC,mBAAmB,QAAO,2BAA0B;AAO5D,SAAQC,aAAa,QAAO,8BAA6B;AAmBzD,MAAM,EACJC,cAAc,EACdC,QAAQ,SAAS,EACjBC,OAAO,EACPC,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gB,eAAe;YAElEH,MAAM,CAACR,KAAK,GAAGF,uBAAuBa;QACxC;IACF;IAEA,IAAIP,MAAMC,OAAO,CAACT,QAAQa,EAAE,GAAG;QAC7BA,KAAK,CAAC;QAEN,KAAK,MAAMC,SAASd,QAAQa,EAAE,CAAE;YAC9B,IAAI,CAACd,kBAAkBe,QAAQ;YAC/B,MAAMV,OAAOU,MAAMV,IAAI;YACvB,MAAMY,eAAeF,MAAMd,OAAO;YAClC,IAAI,OAAOI,SAAS,YAAY,CAACL,kBAAkBiB,eAAe;YAElEH,EAAE,CAACT,KAAK,GAAGF,uBAAuBc;QACpC;IACF;IAEA,OAAO;QACLL,SAASD;QACTE;QACAC;QACAzB,MAAMiB,KAAKC,SAAS,CAACN,SAASb,MAAM;IACtC;AACF;AAEA,MAAMtB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { SchemaExtractionWatchModeTrace } from '@sanity/cli-build/_internal/extract';
|
|
1
2
|
import { getCliTelemetry } from '@sanity/cli-core';
|
|
2
3
|
import mean from 'lodash-es/mean.js';
|
|
3
4
|
import once from 'lodash-es/once.js';
|
|
4
|
-
import { SchemaExtractionWatchModeTrace } from '../../telemetry/extractSchema.telemetry.js';
|
|
5
5
|
import { DEFAULT_WATCH_PATTERNS, startExtractSchemaWatcher } from './extractSchemaWatcher.js';
|
|
6
6
|
export async function watchExtractSchema(options) {
|
|
7
7
|
const { extractOptions, output } = options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/watchExtractSchema.ts"],"sourcesContent":["import {getCliTelemetry, type Output} from '@sanity/cli-core'\nimport mean from 'lodash-es/mean.js'\nimport once from 'lodash-es/once.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/watchExtractSchema.ts"],"sourcesContent":["import {\n type ExtractOptions,\n SchemaExtractionWatchModeTrace,\n} from '@sanity/cli-build/_internal/extract'\nimport {getCliTelemetry, type Output} from '@sanity/cli-core'\nimport mean from 'lodash-es/mean.js'\nimport once from 'lodash-es/once.js'\n\nimport {DEFAULT_WATCH_PATTERNS, startExtractSchemaWatcher} from './extractSchemaWatcher.js'\n\ninterface WatchExtractSchemaOptions {\n extractOptions: ExtractOptions\n output: Output\n}\n\nexport async function watchExtractSchema(\n options: WatchExtractSchemaOptions,\n): Promise<{close: () => Promise<void>}> {\n const {extractOptions, output} = options\n\n // Keep the start time + some simple stats for extractions as they happen\n const startTime = Date.now()\n const stats: {failedCount: number; successfulDurations: number[]} = {\n failedCount: 0,\n successfulDurations: [],\n }\n\n const watchPatterns = [...DEFAULT_WATCH_PATTERNS, ...extractOptions.watchPatterns]\n\n const trace = getCliTelemetry().trace(SchemaExtractionWatchModeTrace)\n trace.start()\n\n // Print watch mode header and patterns at the very beginning\n output.log('Schema extraction watch mode')\n output.log('')\n output.log('Watching for changes in:')\n for (const pattern of watchPatterns) {\n output.log(` - ${pattern}`)\n }\n output.log('')\n\n output.log('Running initial extraction...')\n\n // Start the watcher (includes initial extraction)\n const {close} = await startExtractSchemaWatcher({\n extractOptions,\n onExtraction: ({duration, success}) => {\n if (success) {\n stats.successfulDurations.push(duration)\n } else {\n stats.failedCount++\n }\n },\n output,\n watchPatterns,\n })\n\n trace.log({\n enforceRequiredFields: extractOptions.enforceRequiredFields,\n schemaFormat: extractOptions.format,\n step: 'started',\n })\n\n output.log('')\n output.log('Watching for changes... (Ctrl+C to stop)')\n\n /**\n * Cleanup function that logs telemetry and stops the watcher.\n * Wrapped in once() to prevent multiple calls.\n */\n const cleanup = once(async () => {\n trace.log({\n averageExtractionDuration: mean(stats.successfulDurations) || 0,\n extractionFailedCount: stats.failedCount,\n extractionSuccessfulCount: stats.successfulDurations.length,\n step: 'stopped',\n watcherDuration: Date.now() - startTime,\n })\n trace.complete()\n\n output.log('')\n output.log('Stopping watch mode...')\n await close()\n })\n\n // Return cleanup function for programmatic usage and testing\n // The CLI framework will handle SIGINT/SIGTERM\n return {close: cleanup}\n}\n"],"names":["SchemaExtractionWatchModeTrace","getCliTelemetry","mean","once","DEFAULT_WATCH_PATTERNS","startExtractSchemaWatcher","watchExtractSchema","options","extractOptions","output","startTime","Date","now","stats","failedCount","successfulDurations","watchPatterns","trace","start","log","pattern","close","onExtraction","duration","success","push","enforceRequiredFields","schemaFormat","format","step","cleanup","averageExtractionDuration","extractionFailedCount","extractionSuccessfulCount","length","watcherDuration","complete"],"mappings":"AAAA,SAEEA,8BAA8B,QACzB,sCAAqC;AAC5C,SAAQC,eAAe,QAAoB,mBAAkB;AAC7D,OAAOC,UAAU,oBAAmB;AACpC,OAAOC,UAAU,oBAAmB;AAEpC,SAAQC,sBAAsB,EAAEC,yBAAyB,QAAO,4BAA2B;AAO3F,OAAO,eAAeC,mBACpBC,OAAkC;IAElC,MAAM,EAACC,cAAc,EAAEC,MAAM,EAAC,GAAGF;IAEjC,yEAAyE;IACzE,MAAMG,YAAYC,KAAKC,GAAG;IAC1B,MAAMC,QAA8D;QAClEC,aAAa;QACbC,qBAAqB,EAAE;IACzB;IAEA,MAAMC,gBAAgB;WAAIZ;WAA2BI,eAAeQ,aAAa;KAAC;IAElF,MAAMC,QAAQhB,kBAAkBgB,KAAK,CAACjB;IACtCiB,MAAMC,KAAK;IAEX,6DAA6D;IAC7DT,OAAOU,GAAG,CAAC;IACXV,OAAOU,GAAG,CAAC;IACXV,OAAOU,GAAG,CAAC;IACX,KAAK,MAAMC,WAAWJ,cAAe;QACnCP,OAAOU,GAAG,CAAC,CAAC,IAAI,EAAEC,SAAS;IAC7B;IACAX,OAAOU,GAAG,CAAC;IAEXV,OAAOU,GAAG,CAAC;IAEX,kDAAkD;IAClD,MAAM,EAACE,KAAK,EAAC,GAAG,MAAMhB,0BAA0B;QAC9CG;QACAc,cAAc,CAAC,EAACC,QAAQ,EAAEC,OAAO,EAAC;YAChC,IAAIA,SAAS;gBACXX,MAAME,mBAAmB,CAACU,IAAI,CAACF;YACjC,OAAO;gBACLV,MAAMC,WAAW;YACnB;QACF;QACAL;QACAO;IACF;IAEAC,MAAME,GAAG,CAAC;QACRO,uBAAuBlB,eAAekB,qBAAqB;QAC3DC,cAAcnB,eAAeoB,MAAM;QACnCC,MAAM;IACR;IAEApB,OAAOU,GAAG,CAAC;IACXV,OAAOU,GAAG,CAAC;IAEX;;;GAGC,GACD,MAAMW,UAAU3B,KAAK;QACnBc,MAAME,GAAG,CAAC;YACRY,2BAA2B7B,KAAKW,MAAME,mBAAmB,KAAK;YAC9DiB,uBAAuBnB,MAAMC,WAAW;YACxCmB,2BAA2BpB,MAAME,mBAAmB,CAACmB,MAAM;YAC3DL,MAAM;YACNM,iBAAiBxB,KAAKC,GAAG,KAAKF;QAChC;QACAO,MAAMmB,QAAQ;QAEd3B,OAAOU,GAAG,CAAC;QACXV,OAAOU,GAAG,CAAC;QACX,MAAME;IACR;IAEA,6DAA6D;IAC7D,+CAA+C;IAC/C,OAAO;QAACA,OAAOS;IAAO;AACxB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { subdebug } from '@sanity/cli-core';
|
|
2
|
+
import { execa } from 'execa';
|
|
3
|
+
import { SKILLS_BIN_PATH } from './setupSkills.js';
|
|
4
|
+
const debug = subdebug('skills:state');
|
|
5
|
+
/**
|
|
6
|
+
* Runs the bundled `skills list -g --json` and returns the set of agent
|
|
7
|
+
* display names that have `skillName` installed globally.
|
|
8
|
+
*
|
|
9
|
+
* Any failure (spawn, parse, timeout, non-zero exit) is debug-logged and
|
|
10
|
+
* resolved with an empty set. Callers should treat that as "treat all agents
|
|
11
|
+
* as not installed" — re-installing is idempotent, so over-installing is
|
|
12
|
+
* safer than skipping based on a flaky probe.
|
|
13
|
+
*/ export async function readSkillState(opts) {
|
|
14
|
+
const empty = {
|
|
15
|
+
installedAgentDisplayNames: new Set()
|
|
16
|
+
};
|
|
17
|
+
let stdout;
|
|
18
|
+
try {
|
|
19
|
+
const result = await execa(process.execPath, [
|
|
20
|
+
SKILLS_BIN_PATH,
|
|
21
|
+
'list',
|
|
22
|
+
'-g',
|
|
23
|
+
'--json'
|
|
24
|
+
], {
|
|
25
|
+
stdio: 'pipe',
|
|
26
|
+
timeout: 10_000
|
|
27
|
+
});
|
|
28
|
+
stdout = result.stdout;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
debug('skills list failed: %O', error);
|
|
31
|
+
return empty;
|
|
32
|
+
}
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = JSON.parse(stdout);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
debug('Failed to parse skills list JSON: %O', error);
|
|
38
|
+
return empty;
|
|
39
|
+
}
|
|
40
|
+
if (!Array.isArray(parsed)) {
|
|
41
|
+
debug('Unexpected skills list JSON shape (not an array)');
|
|
42
|
+
return empty;
|
|
43
|
+
}
|
|
44
|
+
const match = parsed.find((entry)=>entry?.name === opts.skillName);
|
|
45
|
+
if (!match || !Array.isArray(match.agents)) {
|
|
46
|
+
return empty;
|
|
47
|
+
}
|
|
48
|
+
const displayNames = match.agents.filter((a)=>typeof a === 'string');
|
|
49
|
+
return {
|
|
50
|
+
installedAgentDisplayNames: new Set(displayNames)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=readSkillState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/skills/readSkillState.ts"],"sourcesContent":["import {subdebug} from '@sanity/cli-core'\nimport {execa} from 'execa'\n\nimport {SKILLS_BIN_PATH} from './setupSkills.js'\n\nconst debug = subdebug('skills:state')\n\ninterface ReadSkillStateOptions {\n /** Name of the skill to look up (matches the `name` field in `skills list --json`). */\n skillName: string\n}\n\ninterface SkillState {\n /** Display names of agents that have this skill installed globally. */\n installedAgentDisplayNames: Set<string>\n}\n\ninterface SkillListEntry {\n agents?: unknown\n name?: unknown\n}\n\n/**\n * Runs the bundled `skills list -g --json` and returns the set of agent\n * display names that have `skillName` installed globally.\n *\n * Any failure (spawn, parse, timeout, non-zero exit) is debug-logged and\n * resolved with an empty set. Callers should treat that as \"treat all agents\n * as not installed\" — re-installing is idempotent, so over-installing is\n * safer than skipping based on a flaky probe.\n */\nexport async function readSkillState(opts: ReadSkillStateOptions): Promise<SkillState> {\n const empty: SkillState = {installedAgentDisplayNames: new Set()}\n\n let stdout: string\n try {\n const result = await execa(process.execPath, [SKILLS_BIN_PATH, 'list', '-g', '--json'], {\n stdio: 'pipe',\n timeout: 10_000,\n })\n stdout = result.stdout\n } catch (error) {\n debug('skills list failed: %O', error)\n return empty\n }\n\n let parsed: unknown\n try {\n parsed = JSON.parse(stdout)\n } catch (error) {\n debug('Failed to parse skills list JSON: %O', error)\n return empty\n }\n\n if (!Array.isArray(parsed)) {\n debug('Unexpected skills list JSON shape (not an array)')\n return empty\n }\n\n const match = (parsed as SkillListEntry[]).find((entry) => entry?.name === opts.skillName)\n if (!match || !Array.isArray(match.agents)) {\n return empty\n }\n\n const displayNames = match.agents.filter((a): a is string => typeof a === 'string')\n return {installedAgentDisplayNames: new Set(displayNames)}\n}\n"],"names":["subdebug","execa","SKILLS_BIN_PATH","debug","readSkillState","opts","empty","installedAgentDisplayNames","Set","stdout","result","process","execPath","stdio","timeout","error","parsed","JSON","parse","Array","isArray","match","find","entry","name","skillName","agents","displayNames","filter","a"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,SAAQC,KAAK,QAAO,QAAO;AAE3B,SAAQC,eAAe,QAAO,mBAAkB;AAEhD,MAAMC,QAAQH,SAAS;AAiBvB;;;;;;;;CAQC,GACD,OAAO,eAAeI,eAAeC,IAA2B;IAC9D,MAAMC,QAAoB;QAACC,4BAA4B,IAAIC;IAAK;IAEhE,IAAIC;IACJ,IAAI;QACF,MAAMC,SAAS,MAAMT,MAAMU,QAAQC,QAAQ,EAAE;YAACV;YAAiB;YAAQ;YAAM;SAAS,EAAE;YACtFW,OAAO;YACPC,SAAS;QACX;QACAL,SAASC,OAAOD,MAAM;IACxB,EAAE,OAAOM,OAAO;QACdZ,MAAM,0BAA0BY;QAChC,OAAOT;IACT;IAEA,IAAIU;IACJ,IAAI;QACFA,SAASC,KAAKC,KAAK,CAACT;IACtB,EAAE,OAAOM,OAAO;QACdZ,MAAM,wCAAwCY;QAC9C,OAAOT;IACT;IAEA,IAAI,CAACa,MAAMC,OAAO,CAACJ,SAAS;QAC1Bb,MAAM;QACN,OAAOG;IACT;IAEA,MAAMe,QAAQ,AAACL,OAA4BM,IAAI,CAAC,CAACC,QAAUA,OAAOC,SAASnB,KAAKoB,SAAS;IACzF,IAAI,CAACJ,SAAS,CAACF,MAAMC,OAAO,CAACC,MAAMK,MAAM,GAAG;QAC1C,OAAOpB;IACT;IAEA,MAAMqB,eAAeN,MAAMK,MAAM,CAACE,MAAM,CAAC,CAACC,IAAmB,OAAOA,MAAM;IAC1E,OAAO;QAACtB,4BAA4B,IAAIC,IAAImB;IAAa;AAC3D"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { ux } from '@oclif/core';
|
|
3
|
+
import { subdebug } from '@sanity/cli-core';
|
|
4
|
+
import { logSymbols } from '@sanity/cli-core/ux';
|
|
5
|
+
import { execa } from 'execa';
|
|
6
|
+
import { getErrorMessage, toError } from '../../util/getErrorMessage.js';
|
|
7
|
+
const skillsDebug = subdebug('skills:setup');
|
|
8
|
+
/** Source repo for the bundled `skills` CLI. See https://www.sanity.io/docs/ai/skills. */ export const SANITY_SKILLS_REPO = 'sanity-io/agent-toolkit';
|
|
9
|
+
/** Name of the skill we install — must match the entry in the source repo. */ export const SANITY_SKILL_NAME = 'sanity-best-practices';
|
|
10
|
+
/**
|
|
11
|
+
* Absolute path to the bundled `skills` CLI bin. Resolved once at module load
|
|
12
|
+
* via `import.meta.resolve` so we run the version pinned in our package.json
|
|
13
|
+
* instead of paying the `npx -y` registry lookup at runtime.
|
|
14
|
+
*/ export const SKILLS_BIN_PATH = fileURLToPath(import.meta.resolve('skills/bin/cli.mjs', import.meta.url));
|
|
15
|
+
/**
|
|
16
|
+
* Runs the bundled `skills add` globally for the given agents. Failures are
|
|
17
|
+
* surfaced as warnings and never throw — skills install is best-effort and
|
|
18
|
+
* must not abort `sanity init`.
|
|
19
|
+
*/ export async function setupSkills(options) {
|
|
20
|
+
const uniqueAgents = [
|
|
21
|
+
...new Set(options.agents)
|
|
22
|
+
];
|
|
23
|
+
if (uniqueAgents.length === 0) {
|
|
24
|
+
skillsDebug('No agents passed — skipping skills install');
|
|
25
|
+
return {
|
|
26
|
+
installedAgents: [],
|
|
27
|
+
skipped: true
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const args = [
|
|
31
|
+
SKILLS_BIN_PATH,
|
|
32
|
+
'add',
|
|
33
|
+
SANITY_SKILLS_REPO,
|
|
34
|
+
'--skill',
|
|
35
|
+
SANITY_SKILL_NAME,
|
|
36
|
+
'-g',
|
|
37
|
+
...uniqueAgents.flatMap((agent)=>[
|
|
38
|
+
'-a',
|
|
39
|
+
agent
|
|
40
|
+
]),
|
|
41
|
+
'-y'
|
|
42
|
+
];
|
|
43
|
+
skillsDebug('Running: %s %s', process.execPath, args.join(' '));
|
|
44
|
+
try {
|
|
45
|
+
const result = await execa(process.execPath, args, {
|
|
46
|
+
stdio: 'pipe',
|
|
47
|
+
timeout: 90_000
|
|
48
|
+
});
|
|
49
|
+
skillsDebug('skills stdout: %s', result.stdout);
|
|
50
|
+
skillsDebug('skills stderr: %s', result.stderr);
|
|
51
|
+
ux.stdout(`${logSymbols.success} Installed Sanity agent skills for ${uniqueAgents.join(', ')}`);
|
|
52
|
+
return {
|
|
53
|
+
installedAgents: uniqueAgents,
|
|
54
|
+
skipped: false
|
|
55
|
+
};
|
|
56
|
+
} catch (error) {
|
|
57
|
+
skillsDebug('Error installing skills %O', error);
|
|
58
|
+
const err = toError(error);
|
|
59
|
+
ux.warn(`Could not install Sanity agent skills: ${getErrorMessage(error)}`);
|
|
60
|
+
if (error && typeof error === 'object') {
|
|
61
|
+
const { stderr, stdout } = error;
|
|
62
|
+
if (stdout) ux.warn(stdout);
|
|
63
|
+
if (stderr) ux.warn(stderr);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
error: err,
|
|
67
|
+
installedAgents: [],
|
|
68
|
+
skipped: false
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=setupSkills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/skills/setupSkills.ts"],"sourcesContent":["import {fileURLToPath} from 'node:url'\n\nimport {ux} from '@oclif/core'\nimport {subdebug} from '@sanity/cli-core'\nimport {logSymbols} from '@sanity/cli-core/ux'\nimport {execa} from 'execa'\n\nimport {getErrorMessage, toError} from '../../util/getErrorMessage.js'\n\nconst skillsDebug = subdebug('skills:setup')\n\n/** Source repo for the bundled `skills` CLI. See https://www.sanity.io/docs/ai/skills. */\nexport const SANITY_SKILLS_REPO = 'sanity-io/agent-toolkit'\n\n/** Name of the skill we install — must match the entry in the source repo. */\nexport const SANITY_SKILL_NAME = 'sanity-best-practices'\n\n/**\n * Absolute path to the bundled `skills` CLI bin. Resolved once at module load\n * via `import.meta.resolve` so we run the version pinned in our package.json\n * instead of paying the `npx -y` registry lookup at runtime.\n */\nexport const SKILLS_BIN_PATH = fileURLToPath(\n import.meta.resolve('skills/bin/cli.mjs', import.meta.url),\n)\n\ninterface SetupSkillsOptions {\n /** Skills-CLI agent IDs (e.g. 'cursor', 'claude-code') to install for. */\n agents: string[]\n}\n\ninterface SetupSkillsResult {\n /** Deduplicated `--agent` values passed to `skills add`. */\n installedAgents: string[]\n skipped: boolean\n\n error?: Error\n}\n\n/**\n * Runs the bundled `skills add` globally for the given agents. Failures are\n * surfaced as warnings and never throw — skills install is best-effort and\n * must not abort `sanity init`.\n */\nexport async function setupSkills(options: SetupSkillsOptions): Promise<SetupSkillsResult> {\n const uniqueAgents = [...new Set(options.agents)]\n\n if (uniqueAgents.length === 0) {\n skillsDebug('No agents passed — skipping skills install')\n return {installedAgents: [], skipped: true}\n }\n\n const args = [\n SKILLS_BIN_PATH,\n 'add',\n SANITY_SKILLS_REPO,\n '--skill',\n SANITY_SKILL_NAME,\n '-g',\n ...uniqueAgents.flatMap((agent) => ['-a', agent]),\n '-y',\n ]\n\n skillsDebug('Running: %s %s', process.execPath, args.join(' '))\n\n try {\n const result = await execa(process.execPath, args, {stdio: 'pipe', timeout: 90_000})\n skillsDebug('skills stdout: %s', result.stdout)\n skillsDebug('skills stderr: %s', result.stderr)\n ux.stdout(`${logSymbols.success} Installed Sanity agent skills for ${uniqueAgents.join(', ')}`)\n return {installedAgents: uniqueAgents, skipped: false}\n } catch (error) {\n skillsDebug('Error installing skills %O', error)\n const err = toError(error)\n ux.warn(`Could not install Sanity agent skills: ${getErrorMessage(error)}`)\n if (error && typeof error === 'object') {\n const {stderr, stdout} = error as {stderr?: string; stdout?: string}\n if (stdout) ux.warn(stdout)\n if (stderr) ux.warn(stderr)\n }\n return {error: err, installedAgents: [], skipped: false}\n }\n}\n"],"names":["fileURLToPath","ux","subdebug","logSymbols","execa","getErrorMessage","toError","skillsDebug","SANITY_SKILLS_REPO","SANITY_SKILL_NAME","SKILLS_BIN_PATH","resolve","url","setupSkills","options","uniqueAgents","Set","agents","length","installedAgents","skipped","args","flatMap","agent","process","execPath","join","result","stdio","timeout","stdout","stderr","success","error","err","warn"],"mappings":"AAAA,SAAQA,aAAa,QAAO,WAAU;AAEtC,SAAQC,EAAE,QAAO,cAAa;AAC9B,SAAQC,QAAQ,QAAO,mBAAkB;AACzC,SAAQC,UAAU,QAAO,sBAAqB;AAC9C,SAAQC,KAAK,QAAO,QAAO;AAE3B,SAAQC,eAAe,EAAEC,OAAO,QAAO,gCAA+B;AAEtE,MAAMC,cAAcL,SAAS;AAE7B,wFAAwF,GACxF,OAAO,MAAMM,qBAAqB,0BAAyB;AAE3D,4EAA4E,GAC5E,OAAO,MAAM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BAAiB,EAAE;YAAEC,SAAS;QAAK;IACzD;AACF"}
|
package/dist/commands/build.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
2
|
import { SanityCommand } from '@sanity/cli-core';
|
|
3
3
|
import { buildApp } from '../actions/build/buildApp.js';
|
|
4
|
-
import { buildDebug } from '../actions/build/buildDebug.js';
|
|
5
4
|
import { buildStudio } from '../actions/build/buildStudio.js';
|
|
6
5
|
import { shouldAutoUpdate } from '../actions/build/shouldAutoUpdate.js';
|
|
7
6
|
import { determineIsApp } from '../util/determineIsApp.js';
|
|
@@ -52,27 +51,15 @@ export class BuildCommand extends SanityCommand {
|
|
|
52
51
|
flags,
|
|
53
52
|
output
|
|
54
53
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
buildDebug(`Building studio`);
|
|
67
|
-
await buildStudio({
|
|
68
|
-
autoUpdatesEnabled,
|
|
69
|
-
cliConfig,
|
|
70
|
-
flags,
|
|
71
|
-
outDir: this.args.outputDir,
|
|
72
|
-
output,
|
|
73
|
-
workDir
|
|
74
|
-
});
|
|
75
|
-
}
|
|
54
|
+
const buildFunc = isApp ? buildApp : buildStudio;
|
|
55
|
+
await buildFunc({
|
|
56
|
+
autoUpdatesEnabled,
|
|
57
|
+
cliConfig,
|
|
58
|
+
flags,
|
|
59
|
+
outDir: this.args.outputDir,
|
|
60
|
+
output,
|
|
61
|
+
workDir
|
|
62
|
+
});
|
|
76
63
|
}
|
|
77
64
|
}
|
|
78
65
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/build.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {SanityCommand} from '@sanity/cli-core'\n\nimport {buildApp} from '../actions/build/buildApp.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/commands/build.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {SanityCommand} from '@sanity/cli-core'\n\nimport {buildApp} from '../actions/build/buildApp.js'\nimport {buildStudio} from '../actions/build/buildStudio.js'\nimport {shouldAutoUpdate} from '../actions/build/shouldAutoUpdate.js'\nimport {determineIsApp} from '../util/determineIsApp.js'\n\nexport class BuildCommand extends SanityCommand<typeof BuildCommand> {\n static override args = {\n outputDir: Args.directory({description: 'Output directory'}),\n }\n\n static override description = 'Build Sanity Studio into a static bundle'\n\n static override examples = [\n '<%= config.bin %> <%= command.id %>',\n '<%= config.bin %> <%= command.id %> --no-minify --source-maps',\n ]\n\n static override flags = {\n 'auto-updates': Flags.boolean({\n allowNo: true,\n description: 'Enable/disable auto updates of studio versions',\n }),\n minify: Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Enable/disable minifying of built bundles',\n }),\n 'source-maps': Flags.boolean({\n allowNo: true,\n default: false,\n description: 'Enable source maps for built bundles (increases size of bundle)',\n }),\n stats: Flags.boolean({\n default: false,\n description: 'Show stats about the built bundles',\n }),\n yes: Flags.boolean({\n char: 'y',\n default: false,\n description:\n 'Unattended mode, answers \"yes\" to any \"yes/no\" prompt and otherwise uses defaults',\n }),\n }\n\n public async run(): Promise<void> {\n const cliConfig = await this.getCliConfig()\n\n const {flags} = await this.parse(BuildCommand)\n\n const isApp = determineIsApp(cliConfig)\n\n const workDir = (await this.getProjectRoot()).directory\n\n const output = this.output\n\n const autoUpdatesEnabled = shouldAutoUpdate({cliConfig, flags, output})\n\n const buildFunc = isApp ? buildApp : buildStudio\n await buildFunc({\n autoUpdatesEnabled,\n cliConfig,\n flags,\n outDir: this.args.outputDir,\n output,\n workDir,\n })\n }\n}\n"],"names":["Args","Flags","SanityCommand","buildApp","buildStudio","shouldAutoUpdate","determineIsApp","BuildCommand","args","outputDir","directory","description","examples","flags","boolean","allowNo","minify","default","stats","yes","char","run","cliConfig","getCliConfig","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rC,MAAM0B,UAAU;YACdD;YACAP;YACAT;YACAkB,QAAQ,IAAI,CAACvB,IAAI,CAACC,SAAS;YAC3BmB;YACAF;QACF;IACF;AACF"}
|
|
@@ -115,9 +115,9 @@ export class Add extends SanityCommand {
|
|
|
115
115
|
'red',
|
|
116
116
|
'underline'
|
|
117
117
|
], 'HIGHLY')} recommend NOT allowing credentials
|
|
118
|
-
on origins containing wildcards. If you are logged in to a studio
|
|
119
|
-
be able to send requests ${styleText('underline', 'on your behalf')}
|
|
120
|
-
data, from any matching origin. Please tread carefully!
|
|
118
|
+
on origins containing wildcards. If you are logged in to a Sanity studio or an app built with
|
|
119
|
+
the Sanity App SDK, people will be able to send requests ${styleText('underline', 'on your behalf')}
|
|
120
|
+
to read and modify data, from any matching origin. Please tread carefully!
|
|
121
121
|
`);
|
|
122
122
|
} else {
|
|
123
123
|
this.log(oneline`
|
|
@@ -125,8 +125,8 @@ export class Add extends SanityCommand {
|
|
|
125
125
|
Should this origin be allowed to send requests using authentication tokens or
|
|
126
126
|
session cookies? Be aware that any script on this origin will be able to send
|
|
127
127
|
requests ${styleText('underline', 'on your behalf')} to read and modify data if you
|
|
128
|
-
are logged in to a Sanity studio. If this origin hosts a studio
|
|
129
|
-
this, otherwise you should probably answer "No" (n).
|
|
128
|
+
are logged in to a Sanity studio or app. If this origin hosts a studio or an app built with
|
|
129
|
+
the Sanity App SDK, you will need this, otherwise you should probably answer "No" (n).
|
|
130
130
|
`);
|
|
131
131
|
}
|
|
132
132
|
this.log('');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/cors/add.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {confirm, logSymbols} from '@sanity/cli-core/ux'\nimport {oneline} from 'oneline'\n\nimport {filterAndValidateOrigin} from '../../actions/cors/filterAndValidateOrigin.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {createCorsOrigin} from '../../services/cors.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst addCorsDebug = subdebug('cors:add')\n\nexport class Add extends SanityCommand<typeof Add> {\n static override args = {\n origin: Args.string({\n description: 'Origin to allow (e.g., https://example.com)',\n required: true,\n }),\n }\n\n static override description = 'Add a CORS origin to the project'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Interactively add a CORS origin',\n },\n {\n command: '<%= config.bin %> <%= command.id %> http://localhost:3000 --no-credentials',\n description: 'Add a localhost origin without credentials',\n },\n {\n command: '<%= config.bin %> <%= command.id %> https://myapp.com --credentials',\n description: 'Add a production origin with credentials allowed',\n },\n {\n command: '<%= config.bin %> <%= command.id %> https://myapp.com --project-id abc123',\n description: 'Add a CORS origin for a specific project',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to add CORS origin to',\n semantics: 'override',\n }),\n credentials: Flags.boolean({\n allowNo: true,\n default: undefined,\n description: 'Allow credentials (token/cookie) to be sent from this origin',\n required: false,\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(Add)\n const {origin} = args\n\n // Ensure we have project context\n const projectId = await this.getProjectId({\n fallback: () =>\n promptForProject({\n requiredPermissions: [{grant: 'create', permission: 'sanity.project.cors'}],\n }),\n })\n\n // Check if the origin argument looks like a file path and warn\n try {\n const isFile = fs.existsSync(path.join(process.cwd(), args.origin))\n if (isFile) {\n this.warn(`Origin \"${args.origin}?\" Remember to quote values (sanity cors add \"*\")`)\n }\n } catch {\n // Ignore errors checking if it's a file\n }\n\n const filteredOrigin = await filterAndValidateOrigin(origin, this.output)\n const hasWildcard = origin.includes('*')\n\n if (hasWildcard) {\n const confirmed = await this.promptForWildcardConfirmation(origin)\n if (!confirmed) {\n this.error('Operation cancelled', {exit: 1})\n }\n }\n\n const allowCredentials =\n flags.credentials === undefined\n ? await this.promptForCredentials(hasWildcard)\n : Boolean(flags.credentials)\n\n if (filteredOrigin !== origin) {\n this.log(`Normalized origin to: ${filteredOrigin}`)\n }\n\n try {\n const response = await createCorsOrigin({\n allowCredentials,\n origin: filteredOrigin,\n projectId,\n })\n\n addCorsDebug(`CORS origin added successfully`, response)\n\n this.log('CORS origin added successfully')\n } catch (error) {\n const err = error as Error\n\n addCorsDebug(`Error adding CORS origin`, err)\n this.error(`CORS origin addition failed:\\n${err.message}`, {exit: 1})\n }\n }\n\n /**\n * Prompt the user for credentials\n *\n * @param hasWildcard - Whether the origin contains a wildcard\n * @returns - Whether to allow credentials\n */\n private async promptForCredentials(hasWildcard: boolean) {\n this.log('')\n if (hasWildcard) {\n this.log(oneline`\n ${styleText('yellow', `${logSymbols.warning} Warning:`)}\n We ${styleText(['red', 'underline'], 'HIGHLY')} recommend NOT allowing credentials\n on origins containing wildcards. If you are logged in to a studio, people will\n be able to send requests ${styleText('underline', 'on your behalf')} to read and modify\n data, from any matching origin. Please tread carefully!\n `)\n } else {\n this.log(oneline`\n ${styleText('yellow', `${logSymbols.warning} Warning:`)}\n Should this origin be allowed to send requests using authentication tokens or\n session cookies? Be aware that any script on this origin will be able to send\n requests ${styleText('underline', 'on your behalf')} to read and modify data if you\n are logged in to a Sanity studio. If this origin hosts a studio, you will need\n this, otherwise you should probably answer \"No\" (n).\n `)\n }\n\n this.log('')\n\n return confirm({\n default: false,\n message: oneline`\n Allow credentials to be sent from this origin? Please read the warning above.\n `,\n })\n }\n\n /**\n * Prompt the user for wildcard confirmation\n *\n * @param origin - The origin to check for wildcards\n * @returns - Whether to allow the origin\n */\n private async promptForWildcardConfirmation(origin: string) {\n this.log('')\n this.log(styleText('yellow', `${logSymbols.warning} Warning: Examples of allowed origins:`))\n\n if (origin === '*') {\n this.log('- http://www.some-malicious.site')\n this.log('- https://not.what-you-were-expecting.com')\n this.log('- https://high-traffic-site.com')\n this.log('- http://192.168.1.1:8080')\n } else {\n this.log(`- ${origin.replace(/:\\*/, ':1234').replaceAll('*', 'foo')}`)\n this.log(`- ${origin.replace(/:\\*/, ':3030').replaceAll('*', 'foo.bar')}`)\n }\n\n this.log('')\n\n return confirm({\n default: false,\n message: oneline`\n Using wildcards can be ${styleText('red', 'risky')}.\n Are you ${styleText('underline', 'absolutely sure')} you want to allow this origin?`,\n })\n }\n}\n"],"names":["fs","path","styleText","Args","Flags","SanityCommand","subdebug","confirm","logSymbols","oneline","filterAndValidateOrigin","promptForProject","createCorsOrigin","getProjectIdFlag","addCorsDebug","Add","args","origin","string","description","required","examples","command","flags","semantics","credentials","boolean","allowNo","default","undefined","run","parse","projectId","getProjectId","fallback","requiredPermissions","grant","permission","isFile","existsSync","join","process","cwd","warn","filteredOrigin","output","hasWildcard","includes","confirmed","promptForWildcardConfirmation","error","exit","allowCredentials","promptForCredentials","Boolean","log","response","err","message","warning","replace","replaceAll"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxD,SAAQC,OAAO,EAAEC,UAAU,QAAO,sBAAqB;AACvD,SAAQC,OAAO,QAAO,UAAS;AAE/B,SAAQC,uBAAuB,QAAO,gDAA+C;AACrF,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,gBAAgB,QAAO,yBAAwB;AACvD,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,MAAMC,eAAeR,SAAS;AAE9B,OAAO,MAAMS,YAAYV;IACvB,OAAgBW,OAAO;QACrBC,QAAQd,KAAKe,MAAM,CAAC;YAClBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,mCAAkC;IAEhE,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;Y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C;QAE1F,IAAI1C,WAAW,KAAK;YAClB,IAAI,CAACsC,GAAG,CAAC;YACT,IAAI,CAACA,GAAG,CAAC;YACT,IAAI,CAACA,GAAG,CAAC;YACT,IAAI,CAACA,GAAG,CAAC;QACX,OAAO;YACL,IAAI,CAACA,GAAG,CAAC,CAAC,EAAE,EAAEtC,OAAO2C,OAAO,CAAC,OAAO,SAASC,UAAU,CAAC,KAAK,QAAQ;YACrE,IAAI,CAACN,GAAG,CAAC,CAAC,EAAE,EAAEtC,OAAO2C,OAAO,CAAC,OAAO,SAASC,UAAU,CAAC,KAAK,YAAY;QAC3E;QAEA,IAAI,CAACN,GAAG,CAAC;QAET,OAAOhD,QAAQ;YACbqB,SAAS;YACT8B,SAASjD,OAAO,CAAC;6BACM,EAAEP,UAAU,OAAO,SAAS;cAC3C,EAAEA,UAAU,aAAa,mBAAmB,+BAA+B,CAAC;QACtF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/cors/add.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {confirm, logSymbols} from '@sanity/cli-core/ux'\nimport {oneline} from 'oneline'\n\nimport {filterAndValidateOrigin} from '../../actions/cors/filterAndValidateOrigin.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {createCorsOrigin} from '../../services/cors.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst addCorsDebug = subdebug('cors:add')\n\nexport class Add extends SanityCommand<typeof Add> {\n static override args = {\n origin: Args.string({\n description: 'Origin to allow (e.g., https://example.com)',\n required: true,\n }),\n }\n\n static override description = 'Add a CORS origin to the project'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Interactively add a CORS origin',\n },\n {\n command: '<%= config.bin %> <%= command.id %> http://localhost:3000 --no-credentials',\n description: 'Add a localhost origin without credentials',\n },\n {\n command: '<%= config.bin %> <%= command.id %> https://myapp.com --credentials',\n description: 'Add a production origin with credentials allowed',\n },\n {\n command: '<%= config.bin %> <%= command.id %> https://myapp.com --project-id abc123',\n description: 'Add a CORS origin for a specific project',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to add CORS origin to',\n semantics: 'override',\n }),\n credentials: Flags.boolean({\n allowNo: true,\n default: undefined,\n description: 'Allow credentials (token/cookie) to be sent from this origin',\n required: false,\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(Add)\n const {origin} = args\n\n // Ensure we have project context\n const projectId = await this.getProjectId({\n fallback: () =>\n promptForProject({\n requiredPermissions: [{grant: 'create', permission: 'sanity.project.cors'}],\n }),\n })\n\n // Check if the origin argument looks like a file path and warn\n try {\n const isFile = fs.existsSync(path.join(process.cwd(), args.origin))\n if (isFile) {\n this.warn(`Origin \"${args.origin}?\" Remember to quote values (sanity cors add \"*\")`)\n }\n } catch {\n // Ignore errors checking if it's a file\n }\n\n const filteredOrigin = await filterAndValidateOrigin(origin, this.output)\n const hasWildcard = origin.includes('*')\n\n if (hasWildcard) {\n const confirmed = await this.promptForWildcardConfirmation(origin)\n if (!confirmed) {\n this.error('Operation cancelled', {exit: 1})\n }\n }\n\n const allowCredentials =\n flags.credentials === undefined\n ? await this.promptForCredentials(hasWildcard)\n : Boolean(flags.credentials)\n\n if (filteredOrigin !== origin) {\n this.log(`Normalized origin to: ${filteredOrigin}`)\n }\n\n try {\n const response = await createCorsOrigin({\n allowCredentials,\n origin: filteredOrigin,\n projectId,\n })\n\n addCorsDebug(`CORS origin added successfully`, response)\n\n this.log('CORS origin added successfully')\n } catch (error) {\n const err = error as Error\n\n addCorsDebug(`Error adding CORS origin`, err)\n this.error(`CORS origin addition failed:\\n${err.message}`, {exit: 1})\n }\n }\n\n /**\n * Prompt the user for credentials\n *\n * @param hasWildcard - Whether the origin contains a wildcard\n * @returns - Whether to allow credentials\n */\n private async promptForCredentials(hasWildcard: boolean) {\n this.log('')\n if (hasWildcard) {\n this.log(oneline`\n ${styleText('yellow', `${logSymbols.warning} Warning:`)}\n We ${styleText(['red', 'underline'], 'HIGHLY')} recommend NOT allowing credentials\n on origins containing wildcards. If you are logged in to a Sanity studio or an app built with\n the Sanity App SDK, people will be able to send requests ${styleText('underline', 'on your behalf')}\n to read and modify data, from any matching origin. Please tread carefully!\n `)\n } else {\n this.log(oneline`\n ${styleText('yellow', `${logSymbols.warning} Warning:`)}\n Should this origin be allowed to send requests using authentication tokens or\n session cookies? Be aware that any script on this origin will be able to send\n requests ${styleText('underline', 'on your behalf')} to read and modify data if you\n are logged in to a Sanity studio or app. If this origin hosts a studio or an app built with\n the Sanity App SDK, you will need this, otherwise you should probably answer \"No\" (n).\n `)\n }\n\n this.log('')\n\n return confirm({\n default: false,\n message: oneline`\n Allow credentials to be sent from this origin? Please read the warning above.\n `,\n })\n }\n\n /**\n * Prompt the user for wildcard confirmation\n *\n * @param origin - The origin to check for wildcards\n * @returns - Whether to allow the origin\n */\n private async promptForWildcardConfirmation(origin: string) {\n this.log('')\n this.log(styleText('yellow', `${logSymbols.warning} Warning: Examples of allowed origins:`))\n\n if (origin === '*') {\n this.log('- http://www.some-malicious.site')\n this.log('- https://not.what-you-were-expecting.com')\n this.log('- https://high-traffic-site.com')\n this.log('- http://192.168.1.1:8080')\n } else {\n this.log(`- ${origin.replace(/:\\*/, ':1234').replaceAll('*', 'foo')}`)\n this.log(`- ${origin.replace(/:\\*/, ':3030').replaceAll('*', 'foo.bar')}`)\n }\n\n this.log('')\n\n return confirm({\n default: false,\n message: oneline`\n Using wildcards can be ${styleText('red', 'risky')}.\n Are you ${styleText('underline', 'absolutely sure')} you want to allow this origin?`,\n })\n }\n}\n"],"names":["fs","path","styleText","Args","Flags","SanityCommand","subdebug","confirm","logSymbols","oneline","filterAndValidateOrigin","promptForProject","createCorsOrigin","getProjectIdFlag","addCorsDebug","Add","args","origin","string","description","required","examples","command","flags","semantics","credentials","boolean","allowNo","default","undefined","run","parse","projectId","getProjectId","fallback","requiredPermissions","grant","permission","isFile","existsSync","join","process","cwd","warn","filteredOrigin","output","hasWildcard","includes","confirmed","promptForWildcardConfirmation","error","exit","allowCredentials","promptForCredentials","Boolean","log","response","err","message","warning","replace","replaceAll"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxD,SAAQC,OAAO,EAAEC,UAAU,QAAO,sBAAqB;AACvD,SAAQC,OAAO,QAAO,UAAS;AAE/B,SAAQC,uBAAuB,QAAO,gDAA+C;AACrF,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,gBAAgB,QAAO,yBAAwB;AACvD,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,MAAMC,eAAeR,SAAS;AAE9B,OAAO,MAAMS,YAAYV;IACvB,OAAgBW,OAAO;QACrBC,QAAQd,KAAKe,MAAM,CAAC;YAClBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,mCAAkC;IAEhE,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtB,GAAGV,iBAAiB;YAClBM,aAAa;YACbK,WAAW;QACb,EAAE;QACFC,aAAarB,MAAMsB,OAAO,CAAC;YACzBC,SAAS;YACTC,SAASC;YACTV,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,MAAaU,MAAqB;QAChC,MAAM,EAACd,IAAI,EAAEO,KAAK,EAAC,GAAG,MAAM,IAAI,CAACQ,KAAK,CAAChB;QACvC,MAAM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AU,CAAC,KAAK,YAAY;QAC3E;QAEA,IAAI,CAACN,GAAG,CAAC;QAET,OAAOhD,QAAQ;YACbqB,SAAS;YACT8B,SAASjD,OAAO,CAAC;6BACM,EAAEP,UAAU,OAAO,SAAS;cAC3C,EAAEA,UAAU,aAAa,mBAAmB,+BAA+B,CAAC;QACtF;IACF;AACF"}
|
|
@@ -41,6 +41,10 @@ export class DatasetExportCommand extends SanityCommand {
|
|
|
41
41
|
{
|
|
42
42
|
command: '<%= config.bin %> <%= command.id %> staging staging.tar.gz --types products,shops',
|
|
43
43
|
description: 'Export specific document types'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
command: '<%= config.bin %> <%= command.id %> moviedb moviedb.tar.gz --no-strict-asset-verification',
|
|
47
|
+
description: 'Export dataset without aborting on asset verification failures'
|
|
44
48
|
}
|
|
45
49
|
];
|
|
46
50
|
static flags = {
|
|
@@ -72,6 +76,10 @@ export class DatasetExportCommand extends SanityCommand {
|
|
|
72
76
|
default: false,
|
|
73
77
|
description: 'Export only published versions of documents'
|
|
74
78
|
}),
|
|
79
|
+
'no-strict-asset-verification': Flags.boolean({
|
|
80
|
+
default: false,
|
|
81
|
+
description: 'Do not abort the export when an asset fails hash or content-length verification'
|
|
82
|
+
}),
|
|
75
83
|
overwrite: Flags.boolean({
|
|
76
84
|
default: false,
|
|
77
85
|
description: 'Overwrite any file with the same name'
|
|
@@ -183,6 +191,7 @@ dataset: ${dataset.padEnd(46)}`, {
|
|
|
183
191
|
onProgress,
|
|
184
192
|
outputPath,
|
|
185
193
|
raw: flags.raw,
|
|
194
|
+
strictAssetVerification: !flags['no-strict-asset-verification'],
|
|
186
195
|
types: flags.types ? flags.types.split(',') : undefined
|
|
187
196
|
};
|
|
188
197
|
const start = Date.now();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/datasets/export.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\nimport {type Writable} from 'node:stream'\n\nimport {Args, Flags} from '@oclif/core'\nimport {getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {boxen, input, spinner} from '@sanity/cli-core/ux'\nimport {type DatasetsResponse} from '@sanity/client'\nimport {exportDataset, type ExportOptions, type ExportProgress} from '@sanity/export'\nimport prettyMs from 'pretty-ms'\n\nimport {validateDatasetName} from '../../actions/dataset/validateDatasetName.js'\nimport {promptForDataset} from '../../prompts/promptForDataset.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {listDatasets} from '../../services/datasets.js'\nimport {absolutify} from '../../util/absolutify.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst noop = () => null\nconst exportDebug = subdebug('dataset:export')\n\nexport class DatasetExportCommand extends SanityCommand<typeof DatasetExportCommand> {\n static override args = {\n name: Args.string({\n description: 'Name of the dataset to export',\n }),\n // Args are order dependent\n // eslint-disable-next-line perfectionist/sort-objects\n destination: Args.string({\n description: 'Output destination file path',\n }),\n }\n\n static override description =\n 'Export a dataset to a local gzipped tarball. Assets returning 401, 403, or 404 are excluded from the export.'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> moviedb localPath.tar.gz',\n description: 'Export dataset \"moviedb\" to localPath.tar.gz',\n },\n {\n command: '<%= config.bin %> <%= command.id %> moviedb assetless.tar.gz --no-assets',\n description: 'Export dataset without assets',\n },\n {\n command: '<%= config.bin %> <%= command.id %> staging staging.tar.gz --raw',\n description: 'Export raw documents without asset reference rewriting',\n },\n {\n command: '<%= config.bin %> <%= command.id %> staging staging.tar.gz --types products,shops',\n description: 'Export specific document types',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to export dataset from',\n semantics: 'override',\n }),\n 'asset-concurrency': Flags.integer({\n default: 8,\n description: 'Concurrent number of asset downloads',\n }),\n mode: Flags.string({\n default: 'stream',\n description:\n \"Export mode ('cursor' is faster for large datasets but may miss concurrent changes)\",\n options: ['stream', 'cursor'],\n }),\n 'no-assets': Flags.boolean({\n default: false,\n description: 'Export only non-asset documents and remove references to image assets',\n }),\n 'no-compress': Flags.boolean({\n default: false,\n description: 'Skips compressing tarball entries (still generates a gzip file)',\n }),\n 'no-drafts': Flags.boolean({\n default: false,\n description: 'Export only published versions of documents',\n }),\n overwrite: Flags.boolean({\n default: false,\n description: 'Overwrite any file with the same name',\n }),\n raw: Flags.boolean({\n default: false,\n description: 'Extract only documents, without rewriting asset references',\n }),\n types: Flags.string({\n description: 'Defines which document types to export (comma-separated)',\n }),\n }\n\n static override hiddenAliases: string[] = ['dataset:export']\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(DatasetExportCommand)\n const {destination: targetDestination, name: targetDataset} = args\n\n // Get project configuration\n const projectId = await this.getProjectId({\n fallback: () =>\n promptForProject({\n requiredPermissions: [{grant: 'read', permission: 'sanity.project.datasets'}],\n }),\n })\n\n const projectClient = await getProjectCliClient({\n apiVersion: '2023-05-26',\n projectId,\n requireUser: true,\n })\n\n let datasets: DatasetsResponse\n\n try {\n datasets = await listDatasets(projectId)\n } catch (error) {\n exportDebug('Error listing datasets', error)\n this.error(`Failed to list datasets:\\n${error instanceof Error ? error.message : error}`, {\n exit: 1,\n })\n }\n\n // Determine dataset name\n let dataset = targetDataset\n if (!dataset) {\n try {\n // Get default dataset from config (only available when running from a project directory)\n const cliConfig = await this.tryGetCliConfig()\n const defaultDataset = cliConfig.api?.dataset\n\n if (defaultDataset) {\n dataset = defaultDataset\n this.log(`Using default dataset: ${dataset}`)\n } else {\n dataset = await promptForDataset({allowCreation: false, datasets})\n }\n } catch (error) {\n exportDebug('Error selecting dataset', error)\n this.error(`Failed to select dataset:\\n${error instanceof Error ? error.message : error}`, {\n exit: 1,\n })\n }\n }\n\n // Validate dataset name\n const dsError = validateDatasetName(dataset)\n if (dsError) {\n this.error(dsError, {exit: 1})\n }\n\n // Verify existence of dataset before trying to export from it\n if (!datasets.some((set) => set.name === dataset)) {\n this.error(`Dataset with name \"${dataset}\" not found`, {exit: 1})\n }\n\n this.log(\n boxen(\n `Exporting from:\nprojectId: ${projectId.padEnd(44)}\ndataset: ${dataset.padEnd(46)}`,\n {\n borderColor: 'yellow',\n borderStyle: 'round',\n },\n ),\n )\n\n // Determine output path\n let destinationPath = targetDestination\n if (!destinationPath) {\n destinationPath = await this.promptForDestination({dataset})\n }\n\n const outputPath = await this.getOutputPath(destinationPath, dataset, flags)\n if (!outputPath) {\n this.error('Cancelled', {exit: 1})\n }\n\n // Prepare export options\n const {fail, onProgress, succeed} = this.createProgressHandler()\n const exportOptions: ExportOptions = {\n assetConcurrency: flags['asset-concurrency'],\n assets: !flags['no-assets'],\n client: projectClient,\n compress: !flags['no-compress'],\n dataset,\n drafts: !flags['no-drafts'],\n mode: flags.mode === 'cursor' || flags.mode === 'stream' ? flags.mode : undefined,\n onProgress,\n outputPath,\n raw: flags.raw,\n types: flags.types ? flags.types.split(',') : undefined,\n }\n\n const start = Date.now()\n try {\n await exportDataset(exportOptions)\n succeed()\n this.log(`Export finished (${prettyMs(Date.now() - start)})`)\n } catch (error) {\n fail()\n const err = error instanceof Error ? error : new Error(String(error))\n exportDebug('Export failed', err)\n this.error(`Export failed: ${err.message}`, {exit: 1})\n }\n }\n\n private createProgressHandler() {\n let currentSpinner: ReturnType<typeof spinner> | null = null\n let currentStep = ''\n\n const onProgress = (progress: ExportProgress) => {\n if (progress.step !== currentStep) {\n // Complete previous step\n succeed()\n\n // Start new step\n currentStep = progress.step\n currentSpinner = spinner(progress.step).start()\n } else if (progress.step === currentStep && progress.update && currentSpinner) {\n // Update current step with progress info\n currentSpinner.text = `${progress.step} (${progress.current}/${progress.total})`\n }\n }\n\n const succeed = () => {\n currentSpinner?.succeed()\n }\n\n const fail = () => {\n currentSpinner?.fail()\n }\n\n return {fail, onProgress, succeed}\n }\n\n private async getOutputPath(\n destination: string,\n dataset: string,\n flags: {overwrite?: boolean},\n ): Promise<string | Writable> {\n if (destination === '-') {\n return process.stdout\n }\n\n const dstPath = path.isAbsolute(destination)\n ? destination\n : path.resolve(process.cwd(), destination)\n\n const dstStats = await fs.stat(dstPath).catch(noop)\n const looksLikeFile = dstStats ? dstStats.isFile() : path.basename(dstPath).includes('.')\n\n if (!dstStats) {\n const createPath = looksLikeFile ? path.dirname(dstPath) : dstPath\n try {\n await fs.mkdir(createPath, {recursive: true})\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error))\n const errorWithCode = err as Error & {code?: string}\n if (errorWithCode.code === 'EACCES') {\n this.error(\n `Permission denied: Cannot create directory \"${createPath}\". Please check write permissions.`,\n {\n exit: 1,\n },\n )\n } else {\n this.error(`Failed to create directory \"${createPath}\": ${err.message}`, {\n exit: 1,\n })\n }\n }\n }\n\n const finalPath = looksLikeFile ? dstPath : path.join(dstPath, `${dataset}.tar.gz`)\n const finalPathStats = await fs.stat(finalPath).catch(noop)\n\n if (!flags.overwrite && finalPathStats && finalPathStats.isFile()) {\n this.error(`File \"${finalPath}\" already exists. Use --overwrite flag to overwrite it.`, {\n exit: 1,\n })\n }\n\n return finalPath\n }\n\n private promptForDestination(options: {dataset: string; workDir?: string}): Promise<string> {\n const {dataset, workDir = process.cwd()} = options\n\n const defaultPath = path.join(workDir, `${dataset}.tar.gz`)\n\n return input({\n default: defaultPath,\n message: 'Output path:',\n transformer: (value: string) => absolutify(value.trim()),\n validate: (value: string) => {\n const trimmed = value.trim()\n if (!trimmed) {\n return 'Please provide a valid output path'\n }\n return true\n },\n })\n }\n}\n"],"names":["fs","path","Args","Flags","getProjectCliClient","SanityCommand","subdebug","boxen","input","spinner","exportDataset","prettyMs","validateDatasetName","promptForDataset","promptForProject","listDatasets","absolutify","getProjectIdFlag","noop","exportDebug","DatasetExportCommand","args","name","string","description","destination","examples","command","flags","semantics","integer","default","mode","options","boolean","overwrite","raw","types","hiddenAliases","run","parse","targetDestination","targetDataset","projectId","getProjectId","fallback","requiredPermissions","grant","permission","projectClient","apiVersion","requireUser","datasets","error","Error","message","exit","dataset","cliConfig","tryGetCliConfig","defaultDataset","api","log","allowCreation","dsError","some","set","padEnd","borderColor","borderStyle","destinationPath","promptForDestination","outputPath","getOutputPath","fail","onProgress","succeed","createProgressHandler","exportOptions","assetConcurrency","assets","client","compress","drafts","undefined","split","start","Date","now","err","String","currentSpinner","currentStep","progress","step","update","text","current","total","process","stdout","dstPath","isAbsolute","resolve","cwd","dstStats","stat","catch","looksLikeFile","isFile","basename","includes","createPath","dirname","mkdir","recursive","errorWithCode","code","finalPath","join","finalPathStats","workDir","defaultPath","transformer","value","trim","validate","trimmed"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAG5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAC7E,SAAQC,KAAK,EAAEC,KAAK,EAAEC,OAAO,QAAO,sBAAqB;AAEzD,SAAQC,aAAa,QAAgD,iBAAgB;AACrF,OAAOC,cAAc,YAAW;AAEhC,SAAQC,mBAAmB,QAAO,+CAA8C;AAChF,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAAQC,UAAU,QAAO,2BAA0B;AACnD,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,MAAMC,OAAO,IAAM;AACnB,MAAMC,cAAcb,SAAS;AAE7B,OAAO,MAAMc,6BAA6Bf;IACxC,OAAgBgB,OAAO;QACrBC,MAAMpB,KAAKqB,MAAM,CAAC;YAChBC,aAAa;QACf;QACA,2BAA2B;QAC3B,sDAAsD;QACtDC,aAAavB,KAAKqB,MAAM,CAAC;YACvBC,aAAa;QACf;IACF,EAAC;IAED,OAAgBA,cACd,+GAA8G;IAEhH,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;Q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IAAI,KAAK,UAAU;oBACnC,IAAI,CAAChE,KAAK,CACR,CAAC,4CAA4C,EAAE2D,WAAW,kCAAkC,CAAC,EAC7F;wBACExD,MAAM;oBACR;gBAEJ,OAAO;oBACL,IAAI,CAACH,KAAK,CAAC,CAAC,4BAA4B,EAAE2D,WAAW,GAAG,EAAEvB,IAAIlC,OAAO,EAAE,EAAE;wBACvEC,MAAM;oBACR;gBACF;YACF;QACF;QAEA,MAAM8D,YAAYV,gBAAgBP,UAAUpG,KAAKsH,IAAI,CAAClB,SAAS,GAAG5C,QAAQ,OAAO,CAAC;QAClF,MAAM+D,iBAAiB,MAAMxH,GAAG0G,IAAI,CAACY,WAAWX,KAAK,CAACzF;QAEtD,IAAI,CAACU,MAAMO,SAAS,IAAIqF,kBAAkBA,eAAeX,MAAM,IAAI;YACjE,IAAI,CAACxD,KAAK,CAAC,CAAC,MAAM,EAAEiE,UAAU,uDAAuD,CAAC,EAAE;gBACtF9D,MAAM;YACR;QACF;QAEA,OAAO8D;IACT;IAEQ/C,qBAAqBtC,OAA4C,EAAmB;QAC1F,MAAM,EAACwB,OAAO,EAAEgE,UAAUtB,QAAQK,GAAG,EAAE,EAAC,GAAGvE;QAE3C,MAAMyF,cAAczH,KAAKsH,IAAI,CAACE,SAAS,GAAGhE,QAAQ,OAAO,CAAC;QAE1D,OAAOjD,MAAM;YACXuB,SAAS2F;YACTnE,SAAS;YACToE,aAAa,CAACC,QAAkB5G,WAAW4G,MAAMC,IAAI;YACrDC,UAAU,CAACF;gBACT,MAAMG,UAAUH,MAAMC,IAAI;gBAC1B,IAAI,CAACE,SAAS;oBACZ,OAAO;gBACT;gBACA,OAAO;YACT;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/datasets/export.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\nimport {type Writable} from 'node:stream'\n\nimport {Args, Flags} from '@oclif/core'\nimport {getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {boxen, input, spinner} from '@sanity/cli-core/ux'\nimport {type DatasetsResponse} from '@sanity/client'\nimport {exportDataset, type ExportOptions, type ExportProgress} from '@sanity/export'\nimport prettyMs from 'pretty-ms'\n\nimport {validateDatasetName} from '../../actions/dataset/validateDatasetName.js'\nimport {promptForDataset} from '../../prompts/promptForDataset.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {listDatasets} from '../../services/datasets.js'\nimport {absolutify} from '../../util/absolutify.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst noop = () => null\nconst exportDebug = subdebug('dataset:export')\n\nexport class DatasetExportCommand extends SanityCommand<typeof DatasetExportCommand> {\n static override args = {\n name: Args.string({\n description: 'Name of the dataset to export',\n }),\n // Args are order dependent\n // eslint-disable-next-line perfectionist/sort-objects\n destination: Args.string({\n description: 'Output destination file path',\n }),\n }\n\n static override description =\n 'Export a dataset to a local gzipped tarball. Assets returning 401, 403, or 404 are excluded from the export.'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> moviedb localPath.tar.gz',\n description: 'Export dataset \"moviedb\" to localPath.tar.gz',\n },\n {\n command: '<%= config.bin %> <%= command.id %> moviedb assetless.tar.gz --no-assets',\n description: 'Export dataset without assets',\n },\n {\n command: '<%= config.bin %> <%= command.id %> staging staging.tar.gz --raw',\n description: 'Export raw documents without asset reference rewriting',\n },\n {\n command: '<%= config.bin %> <%= command.id %> staging staging.tar.gz --types products,shops',\n description: 'Export specific document types',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> moviedb moviedb.tar.gz --no-strict-asset-verification',\n description: 'Export dataset without aborting on asset verification failures',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to export dataset from',\n semantics: 'override',\n }),\n 'asset-concurrency': Flags.integer({\n default: 8,\n description: 'Concurrent number of asset downloads',\n }),\n mode: Flags.string({\n default: 'stream',\n description:\n \"Export mode ('cursor' is faster for large datasets but may miss concurrent changes)\",\n options: ['stream', 'cursor'],\n }),\n 'no-assets': Flags.boolean({\n default: false,\n description: 'Export only non-asset documents and remove references to image assets',\n }),\n 'no-compress': Flags.boolean({\n default: false,\n description: 'Skips compressing tarball entries (still generates a gzip file)',\n }),\n 'no-drafts': Flags.boolean({\n default: false,\n description: 'Export only published versions of documents',\n }),\n 'no-strict-asset-verification': Flags.boolean({\n default: false,\n description:\n 'Do not abort the export when an asset fails hash or content-length verification',\n }),\n overwrite: Flags.boolean({\n default: false,\n description: 'Overwrite any file with the same name',\n }),\n raw: Flags.boolean({\n default: false,\n description: 'Extract only documents, without rewriting asset references',\n }),\n types: Flags.string({\n description: 'Defines which document types to export (comma-separated)',\n }),\n }\n\n static override hiddenAliases: string[] = ['dataset:export']\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(DatasetExportCommand)\n const {destination: targetDestination, name: targetDataset} = args\n\n // Get project configuration\n const projectId = await this.getProjectId({\n fallback: () =>\n promptForProject({\n requiredPermissions: [{grant: 'read', permission: 'sanity.project.datasets'}],\n }),\n })\n\n const projectClient = await getProjectCliClient({\n apiVersion: '2023-05-26',\n projectId,\n requireUser: true,\n })\n\n let datasets: DatasetsResponse\n\n try {\n datasets = await listDatasets(projectId)\n } catch (error) {\n exportDebug('Error listing datasets', error)\n this.error(`Failed to list datasets:\\n${error instanceof Error ? error.message : error}`, {\n exit: 1,\n })\n }\n\n // Determine dataset name\n let dataset = targetDataset\n if (!dataset) {\n try {\n // Get default dataset from config (only available when running from a project directory)\n const cliConfig = await this.tryGetCliConfig()\n const defaultDataset = cliConfig.api?.dataset\n\n if (defaultDataset) {\n dataset = defaultDataset\n this.log(`Using default dataset: ${dataset}`)\n } else {\n dataset = await promptForDataset({allowCreation: false, datasets})\n }\n } catch (error) {\n exportDebug('Error selecting dataset', error)\n this.error(`Failed to select dataset:\\n${error instanceof Error ? error.message : error}`, {\n exit: 1,\n })\n }\n }\n\n // Validate dataset name\n const dsError = validateDatasetName(dataset)\n if (dsError) {\n this.error(dsError, {exit: 1})\n }\n\n // Verify existence of dataset before trying to export from it\n if (!datasets.some((set) => set.name === dataset)) {\n this.error(`Dataset with name \"${dataset}\" not found`, {exit: 1})\n }\n\n this.log(\n boxen(\n `Exporting from:\nprojectId: ${projectId.padEnd(44)}\ndataset: ${dataset.padEnd(46)}`,\n {\n borderColor: 'yellow',\n borderStyle: 'round',\n },\n ),\n )\n\n // Determine output path\n let destinationPath = targetDestination\n if (!destinationPath) {\n destinationPath = await this.promptForDestination({dataset})\n }\n\n const outputPath = await this.getOutputPath(destinationPath, dataset, flags)\n if (!outputPath) {\n this.error('Cancelled', {exit: 1})\n }\n\n // Prepare export options\n const {fail, onProgress, succeed} = this.createProgressHandler()\n const exportOptions: ExportOptions = {\n assetConcurrency: flags['asset-concurrency'],\n assets: !flags['no-assets'],\n client: projectClient,\n compress: !flags['no-compress'],\n dataset,\n drafts: !flags['no-drafts'],\n mode: flags.mode === 'cursor' || flags.mode === 'stream' ? flags.mode : undefined,\n onProgress,\n outputPath,\n raw: flags.raw,\n strictAssetVerification: !flags['no-strict-asset-verification'],\n types: flags.types ? flags.types.split(',') : undefined,\n }\n\n const start = Date.now()\n try {\n await exportDataset(exportOptions)\n succeed()\n this.log(`Export finished (${prettyMs(Date.now() - start)})`)\n } catch (error) {\n fail()\n const err = error instanceof Error ? error : new Error(String(error))\n exportDebug('Export failed', err)\n this.error(`Export failed: ${err.message}`, {exit: 1})\n }\n }\n\n private createProgressHandler() {\n let currentSpinner: ReturnType<typeof spinner> | null = null\n let currentStep = ''\n\n const onProgress = (progress: ExportProgress) => {\n if (progress.step !== currentStep) {\n // Complete previous step\n succeed()\n\n // Start new step\n currentStep = progress.step\n currentSpinner = spinner(progress.step).start()\n } else if (progress.step === currentStep && progress.update && currentSpinner) {\n // Update current step with progress info\n currentSpinner.text = `${progress.step} (${progress.current}/${progress.total})`\n }\n }\n\n const succeed = () => {\n currentSpinner?.succeed()\n }\n\n const fail = () => {\n currentSpinner?.fail()\n }\n\n return {fail, onProgress, succeed}\n }\n\n private async getOutputPath(\n destination: string,\n dataset: string,\n flags: {overwrite?: boolean},\n ): Promise<string | Writable> {\n if (destination === '-') {\n return process.stdout\n }\n\n const dstPath = path.isAbsolute(destination)\n ? destination\n : path.resolve(process.cwd(), destination)\n\n const dstStats = await fs.stat(dstPath).catch(noop)\n const looksLikeFile = dstStats ? dstStats.isFile() : path.basename(dstPath).includes('.')\n\n if (!dstStats) {\n const createPath = looksLikeFile ? path.dirname(dstPath) : dstPath\n try {\n await fs.mkdir(createPath, {recursive: true})\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error))\n const errorWithCode = err as Error & {code?: string}\n if (errorWithCode.code === 'EACCES') {\n this.error(\n `Permission denied: Cannot create directory \"${createPath}\". Please check write permissions.`,\n {\n exit: 1,\n },\n )\n } else {\n this.error(`Failed to create directory \"${createPath}\": ${err.message}`, {\n exit: 1,\n })\n }\n }\n }\n\n const finalPath = looksLikeFile ? dstPath : path.join(dstPath, `${dataset}.tar.gz`)\n const finalPathStats = await fs.stat(finalPath).catch(noop)\n\n if (!flags.overwrite && finalPathStats && finalPathStats.isFile()) {\n this.error(`File \"${finalPath}\" already exists. Use --overwrite flag to overwrite it.`, {\n exit: 1,\n })\n }\n\n return finalPath\n }\n\n private promptForDestination(options: {dataset: string; workDir?: string}): Promise<string> {\n const {dataset, workDir = process.cwd()} = options\n\n const defaultPath = path.join(workDir, `${dataset}.tar.gz`)\n\n return input({\n default: defaultPath,\n message: 'Output path:',\n transformer: (value: string) => absolutify(value.trim()),\n validate: (value: string) => {\n const trimmed = value.trim()\n if (!trimmed) {\n return 'Please provide a valid output path'\n }\n return true\n },\n })\n }\n}\n"],"names":["fs","path","Args","Flags","getProjectCliClient","SanityCommand","subdebug","boxen","input","spinner","exportDataset","prettyMs","validateDatasetName","promptForDataset","promptForProject","listDatasets","absolutify","getProjectIdFlag","noop","exportDebug","DatasetExportCommand","args","name","string","description","destination","examples","command","flags","semantics","integer","default","mode","options","boolean","overwrite","raw","types","hiddenAliases","run","parse","targetDestination","targetDataset","projectId","getProjectId","fallback","requiredPermissions","grant","permission","projectClient","apiVersion","requireUser","datasets","error","Error","message","exit","dataset","cliConfig","tryGetCliConfig","defaultDataset","api","log","allowCreation","dsError","some","set","padEnd","borderColor","borderStyle","destinationPath","promptForDestination","outputPath","getOutputPath","fail","onProgress","succeed","createProgressHandler","exportOptions","assetConcurrency","assets","client","compress","drafts","undefined","strictAssetVerification","split","start","Date","now","err","String","currentSpinner","currentStep","progress","step","update","text","current","total","process","stdout","dstPath","isAbsolute","resolve","cwd","dstStats","stat","catch","looksLikeFile","isFile","basename","includes","createPath","dirname","mkdir","recursive","errorWithCode","code","finalPath","join","finalPathStats","workDir","defaultPath","transformer","value","trim","validate","trimmed"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAG5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAC7E,SAAQC,KAAK,EAAEC,KAAK,EAAEC,OAAO,QAAO,sBAAqB;AAEzD,SAAQC,aAAa,QAAgD,iBAAgB;AACrF,OAAOC,cAAc,YAAW;AAEhC,SAAQC,mBAAmB,QAAO,+CAA8C;AAChF,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAAQC,UAAU,QAAO,2BAA0B;AACnD,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,MAAMC,OAAO,IAAM;AACnB,MAAMC,cAAcb,SAAS;AAE7B,OAAO,MAAMc,6BAA6Bf;IACxC,OAAgBgB,OAAO;QACrBC,MAAMpB,KAAKqB,MAAM,CAAC;YAChBC,aAAa;QACf;QACA,2BAA2B;QAC3B,sDAAsD;QACtDC,aAAavB,KAAKqB,MAAM,CAAC;YACvBC,aAAa;QACf;IACF,EAAC;I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