@sanity/cli 7.12.0 → 7.12.1
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/dist/actions/build/buildApp.js +1 -1
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStudio.js +1 -1
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/commands/backups/disable.js +4 -4
- package/dist/commands/backups/disable.js.map +1 -1
- package/dist/commands/backups/download.js +7 -7
- package/dist/commands/backups/download.js.map +1 -1
- package/dist/commands/backups/enable.js +4 -4
- package/dist/commands/backups/enable.js.map +1 -1
- package/dist/commands/backups/list.js +7 -7
- package/dist/commands/backups/list.js.map +1 -1
- package/dist/commands/codemod.js +5 -5
- package/dist/commands/codemod.js.map +1 -1
- package/dist/commands/cors/add.js +1 -1
- package/dist/commands/cors/add.js.map +1 -1
- package/dist/commands/cors/delete.js +4 -4
- package/dist/commands/cors/delete.js.map +1 -1
- package/dist/commands/cors/list.js +2 -2
- package/dist/commands/cors/list.js.map +1 -1
- package/dist/commands/datasets/alias/create.js +5 -5
- package/dist/commands/datasets/alias/create.js.map +1 -1
- package/dist/commands/datasets/alias/delete.js +2 -2
- package/dist/commands/datasets/alias/delete.js.map +1 -1
- package/dist/commands/datasets/alias/link.js +5 -5
- package/dist/commands/datasets/alias/link.js.map +1 -1
- package/dist/commands/datasets/alias/unlink.js +3 -3
- package/dist/commands/datasets/alias/unlink.js.map +1 -1
- package/dist/commands/datasets/copy.js +7 -7
- package/dist/commands/datasets/copy.js.map +1 -1
- package/dist/commands/datasets/create.js +3 -3
- package/dist/commands/datasets/create.js.map +1 -1
- package/dist/commands/datasets/delete.js +2 -2
- package/dist/commands/datasets/delete.js.map +1 -1
- package/dist/commands/datasets/embeddings/disable.js +3 -3
- package/dist/commands/datasets/embeddings/disable.js.map +1 -1
- package/dist/commands/datasets/embeddings/enable.js +5 -5
- package/dist/commands/datasets/embeddings/enable.js.map +1 -1
- package/dist/commands/datasets/embeddings/status.js +3 -3
- package/dist/commands/datasets/embeddings/status.js.map +1 -1
- package/dist/commands/datasets/export.js +6 -6
- package/dist/commands/datasets/export.js.map +1 -1
- package/dist/commands/datasets/import.js +3 -3
- package/dist/commands/datasets/import.js.map +1 -1
- package/dist/commands/datasets/list.js +2 -2
- package/dist/commands/datasets/list.js.map +1 -1
- package/dist/commands/datasets/visibility/get.js +2 -2
- package/dist/commands/datasets/visibility/get.js.map +1 -1
- package/dist/commands/datasets/visibility/set.js +3 -3
- package/dist/commands/datasets/visibility/set.js.map +1 -1
- package/dist/commands/deploy.js +2 -2
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.js +2 -2
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/docs/read.js +1 -1
- package/dist/commands/docs/read.js.map +1 -1
- package/dist/commands/docs/search.js +3 -3
- package/dist/commands/docs/search.js.map +1 -1
- package/dist/commands/doctor.js +3 -3
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/documents/create.js +3 -3
- package/dist/commands/documents/create.js.map +1 -1
- package/dist/commands/documents/delete.js +3 -3
- package/dist/commands/documents/delete.js.map +1 -1
- package/dist/commands/documents/get.js +2 -2
- package/dist/commands/documents/get.js.map +1 -1
- package/dist/commands/documents/query.js +2 -2
- package/dist/commands/documents/query.js.map +1 -1
- package/dist/commands/documents/validate.js +3 -3
- package/dist/commands/documents/validate.js.map +1 -1
- package/dist/commands/graphql/deploy.js +13 -13
- package/dist/commands/graphql/deploy.js.map +1 -1
- package/dist/commands/graphql/list.js +2 -2
- package/dist/commands/graphql/list.js.map +1 -1
- package/dist/commands/graphql/undeploy.js +2 -2
- package/dist/commands/graphql/undeploy.js.map +1 -1
- package/dist/commands/hooks/attempt.js +2 -2
- package/dist/commands/hooks/attempt.js.map +1 -1
- package/dist/commands/hooks/create.js +3 -3
- package/dist/commands/hooks/create.js.map +1 -1
- package/dist/commands/hooks/delete.js +4 -4
- package/dist/commands/hooks/delete.js.map +1 -1
- package/dist/commands/hooks/list.js +2 -2
- package/dist/commands/hooks/list.js.map +1 -1
- package/dist/commands/hooks/logs.js +5 -5
- package/dist/commands/hooks/logs.js.map +1 -1
- package/dist/commands/login.js +2 -2
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.js +2 -2
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/manifest/extract.js +3 -3
- package/dist/commands/manifest/extract.js.map +1 -1
- package/dist/commands/mcp/configure.js +4 -4
- package/dist/commands/mcp/configure.js.map +1 -1
- package/dist/commands/media/create-aspect.js +3 -3
- package/dist/commands/media/create-aspect.js.map +1 -1
- package/dist/commands/media/delete-aspect.js +1 -1
- package/dist/commands/media/delete-aspect.js.map +1 -1
- package/dist/commands/media/deploy-aspect.js +4 -4
- package/dist/commands/media/deploy-aspect.js.map +1 -1
- package/dist/commands/media/export.js +7 -7
- package/dist/commands/media/export.js.map +1 -1
- package/dist/commands/media/import.js +6 -6
- package/dist/commands/media/import.js.map +1 -1
- package/dist/commands/migrations/create.js +4 -4
- package/dist/commands/migrations/create.js.map +1 -1
- package/dist/commands/migrations/list.js +2 -2
- package/dist/commands/migrations/list.js.map +1 -1
- package/dist/commands/migrations/run.js +14 -14
- package/dist/commands/migrations/run.js.map +1 -1
- package/dist/commands/openapi/get.js +3 -3
- package/dist/commands/openapi/get.js.map +1 -1
- package/dist/commands/openapi/list.js +2 -2
- package/dist/commands/openapi/list.js.map +1 -1
- package/dist/commands/organizations/create.js +5 -5
- package/dist/commands/organizations/create.js.map +1 -1
- package/dist/commands/organizations/delete.js +6 -6
- package/dist/commands/organizations/delete.js.map +1 -1
- package/dist/commands/organizations/get.js +3 -3
- package/dist/commands/organizations/get.js.map +1 -1
- package/dist/commands/organizations/list.js +2 -2
- package/dist/commands/organizations/list.js.map +1 -1
- package/dist/commands/organizations/update.js +6 -6
- package/dist/commands/organizations/update.js.map +1 -1
- package/dist/commands/preview.js +2 -2
- package/dist/commands/preview.js.map +1 -1
- package/dist/commands/projects/create.js +2 -2
- package/dist/commands/projects/create.js.map +1 -1
- package/dist/commands/projects/list.js +2 -2
- package/dist/commands/projects/list.js.map +1 -1
- package/dist/commands/schemas/delete.js +2 -2
- package/dist/commands/schemas/delete.js.map +1 -1
- package/dist/commands/schemas/deploy.js +2 -2
- package/dist/commands/schemas/deploy.js.map +1 -1
- package/dist/commands/schemas/list.js +1 -1
- package/dist/commands/schemas/list.js.map +1 -1
- package/dist/commands/schemas/validate.js +2 -1
- package/dist/commands/schemas/validate.js.map +1 -1
- package/dist/commands/skills/install.js +2 -2
- package/dist/commands/skills/install.js.map +1 -1
- package/dist/commands/telemetry/disable.js +2 -2
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js +2 -2
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/tokens/create.js +2 -2
- package/dist/commands/tokens/create.js.map +1 -1
- package/dist/commands/tokens/delete.js +2 -2
- package/dist/commands/tokens/delete.js.map +1 -1
- package/dist/commands/tokens/list.js +2 -2
- package/dist/commands/tokens/list.js.map +1 -1
- package/dist/commands/users/invite.js +3 -3
- package/dist/commands/users/invite.js.map +1 -1
- package/oclif.manifest.json +512 -512
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/media/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 {exitCodes, getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {boxen, input, spinner} from '@sanity/cli-core/ux'\nimport {exportDataset, type ExportOptions, type ExportProgress} from '@sanity/export'\nimport prettyMs from 'pretty-ms'\n\nimport {promptForMediaLibrary} from '../../prompts/promptForMediaLibrary.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {getMediaLibraries} from '../../services/mediaLibraries.js'\nimport {absolutify} from '../../util/absolutify.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst noop = () => null\nconst exportDebug = subdebug('media:export')\n\nexport class MediaExportCommand extends SanityCommand<typeof MediaExportCommand> {\n static override args = {\n destination: Args.string({\n description: 'Output destination file path',\n }),\n }\n\n static override description = 'Export file and image assets from a media library (excludes video)'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Export media library interactively',\n },\n {\n command: '<%= config.bin %> <%= command.id %> output.tar.gz',\n description: 'Export media library to output.tar.gz',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --media-library-id my-library-id',\n description: 'Export specific media library',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to export media from',\n semantics: 'override',\n }),\n 'asset-concurrency': Flags.integer({\n default: 8,\n description: 'Concurrent number of asset downloads',\n }),\n 'media-library-id': Flags.string({\n description: 'The id of the target media library',\n }),\n 'no-compress': Flags.boolean({\n default: false,\n description: 'Skips compressing tarball entries (still generates a gzip file)',\n }),\n overwrite: Flags.boolean({\n default: false,\n description: 'Overwrite any file with the same name',\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(MediaExportCommand)\n const {destination: targetDestination} = args\n\n const projectId = await this.getProjectId({fallback: () => promptForProject({})})\n\n const projectClient = await getProjectCliClient({\n apiVersion: 'v2025-02-19',\n projectId,\n requireUser: true,\n })\n\n let mediaLibraries\n try {\n mediaLibraries = await getMediaLibraries(projectId)\n } catch (error) {\n exportDebug('Error listing media libraries', error)\n this.error(\n `Failed to list media libraries:\\n${error instanceof Error ? error.message : error}`,\n {\n exit: 1,\n },\n )\n }\n\n if (mediaLibraries.length === 0) {\n this.error('No active media libraries found in this project', {exit: 1})\n }\n\n let mediaLibraryId = flags['media-library-id']\n if (!mediaLibraryId) {\n if (this.isUnattended()) {\n this.error('Media library ID is required. Pass it with `--media-library-id <id>`.', {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n try {\n mediaLibraryId = await promptForMediaLibrary({mediaLibraries})\n } catch (error) {\n exportDebug('Error selecting media library', error)\n this.error(\n `Failed to select media library:\\n${error instanceof Error ? error.message : error}`,\n {\n exit: 1,\n },\n )\n }\n }\n\n if (!mediaLibraries.some((library) => library.id === mediaLibraryId)) {\n this.error(`Media library with id \"${mediaLibraryId}\" not found`, {exit: 1})\n }\n\n this.log(\n boxen(\n `Exporting from:\nprojectId: ${projectId.padEnd(44)}\nmediaLibraryId: ${mediaLibraryId.padEnd(37)}`,\n {\n borderColor: 'yellow',\n borderStyle: 'round',\n },\n ),\n )\n\n let destinationPath = targetDestination\n if (!destinationPath) {\n destinationPath = this.isUnattended()\n ? path.join(process.cwd(), `${mediaLibraryId}-export.tar.gz`)\n : await this.promptForDestination({mediaLibraryId})\n }\n\n const outputPath = await this.getOutputPath(destinationPath, mediaLibraryId, flags)\n if (!outputPath) {\n this.error('Cancelled', {exit: 1})\n }\n\n const {fail, onProgress, succeed} = this.createProgressHandler()\n const exportOptions: ExportOptions = {\n assetConcurrency: flags['asset-concurrency'],\n client: projectClient,\n compress: !flags['no-compress'],\n mediaLibraryId,\n onProgress,\n outputPath,\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 succeed()\n\n currentStep = progress.step\n currentSpinner = spinner(progress.step).start()\n } else if (progress.step === currentStep && progress.update && currentSpinner) {\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 mediaLibraryId: 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 this.error(`Failed to create directory \"${createPath}\": ${err.message}`, {\n exit: 1,\n })\n }\n }\n\n const finalPath = looksLikeFile\n ? dstPath\n : path.join(dstPath, `${mediaLibraryId}-export.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. Pass \\`--overwrite\\` to replace it.`, {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n\n return finalPath\n }\n\n private promptForDestination(options: {\n mediaLibraryId: string\n workDir?: string\n }): Promise<string> {\n const {mediaLibraryId, workDir = process.cwd()} = options\n\n const defaultPath = path.join(workDir, `${mediaLibraryId}-export.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","exitCodes","getProjectCliClient","SanityCommand","subdebug","boxen","input","spinner","exportDataset","prettyMs","promptForMediaLibrary","promptForProject","getMediaLibraries","absolutify","getProjectIdFlag","noop","exportDebug","MediaExportCommand","args","destination","string","description","examples","command","flags","semantics","integer","default","boolean","overwrite","run","parse","targetDestination","projectId","getProjectId","fallback","projectClient","apiVersion","requireUser","mediaLibraries","error","Error","message","exit","length","mediaLibraryId","isUnattended","USAGE_ERROR","some","library","id","log","padEnd","borderColor","borderStyle","destinationPath","join","process","cwd","promptForDestination","outputPath","getOutputPath","fail","onProgress","succeed","createProgressHandler","exportOptions","assetConcurrency","client","compress","start","Date","now","err","String","currentSpinner","currentStep","progress","step","update","text","current","total","stdout","dstPath","isAbsolute","resolve","dstStats","stat","catch","looksLikeFile","isFile","basename","includes","createPath","dirname","mkdir","recursive","finalPath","finalPathStats","options","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,SAAS,EAAEC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxF,SAAQC,KAAK,EAAEC,KAAK,EAAEC,OAAO,QAAO,sBAAqB;AACzD,SAAQC,aAAa,QAAgD,iBAAgB;AACrF,OAAOC,cAAc,YAAW;AAEhC,SAAQC,qBAAqB,QAAO,yCAAwC;AAC5E,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,iBAAiB,QAAO,mCAAkC;AAClE,SAAQC,UAAU,QAAO,2BAA0B;AACnD,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,MAAMC,OAAO,IAAM;AACnB,MAAMC,cAAcZ,SAAS;AAE7B,OAAO,MAAMa,2BAA2Bd;IACtC,OAAgBe,OAAO;QACrBC,aAAapB,KAAKqB,MAAM,CAAC;YACvBC,aAAa;QACf;IACF,EAAC;IAED,OAAgBA,cAAc,qEAAoE;IAElG,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;KACD,CAAA;IAED,OAAgBG,QAAQ;QACtB,GAAGV,iBAAiB;YAClBO,aAAa;YACbI,WAAW;QACb,EAAE;QACF,qBAAqBzB,MAAM0B,OAAO,CAAC;YACjCC,SAAS;YACTN,aAAa;QACf;QACA,oBAAo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ACF,MAAMvF,GAAGmG,KAAK,CAACF,YAAY;oBAACG,WAAW;gBAAI;YAC7C,EAAE,OAAOzD,OAAO;gBACd,MAAMiC,MAAMjC,iBAAiBC,QAAQD,QAAQ,IAAIC,MAAMiC,OAAOlC;gBAC9D,IAAI,CAACA,KAAK,CAAC,CAAC,4BAA4B,EAAEsD,WAAW,GAAG,EAAErB,IAAI/B,OAAO,EAAE,EAAE;oBACvEC,MAAM;gBACR;YACF;QACF;QAEA,MAAMuD,YAAYR,gBACdN,UACAtF,KAAK0D,IAAI,CAAC4B,SAAS,GAAGvC,eAAe,cAAc,CAAC;QACxD,MAAMsD,iBAAiB,MAAMtG,GAAG2F,IAAI,CAACU,WAAWT,KAAK,CAAC1E;QAEtD,IAAI,CAACS,MAAMK,SAAS,IAAIsE,kBAAkBA,eAAeR,MAAM,IAAI;YACjE,IAAI,CAACnD,KAAK,CAAC,CAAC,MAAM,EAAE0D,UAAU,qDAAqD,CAAC,EAAE;gBACpFvD,MAAM1C,UAAU8C,WAAW;YAC7B;QACF;QAEA,OAAOmD;IACT;IAEQvC,qBAAqByC,OAG5B,EAAmB;QAClB,MAAM,EAACvD,cAAc,EAAEwD,UAAU5C,QAAQC,GAAG,EAAE,EAAC,GAAG0C;QAElD,MAAME,cAAcxG,KAAK0D,IAAI,CAAC6C,SAAS,GAAGxD,eAAe,cAAc,CAAC;QAExE,OAAOvC,MAAM;YACXqB,SAAS2E;YACT5D,SAAS;YACT6D,aAAa,CAACC,QAAkB3F,WAAW2F,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/media/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 {exitCodes, getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {boxen, input, spinner} from '@sanity/cli-core/ux'\nimport {exportDataset, type ExportOptions, type ExportProgress} from '@sanity/export'\nimport prettyMs from 'pretty-ms'\n\nimport {promptForMediaLibrary} from '../../prompts/promptForMediaLibrary.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {getMediaLibraries} from '../../services/mediaLibraries.js'\nimport {absolutify} from '../../util/absolutify.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst noop = () => null\nconst exportDebug = subdebug('media:export')\n\nexport class MediaExportCommand extends SanityCommand<typeof MediaExportCommand> {\n static override args = {\n destination: Args.string({\n description: 'Output destination file path',\n }),\n }\n\n static override description = 'Export file and image assets from a media library (excludes video)'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Export media library interactively',\n },\n {\n command: '<%= config.bin %> <%= command.id %> output.tar.gz',\n description: 'Export media library to output.tar.gz',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --media-library-id my-library-id',\n description: 'Export specific media library',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to export media from',\n semantics: 'override',\n }),\n 'asset-concurrency': Flags.integer({\n default: 8,\n description: 'Concurrent number of asset downloads',\n }),\n 'media-library-id': Flags.string({\n description: 'The id of the target media library',\n }),\n 'no-compress': Flags.boolean({\n default: false,\n description: 'Skips compressing tarball entries (still generates a gzip file)',\n }),\n overwrite: Flags.boolean({\n default: false,\n description: 'Overwrite any file with the same name',\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(MediaExportCommand)\n const {destination: targetDestination} = args\n\n const projectId = await this.getProjectId({fallback: () => promptForProject({})})\n\n const projectClient = await getProjectCliClient({\n apiVersion: 'v2025-02-19',\n projectId,\n requireUser: true,\n })\n\n let mediaLibraries\n try {\n mediaLibraries = await getMediaLibraries(projectId)\n } catch (error) {\n exportDebug('Error listing media libraries', error)\n this.error(\n `Failed to list media libraries:\\n${error instanceof Error ? error.message : error}`,\n {\n exit: exitCodes.RUNTIME_ERROR,\n },\n )\n }\n\n if (mediaLibraries.length === 0) {\n this.error('No active media libraries found in this project', {exit: exitCodes.RUNTIME_ERROR})\n }\n\n let mediaLibraryId = flags['media-library-id']\n if (!mediaLibraryId) {\n if (this.isUnattended()) {\n this.error('Media library ID is required. Pass it with `--media-library-id <id>`.', {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n try {\n mediaLibraryId = await promptForMediaLibrary({mediaLibraries})\n } catch (error) {\n exportDebug('Error selecting media library', error)\n this.error(\n `Failed to select media library:\\n${error instanceof Error ? error.message : error}`,\n {\n exit: exitCodes.RUNTIME_ERROR,\n },\n )\n }\n }\n\n if (!mediaLibraries.some((library) => library.id === mediaLibraryId)) {\n this.error(`Media library with id \"${mediaLibraryId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n this.log(\n boxen(\n `Exporting from:\nprojectId: ${projectId.padEnd(44)}\nmediaLibraryId: ${mediaLibraryId.padEnd(37)}`,\n {\n borderColor: 'yellow',\n borderStyle: 'round',\n },\n ),\n )\n\n let destinationPath = targetDestination\n if (!destinationPath) {\n destinationPath = this.isUnattended()\n ? path.join(process.cwd(), `${mediaLibraryId}-export.tar.gz`)\n : await this.promptForDestination({mediaLibraryId})\n }\n\n const outputPath = await this.getOutputPath(destinationPath, mediaLibraryId, flags)\n if (!outputPath) {\n this.error('Cancelled', {exit: exitCodes.RUNTIME_ERROR})\n }\n\n const {fail, onProgress, succeed} = this.createProgressHandler()\n const exportOptions: ExportOptions = {\n assetConcurrency: flags['asset-concurrency'],\n client: projectClient,\n compress: !flags['no-compress'],\n mediaLibraryId,\n onProgress,\n outputPath,\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: exitCodes.RUNTIME_ERROR})\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 succeed()\n\n currentStep = progress.step\n currentSpinner = spinner(progress.step).start()\n } else if (progress.step === currentStep && progress.update && currentSpinner) {\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 mediaLibraryId: 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 this.error(`Failed to create directory \"${createPath}\": ${err.message}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n const finalPath = looksLikeFile\n ? dstPath\n : path.join(dstPath, `${mediaLibraryId}-export.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. Pass \\`--overwrite\\` to replace it.`, {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n\n return finalPath\n }\n\n private promptForDestination(options: {\n mediaLibraryId: string\n workDir?: string\n }): Promise<string> {\n const {mediaLibraryId, workDir = process.cwd()} = options\n\n const defaultPath = path.join(workDir, `${mediaLibraryId}-export.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","exitCodes","getProjectCliClient","SanityCommand","subdebug","boxen","input","spinner","exportDataset","prettyMs","promptForMediaLibrary","promptForProject","getMediaLibraries","absolutify","getProjectIdFlag","noop","exportDebug","MediaExportCommand","args","destination","string","description","examples","command","flags","semantics","integer","default","boolean","overwrite","run","parse","targetDestination","projectId","getProjectId","fallback","projectClient","apiVersion","requireUser","mediaLibraries","error","Error","message","exit","RUNTIME_ERROR","length","mediaLibraryId","isUnattended","USAGE_ERROR","some","library","id","log","padEnd","borderColor","borderStyle","destinationPath","join","process","cwd","promptForDestination","outputPath","getOutputPath","fail","onProgress","succeed","createProgressHandler","exportOptions","assetConcurrency","client","compress","start","Date","now","err","String","currentSpinner","currentStep","progress","step","update","text","current","total","stdout","dstPath","isAbsolute","resolve","dstStats","stat","catch","looksLikeFile","isFile","basename","includes","createPath","dirname","mkdir","recursive","finalPath","finalPathStats","options","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,SAAS,EAAEC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxF,SAAQC,KAAK,EAAEC,KAAK,EAAEC,OAAO,QAAO,sBAAqB;AACzD,SAAQC,aAAa,QAAgD,iBAAgB;AACrF,OAAOC,cAAc,YAAW;AAEhC,SAAQC,qBAAqB,QAAO,yCAAwC;AAC5E,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,iBAAiB,QAAO,mCAAkC;AAClE,SAAQC,UAAU,QAAO,2BAA0B;AACnD,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,MAAMC,OAAO,IAAM;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EA,OAAOmD;IACT;IAEQvC,qBAAqByC,OAG5B,EAAmB;QAClB,MAAM,EAACvD,cAAc,EAAEwD,UAAU5C,QAAQC,GAAG,EAAE,EAAC,GAAG0C;QAElD,MAAME,cAAczG,KAAK2D,IAAI,CAAC6C,SAAS,GAAGxD,eAAe,cAAc,CAAC;QAExE,OAAOxC,MAAM;YACXqB,SAAS4E;YACT7D,SAAS;YACT8D,aAAa,CAACC,QAAkB5F,WAAW4F,MAAMC,IAAI;YACrDC,UAAU,CAACF;gBACT,MAAMG,UAAUH,MAAMC,IAAI;gBAC1B,IAAI,CAACE,SAAS;oBACZ,OAAO;gBACT;gBACA,OAAO;YACT;QACF;IACF;AACF"}
|
|
@@ -58,12 +58,12 @@ export class MediaImportCommand extends SanityCommand {
|
|
|
58
58
|
} catch (error) {
|
|
59
59
|
importMediaDebug('Error listing media libraries', error);
|
|
60
60
|
this.error(`Failed to list media libraries:\n${error instanceof Error ? error.message : error}`, {
|
|
61
|
-
exit:
|
|
61
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
if (mediaLibraries.length === 0) {
|
|
65
65
|
this.error('No active media libraries found in this project', {
|
|
66
|
-
exit:
|
|
66
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
let mediaLibraryId = flags['media-library-id'];
|
|
@@ -80,13 +80,13 @@ export class MediaImportCommand extends SanityCommand {
|
|
|
80
80
|
} catch (error) {
|
|
81
81
|
importMediaDebug('Error selecting media library', error);
|
|
82
82
|
this.error(`Failed to select media library:\n${error instanceof Error ? error.message : error}`, {
|
|
83
|
-
exit:
|
|
83
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
if (!mediaLibraries.some((library)=>library.id === mediaLibraryId)) {
|
|
88
88
|
this.error(`Media library with id "${mediaLibraryId}" not found`, {
|
|
89
|
-
exit:
|
|
89
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
const projectClient = await getProjectCliClient({
|
|
@@ -138,11 +138,11 @@ export class MediaImportCommand extends SanityCommand {
|
|
|
138
138
|
process.once('SIGINT', ()=>{
|
|
139
139
|
subscription.unsubscribe();
|
|
140
140
|
spin.fail('Import interrupted.');
|
|
141
|
-
process.exit(
|
|
141
|
+
process.exit(exitCodes.SIGINT);
|
|
142
142
|
});
|
|
143
143
|
}).catch((error)=>{
|
|
144
144
|
this.error(styleText('red', error.message), {
|
|
145
|
-
exit:
|
|
145
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
146
146
|
});
|
|
147
147
|
});
|
|
148
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/media/import.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, getProjectCliClient, SanityCommand} from '@sanity/cli-core'\nimport {boxen, spinner} from '@sanity/cli-core/ux'\nimport {SanityClient} from '@sanity/client'\nimport {type OperatorFunction, pipe, scan, tap} from 'rxjs'\n\nimport {importer, type State} from '../../actions/media/importMedia.js'\nimport {importMediaDebug} from '../../actions/media/importMediaDebug.js'\nimport {promptForMediaLibrary} from '../../prompts/promptForMediaLibrary.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {getMediaLibraries} from '../../services/mediaLibraries.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nexport class MediaImportCommand extends SanityCommand<typeof MediaImportCommand> {\n static override args = {\n source: Args.string({\n description: 'Image file or folder to import from',\n required: true,\n }),\n }\n\n static override description = 'Import a set of assets to the target media library.'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> products',\n description: 'Import all assets from the \"products\" directory',\n },\n {\n command: '<%= config.bin %> <%= command.id %> gallery.tar.gz',\n description: 'Import all assets from \"gallery\" archive',\n },\n {\n command: '<%= config.bin %> <%= command.id %> products --replace-aspects',\n description: 'Import all assets from the \"products\" directory and replace aspects',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to import media to',\n semantics: 'override',\n }),\n 'media-library-id': Flags.string({\n description: 'The id of the target media library',\n }),\n 'replace-aspects': Flags.boolean({\n description:\n 'Replace existing aspect data. All versions will be replaced (e.g. published and draft aspect data)',\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(MediaImportCommand)\n const {source} = args\n const replaceAspects = flags['replace-aspects']\n\n const projectId = await this.getProjectId({fallback: () => promptForProject({})})\n\n const cliConfig = await this.tryGetCliConfig()\n const dataset = cliConfig.api?.dataset\n\n let mediaLibraries\n try {\n mediaLibraries = await getMediaLibraries(projectId)\n } catch (error) {\n importMediaDebug('Error listing media libraries', error)\n this.error(\n `Failed to list media libraries:\\n${error instanceof Error ? error.message : error}`,\n {\n exit: 1,\n },\n )\n }\n\n if (mediaLibraries.length === 0) {\n this.error('No active media libraries found in this project', {exit: 1})\n }\n\n let mediaLibraryId = flags['media-library-id']\n if (!mediaLibraryId) {\n if (this.isUnattended()) {\n this.error('Media library ID is required. Pass it with `--media-library-id <id>`.', {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n try {\n mediaLibraryId = await promptForMediaLibrary({mediaLibraries})\n } catch (error) {\n importMediaDebug('Error selecting media library', error)\n this.error(\n `Failed to select media library:\\n${error instanceof Error ? error.message : error}`,\n {\n exit: 1,\n },\n )\n }\n }\n\n if (!mediaLibraries.some((library) => library.id === mediaLibraryId)) {\n this.error(`Media library with id \"${mediaLibraryId}\" not found`, {exit: 1})\n }\n\n const projectClient = await getProjectCliClient({\n apiVersion: 'v2025-02-19',\n dataset,\n perspective: 'drafts',\n projectId,\n requestTagPrefix: 'sanity.mediaLibraryCli.import',\n requireUser: true,\n '~experimental_resource': {\n id: mediaLibraryId,\n type: 'media-library',\n },\n })\n\n this.log(\n boxen(\n `\n Importing to media library: ${mediaLibraryId.padEnd(37)}\n Importing from path: ${source}\n `,\n {\n borderColor: 'yellow',\n borderStyle: 'round',\n },\n ),\n )\n\n const spin = spinner('Beginning import…').start()\n\n await this.importAssets({projectClient, replaceAspects, source, spin})\n }\n\n private async importAssets(options: {\n projectClient: SanityClient\n replaceAspects: boolean\n source: string\n spin: ReturnType<typeof spinner>\n }): Promise<void> {\n const {projectClient, replaceAspects, source, spin} = options\n\n return new Promise<void>((resolve, reject) => {\n const subscription = importer({\n client: projectClient,\n replaceAspects,\n sourcePath: source,\n spinner: spin,\n })\n .pipe(this.reportResult(spin))\n .subscribe({\n complete: () => {\n resolve()\n },\n error: (error: unknown) => {\n const message = error instanceof Error ? error.message : String(error)\n spin.stop()\n reject(new Error(message))\n },\n })\n\n // Cleanup on Ctrl+C\n process.once('SIGINT', () => {\n subscription.unsubscribe()\n spin.fail('Import interrupted.')\n process.exit(130)\n })\n }).catch((error) => {\n this.error(styleText('red', error.message), {exit: 1})\n })\n }\n\n private reportResult(\n spin: ReturnType<typeof spinner>,\n ): OperatorFunction<State, [number, State | undefined]> {\n let previousState: State | undefined\n\n return pipe(\n scan<State, [number, State | undefined]>(\n (processedAssetsCount, state) => [processedAssetsCount[0] + 1, state],\n [0, undefined],\n ),\n tap({\n complete: () => spin.succeed(`Imported ${previousState?.fileCount} assets`),\n next: ([processedAssetsCount, state]) => {\n previousState = state\n spin.text = `${processedAssetsCount} of ${state?.fileCount} assets imported ${styleText('dim', state?.asset.originalFilename ?? '')}`\n },\n }),\n )\n }\n}\n"],"names":["styleText","Args","Flags","exitCodes","getProjectCliClient","SanityCommand","boxen","spinner","pipe","scan","tap","importer","importMediaDebug","promptForMediaLibrary","promptForProject","getMediaLibraries","getProjectIdFlag","MediaImportCommand","args","source","string","description","required","examples","command","flags","semantics","boolean","run","parse","replaceAspects","projectId","getProjectId","fallback","cliConfig","tryGetCliConfig","dataset","api","mediaLibraries","error","Error","message","exit","length","mediaLibraryId","isUnattended","USAGE_ERROR","some","library","id","projectClient","apiVersion","perspective","requestTagPrefix","requireUser","type","log","padEnd","borderColor","borderStyle","spin","start","importAssets","options","Promise","resolve","reject","subscription","client","sourcePath","reportResult","subscribe","complete","String","stop","process","once","unsubscribe","fail","catch","previousState","processedAssetsCount","state","undefined","succeed","fileCount","next","text","asset","originalFilename"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,mBAAmB,EAAEC,aAAa,QAAO,mBAAkB;AAC9E,SAAQC,KAAK,EAAEC,OAAO,QAAO,sBAAqB;AAElD,SAA+BC,IAAI,EAAEC,IAAI,EAAEC,GAAG,QAAO,OAAM;AAE3D,SAAQC,QAAQ,QAAmB,qCAAoC;AACvE,SAAQC,gBAAgB,QAAO,0CAAyC;AACxE,SAAQC,qBAAqB,QAAO,yCAAwC;AAC5E,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,iBAAiB,QAAO,mCAAkC;AAClE,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,OAAO,MAAMC,2BAA2BZ;IACtC,OAAgBa,OAAO;QACrBC,QAAQlB,KAAKmB,MAAM,CAAC;YAClBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,sDAAqD;IAEnF,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtB,GAAGT,iBAAiB;YAClBK,aAAa;YACbK,WAAW;QACb,EAAE;QACF,oBAAoBxB,MAAMkB,MAAM,CAAC;YAC/BC,aAAa;QACf;QACA,mBAAmBnB,MAAMyB,OAAO,CAAC;YAC/BN,aACE;QACJ;IACF,EAAC;IAED,MAAaO,MAAqB;QAChC,MAAM,EAACV,IAAI,EAAEO,KAAK,EAAC,GAAG,MAAM,IA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,IAAIoB;QAEJ,OAAOxE,KACLC,KACE,CAACwE,sBAAsBC,QAAU;gBAACD,oBAAoB,CAAC,EAAE,GAAG;gBAAGC;aAAM,EACrE;YAAC;YAAGC;SAAU,GAEhBzE,IAAI;YACF8D,UAAU,IAAMZ,KAAKwB,OAAO,CAAC,CAAC,SAAS,EAAEJ,eAAeK,UAAU,OAAO,CAAC;YAC1EC,MAAM,CAAC,CAACL,sBAAsBC,MAAM;gBAClCF,gBAAgBE;gBAChBtB,KAAK2B,IAAI,GAAG,GAAGN,qBAAqB,IAAI,EAAEC,OAAOG,UAAU,iBAAiB,EAAErF,UAAU,OAAOkF,OAAOM,MAAMC,oBAAoB,KAAK;YACvI;QACF;IAEJ;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/media/import.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, getProjectCliClient, SanityCommand} from '@sanity/cli-core'\nimport {boxen, spinner} from '@sanity/cli-core/ux'\nimport {SanityClient} from '@sanity/client'\nimport {type OperatorFunction, pipe, scan, tap} from 'rxjs'\n\nimport {importer, type State} from '../../actions/media/importMedia.js'\nimport {importMediaDebug} from '../../actions/media/importMediaDebug.js'\nimport {promptForMediaLibrary} from '../../prompts/promptForMediaLibrary.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {getMediaLibraries} from '../../services/mediaLibraries.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nexport class MediaImportCommand extends SanityCommand<typeof MediaImportCommand> {\n static override args = {\n source: Args.string({\n description: 'Image file or folder to import from',\n required: true,\n }),\n }\n\n static override description = 'Import a set of assets to the target media library.'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> products',\n description: 'Import all assets from the \"products\" directory',\n },\n {\n command: '<%= config.bin %> <%= command.id %> gallery.tar.gz',\n description: 'Import all assets from \"gallery\" archive',\n },\n {\n command: '<%= config.bin %> <%= command.id %> products --replace-aspects',\n description: 'Import all assets from the \"products\" directory and replace aspects',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to import media to',\n semantics: 'override',\n }),\n 'media-library-id': Flags.string({\n description: 'The id of the target media library',\n }),\n 'replace-aspects': Flags.boolean({\n description:\n 'Replace existing aspect data. All versions will be replaced (e.g. published and draft aspect data)',\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(MediaImportCommand)\n const {source} = args\n const replaceAspects = flags['replace-aspects']\n\n const projectId = await this.getProjectId({fallback: () => promptForProject({})})\n\n const cliConfig = await this.tryGetCliConfig()\n const dataset = cliConfig.api?.dataset\n\n let mediaLibraries\n try {\n mediaLibraries = await getMediaLibraries(projectId)\n } catch (error) {\n importMediaDebug('Error listing media libraries', error)\n this.error(\n `Failed to list media libraries:\\n${error instanceof Error ? error.message : error}`,\n {\n exit: exitCodes.RUNTIME_ERROR,\n },\n )\n }\n\n if (mediaLibraries.length === 0) {\n this.error('No active media libraries found in this project', {exit: exitCodes.RUNTIME_ERROR})\n }\n\n let mediaLibraryId = flags['media-library-id']\n if (!mediaLibraryId) {\n if (this.isUnattended()) {\n this.error('Media library ID is required. Pass it with `--media-library-id <id>`.', {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n try {\n mediaLibraryId = await promptForMediaLibrary({mediaLibraries})\n } catch (error) {\n importMediaDebug('Error selecting media library', error)\n this.error(\n `Failed to select media library:\\n${error instanceof Error ? error.message : error}`,\n {\n exit: exitCodes.RUNTIME_ERROR,\n },\n )\n }\n }\n\n if (!mediaLibraries.some((library) => library.id === mediaLibraryId)) {\n this.error(`Media library with id \"${mediaLibraryId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n const projectClient = await getProjectCliClient({\n apiVersion: 'v2025-02-19',\n dataset,\n perspective: 'drafts',\n projectId,\n requestTagPrefix: 'sanity.mediaLibraryCli.import',\n requireUser: true,\n '~experimental_resource': {\n id: mediaLibraryId,\n type: 'media-library',\n },\n })\n\n this.log(\n boxen(\n `\n Importing to media library: ${mediaLibraryId.padEnd(37)}\n Importing from path: ${source}\n `,\n {\n borderColor: 'yellow',\n borderStyle: 'round',\n },\n ),\n )\n\n const spin = spinner('Beginning import…').start()\n\n await this.importAssets({projectClient, replaceAspects, source, spin})\n }\n\n private async importAssets(options: {\n projectClient: SanityClient\n replaceAspects: boolean\n source: string\n spin: ReturnType<typeof spinner>\n }): Promise<void> {\n const {projectClient, replaceAspects, source, spin} = options\n\n return new Promise<void>((resolve, reject) => {\n const subscription = importer({\n client: projectClient,\n replaceAspects,\n sourcePath: source,\n spinner: spin,\n })\n .pipe(this.reportResult(spin))\n .subscribe({\n complete: () => {\n resolve()\n },\n error: (error: unknown) => {\n const message = error instanceof Error ? error.message : String(error)\n spin.stop()\n reject(new Error(message))\n },\n })\n\n // Cleanup on Ctrl+C\n process.once('SIGINT', () => {\n subscription.unsubscribe()\n spin.fail('Import interrupted.')\n process.exit(exitCodes.SIGINT)\n })\n }).catch((error) => {\n this.error(styleText('red', error.message), {exit: exitCodes.RUNTIME_ERROR})\n })\n }\n\n private reportResult(\n spin: ReturnType<typeof spinner>,\n ): OperatorFunction<State, [number, State | undefined]> {\n let previousState: State | undefined\n\n return pipe(\n scan<State, [number, State | undefined]>(\n (processedAssetsCount, state) => [processedAssetsCount[0] + 1, state],\n [0, undefined],\n ),\n tap({\n complete: () => spin.succeed(`Imported ${previousState?.fileCount} assets`),\n next: ([processedAssetsCount, state]) => {\n previousState = state\n spin.text = `${processedAssetsCount} of ${state?.fileCount} assets imported ${styleText('dim', state?.asset.originalFilename ?? '')}`\n },\n }),\n )\n }\n}\n"],"names":["styleText","Args","Flags","exitCodes","getProjectCliClient","SanityCommand","boxen","spinner","pipe","scan","tap","importer","importMediaDebug","promptForMediaLibrary","promptForProject","getMediaLibraries","getProjectIdFlag","MediaImportCommand","args","source","string","description","required","examples","command","flags","semantics","boolean","run","parse","replaceAspects","projectId","getProjectId","fallback","cliConfig","tryGetCliConfig","dataset","api","mediaLibraries","error","Error","message","exit","RUNTIME_ERROR","length","mediaLibraryId","isUnattended","USAGE_ERROR","some","library","id","projectClient","apiVersion","perspective","requestTagPrefix","requireUser","type","log","padEnd","borderColor","borderStyle","spin","start","importAssets","options","Promise","resolve","reject","subscription","client","sourcePath","reportResult","subscribe","complete","String","stop","process","once","unsubscribe","fail","SIGINT","catch","previousState","processedAssetsCount","state","undefined","succeed","fileCount","next","text","asset","originalFilename"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,mBAAmB,EAAEC,aAAa,QAAO,mBAAkB;AAC9E,SAAQC,KAAK,EAAEC,OAAO,QAAO,sBAAqB;AAElD,SAA+BC,IAAI,EAAEC,IAAI,EAAEC,GAAG,QAAO,OAAM;AAE3D,SAAQC,QAAQ,QAAmB,qCAAoC;AACvE,SAAQC,gBAAgB,QAAO,0CAAyC;AACxE,SAAQC,qBAAqB,QAAO,yCAAwC;AAC5E,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,iBAAiB,QAAO,mCAAkC;AAClE,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,OAAO,MAAMC,2BAA2BZ;IACtC,OAAgBa,OAAO;QACrBC,QAAQlB,KAAKmB,MAAM,CAAC;YAClBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,sDAAqD;IAEnF,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtB,GAAGT,iBAAiB;YAClBK,aAAa;YACbK,WAAW;QACb,EAAE;QACF,oBAAoBxB,MAAMkB,MAAM,CAAC;YAC/BC,aAAa;QACf;QACA,mBAAmBnB,MAAMyB,OAAO,CAAC;YAC/BN,aAC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ACvC,UAAU6E,MAAM;YAC/B;QACF,GAAGC,KAAK,CAAC,CAAC1C;YACR,IAAI,CAACA,KAAK,CAACvC,UAAU,OAAOuC,MAAME,OAAO,GAAG;gBAACC,MAAMvC,UAAUwC,aAAa;YAAA;QAC5E;IACF;IAEQ4B,aACNV,IAAgC,EACsB;QACtD,IAAIqB;QAEJ,OAAO1E,KACLC,KACE,CAAC0E,sBAAsBC,QAAU;gBAACD,oBAAoB,CAAC,EAAE,GAAG;gBAAGC;aAAM,EACrE;YAAC;YAAGC;SAAU,GAEhB3E,IAAI;YACF+D,UAAU,IAAMZ,KAAKyB,OAAO,CAAC,CAAC,SAAS,EAAEJ,eAAeK,UAAU,OAAO,CAAC;YAC1EC,MAAM,CAAC,CAACL,sBAAsBC,MAAM;gBAClCF,gBAAgBE;gBAChBvB,KAAK4B,IAAI,GAAG,GAAGN,qBAAqB,IAAI,EAAEC,OAAOG,UAAU,iBAAiB,EAAEvF,UAAU,OAAOoF,OAAOM,MAAMC,oBAAoB,KAAK;YACvI;QACF;IAEJ;AACF"}
|
|
@@ -2,7 +2,7 @@ import { access, mkdir, writeFile } from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { styleText } from 'node:util';
|
|
4
4
|
import { Args } from '@oclif/core';
|
|
5
|
-
import { SanityCommand } from '@sanity/cli-core';
|
|
5
|
+
import { exitCodes, SanityCommand } from '@sanity/cli-core';
|
|
6
6
|
import { confirm, input, select } from '@sanity/cli-core/ux';
|
|
7
7
|
import { MIGRATIONS_DIRECTORY } from '../../actions/migration/constants.js';
|
|
8
8
|
import { minimalAdvanced, minimalSimple, renameField, renameType, stringToPTE } from '../../actions/migration/templates/index.js';
|
|
@@ -62,7 +62,7 @@ export class CreateMigrationCommand extends SanityCommand {
|
|
|
62
62
|
const sluggedName = title.toLowerCase().normalize('NFD').replaceAll(/\p{Mn}/gu, '').replaceAll(/\s+/g, '-').replaceAll(/[^a-z0-9-]/g, '');
|
|
63
63
|
if (!sluggedName) {
|
|
64
64
|
this.error(`Could not derive a valid migration name from title ${JSON.stringify(title)}. Use a title that contains at least one letter or number.`, {
|
|
65
|
-
exit:
|
|
65
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
const destDir = path.join(workDir, MIGRATIONS_DIRECTORY, sluggedName);
|
|
@@ -93,7 +93,7 @@ export class CreateMigrationCommand extends SanityCommand {
|
|
|
93
93
|
} catch (error) {
|
|
94
94
|
const message = error instanceof Error ? error.message : String(error);
|
|
95
95
|
this.error(`Failed to create migration directory: ${message}`, {
|
|
96
|
-
exit:
|
|
96
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
try {
|
|
@@ -101,7 +101,7 @@ export class CreateMigrationCommand extends SanityCommand {
|
|
|
101
101
|
} catch (error) {
|
|
102
102
|
const message = error instanceof Error ? error.message : String(error);
|
|
103
103
|
this.error(`Failed to create migration file: ${message}`, {
|
|
104
|
-
exit:
|
|
104
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/migrations/create.ts"],"sourcesContent":["import {access, mkdir, writeFile} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Args} from '@oclif/core'\nimport {SanityCommand} from '@sanity/cli-core'\nimport {confirm, input, select} from '@sanity/cli-core/ux'\n\nimport {MIGRATIONS_DIRECTORY} from '../../actions/migration/constants.js'\nimport {\n minimalAdvanced,\n minimalSimple,\n renameField,\n renameType,\n stringToPTE,\n} from '../../actions/migration/templates/index.js'\n\nconst TEMPLATES = [\n {name: 'Minimalistic migration to get you started', template: minimalSimple},\n {name: 'Rename an object type', template: renameType},\n {name: 'Rename a field', template: renameField},\n {name: 'Convert string field to Portable Text', template: stringToPTE},\n {\n name: 'Advanced template using async iterators providing more fine grained control',\n template: minimalAdvanced,\n },\n]\n\nexport class CreateMigrationCommand extends SanityCommand<typeof CreateMigrationCommand> {\n static override args = {\n title: Args.string({\n description: 'Title of migration',\n required: false,\n }),\n }\n\n static override description = 'Create a new migration within your project'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Create a new migration, prompting for title and options',\n },\n {\n command: '<%= config.bin %> <%= command.id %> \"Rename field from location to address\"',\n description: 'Create a new migration with the provided title, prompting for options',\n },\n ]\n\n static override hiddenAliases = ['migration:create']\n\n public async run(): Promise<void> {\n const {args} = await this.parse(CreateMigrationCommand)\n const {directory: workDir} = await this.getProjectRoot()\n\n const title = await this.promptForTitle(args.title)\n const types = await this.promptForDocumentTypes()\n const {template} = await this.promptForTemplate()\n\n const renderedTemplate = (template || minimalSimple)({\n documentTypes: types\n .split(',')\n .map((t) => t.trim())\n .filter(Boolean),\n migrationName: title,\n })\n\n const sluggedName = title\n .toLowerCase()\n .normalize('NFD')\n .replaceAll(/\\p{Mn}/gu, '')\n .replaceAll(/\\s+/g, '-')\n .replaceAll(/[^a-z0-9-]/g, '')\n\n if (!sluggedName) {\n this.error(\n `Could not derive a valid migration name from title ${JSON.stringify(\n title,\n )}. Use a title that contains at least one letter or number.`,\n {exit: 1},\n )\n }\n\n const destDir = path.join(workDir, MIGRATIONS_DIRECTORY, sluggedName)\n const definitionFile = path.join(destDir, 'index.ts')\n\n const dirCreated = await this.createMigrationFile(destDir, definitionFile, renderedTemplate)\n\n if (dirCreated) {\n this.log()\n this.log(`${styleText('green', '✓')} Migration created!`)\n this.log()\n this.log('Next steps:')\n this.log(\n `Open ${styleText(\n 'bold',\n definitionFile,\n )} in your code editor and write the code for your migration.`,\n )\n this.log(\n `Dry run the migration with:\\n\\`${styleText(\n 'bold',\n `sanity migration run ${sluggedName} --project=<projectId> --dataset <dataset> `,\n )}\\``,\n )\n this.log(\n `Run the migration against a dataset with:\\n \\`${styleText(\n 'bold',\n `sanity migration run ${sluggedName} --project=<projectId> --dataset <dataset> --no-dry-run`,\n )}\\``,\n )\n this.log()\n this.log(\n `👉 Learn more about schema and content migrations at ${styleText(\n 'bold',\n 'https://www.sanity.io/docs/schema-and-content-migrations',\n )}`,\n )\n }\n }\n\n private async createMigrationFile(\n destDir: string,\n definitionFile: string,\n renderedTemplate: string,\n ): Promise<boolean> {\n const dirExists = await access(destDir)\n .then(() => true)\n .catch(() => false)\n\n if (dirExists) {\n const shouldOverwrite = await this.promptForOverwrite(destDir)\n if (!shouldOverwrite) return false\n }\n\n try {\n await mkdir(destDir, {recursive: true})\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n this.error(`Failed to create migration directory: ${message}`, {exit: 1})\n }\n\n try {\n await writeFile(definitionFile, renderedTemplate)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n this.error(`Failed to create migration file: ${message}`, {exit: 1})\n }\n\n return true\n }\n\n private async promptForDocumentTypes(): Promise<string> {\n return input({\n message:\n 'Type of documents to migrate. You can add multiple types separated by comma (optional)',\n })\n }\n\n private async promptForOverwrite(destDir: string): Promise<boolean> {\n return confirm({\n default: false,\n message: `Migration directory ${styleText('cyan', destDir)} already exists. Overwrite?`,\n })\n }\n\n private async promptForTemplate(): Promise<{\n name: string\n template: (params: {documentTypes: string[]; migrationName: string}) => string\n }> {\n const templatesByName = Object.fromEntries(TEMPLATES.map((t) => [t.name, t]))\n const templateName = await select({\n choices: TEMPLATES.map((definedTemplate) => ({\n name: definedTemplate.name,\n value: definedTemplate.name,\n })),\n message: 'Select a template',\n })\n\n return templatesByName[templateName]!\n }\n\n private async promptForTitle(providedTitle?: string): Promise<string> {\n if (providedTitle?.trim()) {\n return providedTitle\n }\n\n return input({\n message: 'Title of migration (e.g. \"Rename field from location to address\")',\n validate: (value) => {\n if (!value.trim()) {\n return 'Title cannot be empty'\n }\n\n return true\n },\n })\n }\n}\n"],"names":["access","mkdir","writeFile","path","styleText","Args","SanityCommand","confirm","input","select","MIGRATIONS_DIRECTORY","minimalAdvanced","minimalSimple","renameField","renameType","stringToPTE","TEMPLATES","name","template","CreateMigrationCommand","args","title","string","description","required","examples","command","hiddenAliases","run","parse","directory","workDir","getProjectRoot","promptForTitle","types","promptForDocumentTypes","promptForTemplate","renderedTemplate","documentTypes","split","map","t","trim","filter","Boolean","migrationName","sluggedName","toLowerCase","normalize","replaceAll","error","JSON","stringify","exit","destDir","join","definitionFile","dirCreated","createMigrationFile","log","dirExists","then","catch","shouldOverwrite","promptForOverwrite","recursive","message","Error","String","default","templatesByName","Object","fromEntries","templateName","choices","definedTemplate","value","providedTitle","validate"],"mappings":"AAAA,SAAQA,MAAM,EAAEC,KAAK,EAAEC,SAAS,QAAO,mBAAkB;AACzD,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,QAAO,cAAa;AAChC,SAAQC,aAAa,QAAO,mBAAkB;AAC9C,SAAQC,OAAO,EAAEC,KAAK,EAAEC,MAAM,QAAO,sBAAqB;AAE1D,SAAQC,oBAAoB,QAAO,uCAAsC;AACzE,SACEC,eAAe,EACfC,aAAa,EACbC,WAAW,EACXC,UAAU,EACVC,WAAW,QACN,6CAA4C;AAEnD,MAAMC,YAAY;IAChB;QAACC,MAAM;QAA6CC,UAAUN;IAAa;IAC3E;QAACK,MAAM;QAAyBC,UAAUJ;IAAU;IACpD;QAACG,MAAM;QAAkBC,UAAUL;IAAW;IAC9C;QAACI,MAAM;QAAyCC,UAAUH;IAAW;IACrE;QACEE,MAAM;QACNC,UAAUP;IACZ;CACD;AAED,OAAO,MAAMQ,+BAA+Bb;IAC1C,OAAgBc,OAAO;QACrBC,OAAOhB,KAAKiB,MAAM,CAAC;YACjBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,6CAA4C;IAE1E,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;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Ae,EAAoB;QAClE,OAAO/C,QAAQ;YACb8D,SAAS;YACTH,SAAS,CAAC,oBAAoB,EAAE9D,UAAU,QAAQkD,SAAS,2BAA2B,CAAC;QACzF;IACF;IAEA,MAAclB,oBAGX;QACD,MAAMkC,kBAAkBC,OAAOC,WAAW,CAACxD,UAAUwB,GAAG,CAAC,CAACC,IAAM;gBAACA,EAAExB,IAAI;gBAAEwB;aAAE;QAC3E,MAAMgC,eAAe,MAAMhE,OAAO;YAChCiE,SAAS1D,UAAUwB,GAAG,CAAC,CAACmC,kBAAqB,CAAA;oBAC3C1D,MAAM0D,gBAAgB1D,IAAI;oBAC1B2D,OAAOD,gBAAgB1D,IAAI;gBAC7B,CAAA;YACAiD,SAAS;QACX;QAEA,OAAOI,eAAe,CAACG,aAAa;IACtC;IAEA,MAAcxC,eAAe4C,aAAsB,EAAmB;QACpE,IAAIA,eAAenC,QAAQ;YACzB,OAAOmC;QACT;QAEA,OAAOrE,MAAM;YACX0D,SAAS;YACTY,UAAU,CAACF;gBACT,IAAI,CAACA,MAAMlC,IAAI,IAAI;oBACjB,OAAO;gBACT;gBAEA,OAAO;YACT;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/migrations/create.ts"],"sourcesContent":["import {access, mkdir, writeFile} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Args} from '@oclif/core'\nimport {exitCodes, SanityCommand} from '@sanity/cli-core'\nimport {confirm, input, select} from '@sanity/cli-core/ux'\n\nimport {MIGRATIONS_DIRECTORY} from '../../actions/migration/constants.js'\nimport {\n minimalAdvanced,\n minimalSimple,\n renameField,\n renameType,\n stringToPTE,\n} from '../../actions/migration/templates/index.js'\n\nconst TEMPLATES = [\n {name: 'Minimalistic migration to get you started', template: minimalSimple},\n {name: 'Rename an object type', template: renameType},\n {name: 'Rename a field', template: renameField},\n {name: 'Convert string field to Portable Text', template: stringToPTE},\n {\n name: 'Advanced template using async iterators providing more fine grained control',\n template: minimalAdvanced,\n },\n]\n\nexport class CreateMigrationCommand extends SanityCommand<typeof CreateMigrationCommand> {\n static override args = {\n title: Args.string({\n description: 'Title of migration',\n required: false,\n }),\n }\n\n static override description = 'Create a new migration within your project'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Create a new migration, prompting for title and options',\n },\n {\n command: '<%= config.bin %> <%= command.id %> \"Rename field from location to address\"',\n description: 'Create a new migration with the provided title, prompting for options',\n },\n ]\n\n static override hiddenAliases = ['migration:create']\n\n public async run(): Promise<void> {\n const {args} = await this.parse(CreateMigrationCommand)\n const {directory: workDir} = await this.getProjectRoot()\n\n const title = await this.promptForTitle(args.title)\n const types = await this.promptForDocumentTypes()\n const {template} = await this.promptForTemplate()\n\n const renderedTemplate = (template || minimalSimple)({\n documentTypes: types\n .split(',')\n .map((t) => t.trim())\n .filter(Boolean),\n migrationName: title,\n })\n\n const sluggedName = title\n .toLowerCase()\n .normalize('NFD')\n .replaceAll(/\\p{Mn}/gu, '')\n .replaceAll(/\\s+/g, '-')\n .replaceAll(/[^a-z0-9-]/g, '')\n\n if (!sluggedName) {\n this.error(\n `Could not derive a valid migration name from title ${JSON.stringify(\n title,\n )}. Use a title that contains at least one letter or number.`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n\n const destDir = path.join(workDir, MIGRATIONS_DIRECTORY, sluggedName)\n const definitionFile = path.join(destDir, 'index.ts')\n\n const dirCreated = await this.createMigrationFile(destDir, definitionFile, renderedTemplate)\n\n if (dirCreated) {\n this.log()\n this.log(`${styleText('green', '✓')} Migration created!`)\n this.log()\n this.log('Next steps:')\n this.log(\n `Open ${styleText(\n 'bold',\n definitionFile,\n )} in your code editor and write the code for your migration.`,\n )\n this.log(\n `Dry run the migration with:\\n\\`${styleText(\n 'bold',\n `sanity migration run ${sluggedName} --project=<projectId> --dataset <dataset> `,\n )}\\``,\n )\n this.log(\n `Run the migration against a dataset with:\\n \\`${styleText(\n 'bold',\n `sanity migration run ${sluggedName} --project=<projectId> --dataset <dataset> --no-dry-run`,\n )}\\``,\n )\n this.log()\n this.log(\n `👉 Learn more about schema and content migrations at ${styleText(\n 'bold',\n 'https://www.sanity.io/docs/schema-and-content-migrations',\n )}`,\n )\n }\n }\n\n private async createMigrationFile(\n destDir: string,\n definitionFile: string,\n renderedTemplate: string,\n ): Promise<boolean> {\n const dirExists = await access(destDir)\n .then(() => true)\n .catch(() => false)\n\n if (dirExists) {\n const shouldOverwrite = await this.promptForOverwrite(destDir)\n if (!shouldOverwrite) return false\n }\n\n try {\n await mkdir(destDir, {recursive: true})\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n this.error(`Failed to create migration directory: ${message}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n try {\n await writeFile(definitionFile, renderedTemplate)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n this.error(`Failed to create migration file: ${message}`, {exit: exitCodes.RUNTIME_ERROR})\n }\n\n return true\n }\n\n private async promptForDocumentTypes(): Promise<string> {\n return input({\n message:\n 'Type of documents to migrate. You can add multiple types separated by comma (optional)',\n })\n }\n\n private async promptForOverwrite(destDir: string): Promise<boolean> {\n return confirm({\n default: false,\n message: `Migration directory ${styleText('cyan', destDir)} already exists. Overwrite?`,\n })\n }\n\n private async promptForTemplate(): Promise<{\n name: string\n template: (params: {documentTypes: string[]; migrationName: string}) => string\n }> {\n const templatesByName = Object.fromEntries(TEMPLATES.map((t) => [t.name, t]))\n const templateName = await select({\n choices: TEMPLATES.map((definedTemplate) => ({\n name: definedTemplate.name,\n value: definedTemplate.name,\n })),\n message: 'Select a template',\n })\n\n return templatesByName[templateName]!\n }\n\n private async promptForTitle(providedTitle?: string): Promise<string> {\n if (providedTitle?.trim()) {\n return providedTitle\n }\n\n return input({\n message: 'Title of migration (e.g. \"Rename field from location to address\")',\n validate: (value) => {\n if (!value.trim()) {\n return 'Title cannot be empty'\n }\n\n return true\n },\n })\n }\n}\n"],"names":["access","mkdir","writeFile","path","styleText","Args","exitCodes","SanityCommand","confirm","input","select","MIGRATIONS_DIRECTORY","minimalAdvanced","minimalSimple","renameField","renameType","stringToPTE","TEMPLATES","name","template","CreateMigrationCommand","args","title","string","description","required","examples","command","hiddenAliases","run","parse","directory","workDir","getProjectRoot","promptForTitle","types","promptForDocumentTypes","promptForTemplate","renderedTemplate","documentTypes","split","map","t","trim","filter","Boolean","migrationName","sluggedName","toLowerCase","normalize","replaceAll","error","JSON","stringify","exit","RUNTIME_ERROR","destDir","join","definitionFile","dirCreated","createMigrationFile","log","dirExists","then","catch","shouldOverwrite","promptForOverwrite","recursive","message","Error","String","default","templatesByName","Object","fromEntries","templateName","choices","definedTemplate","value","providedTitle","validate"],"mappings":"AAAA,SAAQA,MAAM,EAAEC,KAAK,EAAEC,SAAS,QAAO,mBAAkB;AACzD,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,QAAO,cAAa;AAChC,SAAQC,SAAS,EAAEC,aAAa,QAAO,mBAAkB;AACzD,SAAQC,OAAO,EAAEC,KAAK,EAAEC,MAAM,QAAO,sBAAqB;AAE1D,SAAQC,oBAAoB,QAAO,uCAAsC;AACzE,SACEC,eAAe,EACfC,aAAa,EACbC,WAAW,EACXC,UAAU,EACVC,WAAW,QACN,6CAA4C;AAEnD,MAAMC,YAAY;IAChB;QAACC,MAAM;QAA6CC,UAAUN;IAAa;IAC3E;QAACK,MAAM;QAAyBC,UAAUJ;IAAU;IACpD;QAACG,MAAM;QAAkBC,UAAUL;IAAW;IAC9C;QAACI,MAAM;QAAyCC,UAAUH;IAAW;IACrE;QACEE,MAAM;QACNC,UAAUP;IACZ;CACD;AAED,OAAO,MAAMQ,+BAA+Bb;IAC1C,OAAgBc,OAAO;QACrBC,OAAOjB,KAAKkB,MAAM,CAAC;YACjBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,6CAA4C;IAE1E,OAAgBE,WAAW;QAC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AUiD,aAAa;YAAA;QAC1F;QAEA,OAAO;IACT;IAEA,MAAcnB,yBAA0C;QACtD,OAAO3B,MAAM;YACX2D,SACE;QACJ;IACF;IAEA,MAAcF,mBAAmBV,OAAe,EAAoB;QAClE,OAAOhD,QAAQ;YACb+D,SAAS;YACTH,SAAS,CAAC,oBAAoB,EAAEhE,UAAU,QAAQoD,SAAS,2BAA2B,CAAC;QACzF;IACF;IAEA,MAAcnB,oBAGX;QACD,MAAMmC,kBAAkBC,OAAOC,WAAW,CAACzD,UAAUwB,GAAG,CAAC,CAACC,IAAM;gBAACA,EAAExB,IAAI;gBAAEwB;aAAE;QAC3E,MAAMiC,eAAe,MAAMjE,OAAO;YAChCkE,SAAS3D,UAAUwB,GAAG,CAAC,CAACoC,kBAAqB,CAAA;oBAC3C3D,MAAM2D,gBAAgB3D,IAAI;oBAC1B4D,OAAOD,gBAAgB3D,IAAI;gBAC7B,CAAA;YACAkD,SAAS;QACX;QAEA,OAAOI,eAAe,CAACG,aAAa;IACtC;IAEA,MAAczC,eAAe6C,aAAsB,EAAmB;QACpE,IAAIA,eAAepC,QAAQ;YACzB,OAAOoC;QACT;QAEA,OAAOtE,MAAM;YACX2D,SAAS;YACTY,UAAU,CAACF;gBACT,IAAI,CAACA,MAAMnC,IAAI,IAAI;oBACjB,OAAO;gBACT;gBAEA,OAAO;YACT;QACF;IACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { styleText } from 'node:util';
|
|
2
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
2
|
+
import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
3
3
|
import { Table } from 'console-table-printer';
|
|
4
4
|
import { resolveMigrations } from '../../actions/migration/resolveMigrations.js';
|
|
5
5
|
const listMigrationDebug = subdebug('migration:list');
|
|
@@ -55,7 +55,7 @@ export class ListMigrationCommand extends SanityCommand {
|
|
|
55
55
|
}
|
|
56
56
|
listMigrationDebug('Failed to list migrations:', error);
|
|
57
57
|
this.error(`List migrations failed: ${error instanceof Error ? error.message : String(error)}`, {
|
|
58
|
-
exit:
|
|
58
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/migrations/list.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {Table} from 'console-table-printer'\n\nimport {resolveMigrations} from '../../actions/migration/resolveMigrations.js'\n\nconst listMigrationDebug = subdebug('migration:list')\n\nexport class ListMigrationCommand extends SanityCommand<typeof ListMigrationCommand> {\n static override description = 'List available migrations'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List all available migrations in the project',\n },\n ]\n\n static override hiddenAliases = ['migration:list']\n\n public async run(): Promise<void> {\n const {directory: workDir} = await this.getProjectRoot()\n\n try {\n const migrations = await resolveMigrations(workDir)\n\n if (migrations.length === 0) {\n this.log('No migrations found in migrations folder of the project')\n this.log(\n `\\nRun ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'title', title: 'Title'},\n ],\n title: `Found ${migrations.length} migrations in project`,\n })\n\n for (const definedMigration of migrations) {\n table.addRow({id: definedMigration.id, title: definedMigration.migration.title})\n }\n table.printTable()\n this.log('\\nRun `sanity migration run <ID>` to run a migration')\n listMigrationDebug(`Successfully listed ${migrations.length} migrations`)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n this.log('No migrations folder found in the project')\n this.log(\n `\\nRun ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\n return\n }\n listMigrationDebug('Failed to list migrations:', error)\n this.error(\n `List migrations failed: ${error instanceof Error ? error.message : String(error)}`,\n {\n exit:
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/migrations/list.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {Table} from 'console-table-printer'\n\nimport {resolveMigrations} from '../../actions/migration/resolveMigrations.js'\n\nconst listMigrationDebug = subdebug('migration:list')\n\nexport class ListMigrationCommand extends SanityCommand<typeof ListMigrationCommand> {\n static override description = 'List available migrations'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List all available migrations in the project',\n },\n ]\n\n static override hiddenAliases = ['migration:list']\n\n public async run(): Promise<void> {\n const {directory: workDir} = await this.getProjectRoot()\n\n try {\n const migrations = await resolveMigrations(workDir)\n\n if (migrations.length === 0) {\n this.log('No migrations found in migrations folder of the project')\n this.log(\n `\\nRun ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'title', title: 'Title'},\n ],\n title: `Found ${migrations.length} migrations in project`,\n })\n\n for (const definedMigration of migrations) {\n table.addRow({id: definedMigration.id, title: definedMigration.migration.title})\n }\n table.printTable()\n this.log('\\nRun `sanity migration run <ID>` to run a migration')\n listMigrationDebug(`Successfully listed ${migrations.length} migrations`)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n this.log('No migrations folder found in the project')\n this.log(\n `\\nRun ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\n return\n }\n listMigrationDebug('Failed to list migrations:', error)\n this.error(\n `List migrations failed: ${error instanceof Error ? error.message : String(error)}`,\n {\n exit: exitCodes.RUNTIME_ERROR,\n },\n )\n }\n }\n}\n"],"names":["styleText","exitCodes","SanityCommand","subdebug","Table","resolveMigrations","listMigrationDebug","ListMigrationCommand","description","examples","command","hiddenAliases","run","directory","workDir","getProjectRoot","migrations","length","log","table","columns","alignment","name","title","definedMigration","addRow","id","migration","printTable","error","code","Error","message","String","exit","RUNT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I,AAACA,MAAgCC,IAAI,KAAK,UAAU;gBACtD,IAAI,CAACZ,GAAG,CAAC;gBACT,IAAI,CAACA,GAAG,CACN,CAAC,MAAM,EAAElB,UAAU,SAAS,oCAAoC,0BAA0B,CAAC;gBAE7F;YACF;YACAM,mBAAmB,8BAA8BuB;YACjD,IAAI,CAACA,KAAK,CACR,CAAC,wBAAwB,EAAEA,iBAAiBE,QAAQF,MAAMG,OAAO,GAAGC,OAAOJ,QAAQ,EACnF;gBACEK,MAAMjC,UAAUkC,aAAa;YAC/B;QAEJ;IACF;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { styleText } from 'node:util';
|
|
3
3
|
import { Args, Flags } from '@oclif/core';
|
|
4
|
-
import { getProjectCliClient, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
4
|
+
import { exitCodes, getProjectCliClient, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
5
5
|
import { confirm, spinner } from '@sanity/cli-core/ux';
|
|
6
6
|
import { DEFAULT_MUTATION_CONCURRENCY, dryRun, MAX_MUTATION_CONCURRENCY, run } from '@sanity/migrate';
|
|
7
7
|
import { Table } from 'console-table-printer';
|
|
@@ -86,14 +86,14 @@ export class RunMigrationCommand extends SanityCommand {
|
|
|
86
86
|
// any other failure (e.g. a syntax error in a migration file).
|
|
87
87
|
if (error.code !== 'ENOENT') {
|
|
88
88
|
this.error(`Failed to list migrations: ${error instanceof Error ? error.message : String(error)}`, {
|
|
89
|
-
exit:
|
|
89
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
if (migrations.length === 0) {
|
|
94
94
|
this.log('\nNo migrations found in the project');
|
|
95
95
|
this.log(`Run ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`);
|
|
96
|
-
this.exit(
|
|
96
|
+
this.exit(exitCodes.RUNTIME_ERROR);
|
|
97
97
|
}
|
|
98
98
|
const table = new Table({
|
|
99
99
|
columns: [
|
|
@@ -118,7 +118,7 @@ export class RunMigrationCommand extends SanityCommand {
|
|
|
118
118
|
}
|
|
119
119
|
table.printTable();
|
|
120
120
|
this.log('\nRun `sanity migration run <ID>` to run a migration');
|
|
121
|
-
this.exit(
|
|
121
|
+
this.exit(exitCodes.RUNTIME_ERROR);
|
|
122
122
|
}
|
|
123
123
|
const cliConfig = await this.getCliConfig();
|
|
124
124
|
const projectId = await this.getProjectId({
|
|
@@ -132,17 +132,17 @@ export class RunMigrationCommand extends SanityCommand {
|
|
|
132
132
|
const apiVersion = ensureApiVersionFormat(flags['api-version'] ?? DEFAULT_API_VERSION);
|
|
133
133
|
if (dataset && !project || project && !dataset) {
|
|
134
134
|
this.error('If either --dataset or --project is provided, both must be provided', {
|
|
135
|
-
exit:
|
|
135
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
if (!project && !projectId) {
|
|
139
139
|
this.error('sanity.cli.js does not contain a project identifier ("api.projectId") and no --project option was provided.', {
|
|
140
|
-
exit:
|
|
140
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
143
|
if (!dataset && !datasetFromConfig) {
|
|
144
144
|
this.error('sanity.cli.js does not contain a dataset identifier ("api.dataset") and no --dataset option was provided.', {
|
|
145
|
-
exit:
|
|
145
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
146
146
|
});
|
|
147
147
|
}
|
|
148
148
|
const candidates = await resolveMigrationScript(workDir, id);
|
|
@@ -150,14 +150,14 @@ export class RunMigrationCommand extends SanityCommand {
|
|
|
150
150
|
if (resolvedScripts.length > 1) {
|
|
151
151
|
// todo: consider prompt user about which one to run? note: it's likely a mistake if multiple files resolve to the same name
|
|
152
152
|
this.error(`Found multiple migrations for "${id}" in ${styleText('cyan', migrationsDirectoryPath)}: \n - ${candidates.map((candidate)=>path.relative(migrationsDirectoryPath, candidate.absolutePath)).join('\n - ')}`, {
|
|
153
|
-
exit:
|
|
153
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
const script = resolvedScripts[0];
|
|
157
157
|
if (!script) {
|
|
158
158
|
this.error(`No migration found for "${id}" in ${styleText('cyan', migrationsDirectoryPath)}. Make sure that the migration file exists and exports a valid migration as its default export.\n
|
|
159
159
|
Tried the following files:\n - ${candidates.map((candidate)=>path.relative(migrationsDirectoryPath, candidate.absolutePath)).join('\n - ')}`, {
|
|
160
|
-
exit:
|
|
160
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
const mod = script.mod;
|
|
@@ -165,25 +165,25 @@ export class RunMigrationCommand extends SanityCommand {
|
|
|
165
165
|
// todo: consider adding support for up/down as separate named exports
|
|
166
166
|
// For now, make sure we reserve the names for future use
|
|
167
167
|
this.error('Named "up"/"down" migration exports are not supported at this time, please export your migration as the default export', {
|
|
168
|
-
exit:
|
|
168
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
const migration = mod.default;
|
|
172
172
|
if (fromExport && !dry) {
|
|
173
173
|
this.error('Can only dry run migrations from a dataset export file', {
|
|
174
|
-
exit:
|
|
174
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
const concurrency = flags.concurrency;
|
|
178
178
|
if (concurrency !== undefined) {
|
|
179
179
|
if (concurrency > MAX_MUTATION_CONCURRENCY) {
|
|
180
180
|
this.error(`Concurrency exceeds the maximum allowed value of ${MAX_MUTATION_CONCURRENCY}`, {
|
|
181
|
-
exit:
|
|
181
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
if (concurrency < 1) {
|
|
185
185
|
this.error(`Concurrency must be a positive number, got ${concurrency}`, {
|
|
186
|
-
exit:
|
|
186
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
189
|
}
|
|
@@ -298,7 +298,7 @@ export class RunMigrationCommand extends SanityCommand {
|
|
|
298
298
|
});
|
|
299
299
|
if (!response) {
|
|
300
300
|
runMigrationDebug('User aborted migration');
|
|
301
|
-
this.exit(
|
|
301
|
+
this.exit(exitCodes.RUNTIME_ERROR);
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/migrations/run.ts"],"sourcesContent":["import path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {confirm, spinner} from '@sanity/cli-core/ux'\nimport {\n type APIConfig,\n DEFAULT_MUTATION_CONCURRENCY,\n dryRun,\n MAX_MUTATION_CONCURRENCY,\n type Migration,\n type MigrationProgress,\n run,\n} from '@sanity/migrate'\nimport {Table} from 'console-table-printer'\n\nimport {DEFAULT_API_VERSION, MIGRATIONS_DIRECTORY} from '../../actions/migration/constants.js'\nimport {ensureApiVersionFormat} from '../../actions/migration/ensureApiVersionFormat.js'\nimport {prettyFormat} from '../../actions/migration/prettyMutationFormatter.js'\nimport {resolveMigrations} from '../../actions/migration/resolveMigrations.js'\nimport {\n isLoadableMigrationScript,\n resolveMigrationScript,\n} from '../../actions/migration/resolveMigrationScript.js'\n\nconst runMigrationDebug = subdebug('migration:run')\n\nexport type RunMigrationFlags = RunMigrationCommand['flags']\n\nexport class RunMigrationCommand extends SanityCommand<typeof RunMigrationCommand> {\n static override args = {\n id: Args.string({\n description: 'ID',\n required: false,\n }),\n }\n\n static override description = 'Run a migration against a dataset'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> <id>',\n description: 'dry run the migration',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> <id> --no-dry-run --project xyz --dataset staging',\n description: 'execute the migration against a dataset',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> <id> --from-export=production.tar.gz --no-dry-run --project xyz --dataset staging',\n description: 'execute the migration using a dataset export as the source',\n },\n ]\n\n static override flags = {\n 'api-version': Flags.string({\n description: `API version to use when migrating. Defaults to ${DEFAULT_API_VERSION}.`,\n }),\n concurrency: Flags.integer({\n default: DEFAULT_MUTATION_CONCURRENCY,\n description: `How many mutation requests to run in parallel. Must be between 1 and ${MAX_MUTATION_CONCURRENCY}. Default: ${DEFAULT_MUTATION_CONCURRENCY}.`,\n }),\n confirm: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Prompt for confirmation before running the migration (default: true). Use --no-confirm to skip.',\n }),\n dataset: Flags.string({\n description:\n 'Dataset to migrate. Defaults to the dataset configured in your Sanity CLI config.',\n }),\n 'dry-run': Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'By default the migration runs in dry mode. Use --no-dry-run to migrate dataset.',\n }),\n 'from-export': Flags.string({\n description:\n 'Use a local dataset export as source for migration instead of calling the Sanity API. Note: this is only supported for dry runs.',\n }),\n progress: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Display progress during migration (default: true). Use --no-progress to hide output.',\n }),\n project: Flags.string({\n description:\n 'Project ID of the dataset to migrate. Defaults to the projectId configured in your Sanity CLI config.',\n }),\n }\n\n static override hiddenAliases = ['migration:run']\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(RunMigrationCommand)\n const {directory: workDir} = await this.getProjectRoot()\n const id = args.id\n const migrationsDirectoryPath = path.join(workDir, MIGRATIONS_DIRECTORY)\n\n // Listing migrations (no id given) only needs a project root, mirroring\n // `sanity migrations list` — it must not require api.projectId/dataset.\n if (!id) {\n this.warn(styleText('red', 'Error: Migration ID must be provided'))\n\n let migrations: Awaited<ReturnType<typeof resolveMigrations>> = []\n try {\n migrations = await resolveMigrations(workDir)\n } catch (error) {\n // A missing migrations folder is expected for a fresh project; surface\n // any other failure (e.g. a syntax error in a migration file).\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n this.error(\n `Failed to list migrations: ${error instanceof Error ? error.message : String(error)}`,\n {exit: 1},\n )\n }\n }\n\n if (migrations.length === 0) {\n this.log('\\nNo migrations found in the project')\n this.log(\n `Run ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\n this.exit(1)\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'title', title: 'Title'},\n ],\n title: `Migrations found in project`,\n })\n\n for (const definedMigration of migrations) {\n table.addRow({id: definedMigration.id, title: definedMigration.migration.title})\n }\n table.printTable()\n this.log('\\nRun `sanity migration run <ID>` to run a migration')\n\n this.exit(1)\n }\n\n const cliConfig = await this.getCliConfig()\n const projectId = await this.getProjectId({deprecatedFlagName: 'project'})\n const datasetFromConfig = cliConfig.api?.dataset\n\n const fromExport = flags['from-export']\n const dry = flags['dry-run']\n const dataset = flags.dataset\n const project = flags.project\n const apiVersion = ensureApiVersionFormat(flags['api-version'] ?? DEFAULT_API_VERSION)\n\n if ((dataset && !project) || (project && !dataset)) {\n this.error('If either --dataset or --project is provided, both must be provided', {exit: 1})\n }\n\n if (!project && !projectId) {\n this.error(\n 'sanity.cli.js does not contain a project identifier (\"api.projectId\") and no --project option was provided.',\n {exit: 1},\n )\n }\n\n if (!dataset && !datasetFromConfig) {\n this.error(\n 'sanity.cli.js does not contain a dataset identifier (\"api.dataset\") and no --dataset option was provided.',\n {exit: 1},\n )\n }\n\n const candidates = await resolveMigrationScript(workDir, id)\n const resolvedScripts = candidates.filter((candidate) => isLoadableMigrationScript(candidate))\n\n if (resolvedScripts.length > 1) {\n // todo: consider prompt user about which one to run? note: it's likely a mistake if multiple files resolve to the same name\n this.error(\n `Found multiple migrations for \"${id}\" in ${styleText('cyan', migrationsDirectoryPath)}: \\n - ${candidates\n .map((candidate) => path.relative(migrationsDirectoryPath, candidate.absolutePath))\n .join('\\n - ')}`,\n {exit: 1},\n )\n }\n\n const script = resolvedScripts[0]\n if (!script) {\n this.error(\n `No migration found for \"${id}\" in ${styleText('cyan', migrationsDirectoryPath)}. Make sure that the migration file exists and exports a valid migration as its default export.\\n\n Tried the following files:\\n - ${candidates\n .map((candidate) => path.relative(migrationsDirectoryPath, candidate.absolutePath))\n .join('\\n - ')}`,\n {exit: 1},\n )\n }\n\n const mod = script.mod\n if ('up' in mod || 'down' in mod) {\n // todo: consider adding support for up/down as separate named exports\n // For now, make sure we reserve the names for future use\n this.error(\n 'Named \"up\"/\"down\" migration exports are not supported at this time, please export your migration as the default export',\n {\n exit: 1,\n },\n )\n }\n\n const migration: Migration = mod.default\n\n if (fromExport && !dry) {\n this.error('Can only dry run migrations from a dataset export file', {exit: 1})\n }\n\n const concurrency = flags.concurrency\n if (concurrency !== undefined) {\n if (concurrency > MAX_MUTATION_CONCURRENCY) {\n this.error(`Concurrency exceeds the maximum allowed value of ${MAX_MUTATION_CONCURRENCY}`, {\n exit: 1,\n })\n }\n\n if (concurrency < 1) {\n this.error(`Concurrency must be a positive number, got ${concurrency}`, {exit: 1})\n }\n }\n\n const projectClient = await getProjectCliClient({\n apiVersion,\n projectId: (project ?? projectId)!,\n requireUser: true,\n })\n const projectConfig = projectClient.config()\n\n const apiConfig: APIConfig = {\n apiHost: projectConfig.apiHost,\n apiVersion,\n dataset: (dataset ?? datasetFromConfig)!,\n projectId: (project ?? projectId)!,\n token: projectConfig.token!,\n } as const\n if (dry) {\n await this.dryRunHandler(id, migration, apiConfig, fromExport)\n return\n }\n\n this.log(\n `\\n${styleText(['yellow', 'bold'], 'Note: During migrations, your webhooks stay active.')}`,\n )\n this.log(\n `To adjust them, launch the management interface with ${styleText('cyan', 'sanity manage')}, navigate to the API settings, and toggle the webhooks before and after the migration as needed.\\n`,\n )\n\n if (flags.confirm) {\n await this.promptConfirmMigrate(apiConfig)\n }\n\n const spin = spinner(`Running migration \"${id}\"`).start()\n try {\n await run(\n {\n api: apiConfig,\n concurrency,\n onProgress: this.createProgress(spin, flags, id, dry, apiConfig, migration),\n },\n migration,\n )\n } finally {\n spin.stop()\n }\n }\n\n private createProgress(\n progressSpinner: ReturnType<typeof spinner>,\n flags: RunMigrationFlags,\n id: string,\n dry: boolean,\n apiConfig: APIConfig,\n migration: Migration,\n ) {\n return function onProgress(progress: MigrationProgress) {\n if (!flags.progress) {\n progressSpinner.stop()\n return\n }\n if (progress.done) {\n progressSpinner.text = `Migration \"${id}\" completed.\n\n Project id: ${styleText('bold', apiConfig.projectId)}\n Dataset: ${styleText('bold', apiConfig.dataset)}\n\n ${progress.documents} documents processed.\n ${progress.mutations} mutations generated.\n ${styleText('green', String(progress.completedTransactions.length))} transactions committed.`\n progressSpinner.stopAndPersist({symbol: styleText('green', '✔')})\n return\n }\n\n for (const transaction of [null, ...progress.currentTransactions]) {\n progressSpinner.text = `Running migration \"${id}\" ${dry ? 'in dry mode...' : '...'}\n\n Project id: ${styleText('bold', apiConfig.projectId)}\n Dataset: ${styleText('bold', apiConfig.dataset)}\n Document type: ${styleText('bold', migration.documentTypes?.join(',') ?? '')}\n\n ${progress.documents} documents processed…\n ${progress.mutations} mutations generated…\n ${styleText('blue', String(progress.pending))} requests pending…\n ${styleText('green', String(progress.completedTransactions.length))} transactions committed.\n\n ${\n transaction && !progress.done\n ? `» ${prettyFormat({indentSize: 2, migration, subject: transaction})}`\n : ''\n }`\n }\n }\n }\n\n private async dryRunHandler(\n id: string,\n migration: Migration,\n apiConfig: APIConfig,\n fromExport: string | undefined,\n ) {\n this.log(`Running migration \"${id}\" in dry mode`)\n\n if (fromExport) {\n this.log(`Using export ${styleText('cyan', fromExport)}`)\n }\n\n this.log()\n this.log(`Project id: ${styleText('bold', apiConfig.projectId)}`)\n this.log(`Dataset: ${styleText('bold', apiConfig.dataset)}`)\n\n for await (const mutation of dryRun({api: apiConfig, exportPath: fromExport}, migration)) {\n if (!mutation) continue\n this.log()\n this.log(\n prettyFormat({\n migration,\n subject: mutation,\n }),\n )\n }\n }\n\n private async promptConfirmMigrate(apiConfig: APIConfig) {\n const response = await confirm({\n message: `This migration will run on the ${styleText(\n ['yellow', 'bold'],\n apiConfig.dataset,\n )} dataset in ${styleText(['yellow', 'bold'], apiConfig.projectId)} project. Are you sure?`,\n })\n\n if (!response) {\n runMigrationDebug('User aborted migration')\n this.exit(1)\n }\n }\n}\n"],"names":["path","styleText","Args","Flags","getProjectCliClient","SanityCommand","subdebug","confirm","spinner","DEFAULT_MUTATION_CONCURRENCY","dryRun","MAX_MUTATION_CONCURRENCY","run","Table","DEFAULT_API_VERSION","MIGRATIONS_DIRECTORY","ensureApiVersionFormat","prettyFormat","resolveMigrations","isLoadableMigrationScript","resolveMigrationScript","runMigrationDebug","RunMigrationCommand","args","id","string","description","required","examples","command","flags","concurrency","integer","default","boolean","allowNo","dataset","progress","project","hiddenAliases","parse","directory","workDir","getProjectRoot","migrationsDirectoryPath","join","warn","migrations","error","code","Error","message","String","exit","length","log","table","columns","alignment","name","title","definedMigration","addRow","migration","printTable","cliConfig","getCliConfig","projectId","getProjectId","deprecatedFlagName","datasetFromConfig","api","fromExport","dry","apiVersion","candidates","resolvedScripts","filter","candidate","map","relative","absolutePath","script","mod","undefined","projectClient","requireUser","projectConfig","config","apiConfig","apiHost","token","dryRunHandler","promptConfirmMigrate","spin","start","onProgress","createProgress","stop","progressSpinner","done","text","documents","mutations","completedTransactions","stopAndPersist","symbol","transaction","currentTransactions","documentTypes","pending","indentSize","subject","mutation","exportPath","response"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAC7E,SAAQC,OAAO,EAAEC,OAAO,QAAO,sBAAqB;AACpD,SAEEC,4BAA4B,EAC5BC,MAAM,EACNC,wBAAwB,EAGxBC,GAAG,QACE,kBAAiB;AACxB,SAAQC,KAAK,QAAO,w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,IAAI,CAAC1D,GAAG;YACR,IAAI,CAACA,GAAG,CACNtC,aAAa;gBACX8C;gBACAiD,SAASC;YACX;QAEJ;IACF;IAEA,MAAcpB,qBAAqBJ,SAAoB,EAAE;QACvD,MAAM0B,WAAW,MAAM5G,QAAQ;YAC7B4C,SAAS,CAAC,+BAA+B,EAAElD,UACzC;gBAAC;gBAAU;aAAO,EAClBwF,UAAUrD,OAAO,EACjB,YAAY,EAAEnC,UAAU;gBAAC;gBAAU;aAAO,EAAEwF,UAAUtB,SAAS,EAAE,uBAAuB,CAAC;QAC7F;QAEA,IAAI,CAACgD,UAAU;YACb9F,kBAAkB;YAClB,IAAI,CAACgC,IAAI,CAAC;QACZ;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/migrations/run.ts"],"sourcesContent":["import path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {confirm, spinner} from '@sanity/cli-core/ux'\nimport {\n type APIConfig,\n DEFAULT_MUTATION_CONCURRENCY,\n dryRun,\n MAX_MUTATION_CONCURRENCY,\n type Migration,\n type MigrationProgress,\n run,\n} from '@sanity/migrate'\nimport {Table} from 'console-table-printer'\n\nimport {DEFAULT_API_VERSION, MIGRATIONS_DIRECTORY} from '../../actions/migration/constants.js'\nimport {ensureApiVersionFormat} from '../../actions/migration/ensureApiVersionFormat.js'\nimport {prettyFormat} from '../../actions/migration/prettyMutationFormatter.js'\nimport {resolveMigrations} from '../../actions/migration/resolveMigrations.js'\nimport {\n isLoadableMigrationScript,\n resolveMigrationScript,\n} from '../../actions/migration/resolveMigrationScript.js'\n\nconst runMigrationDebug = subdebug('migration:run')\n\nexport type RunMigrationFlags = RunMigrationCommand['flags']\n\nexport class RunMigrationCommand extends SanityCommand<typeof RunMigrationCommand> {\n static override args = {\n id: Args.string({\n description: 'ID',\n required: false,\n }),\n }\n\n static override description = 'Run a migration against a dataset'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> <id>',\n description: 'dry run the migration',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> <id> --no-dry-run --project xyz --dataset staging',\n description: 'execute the migration against a dataset',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> <id> --from-export=production.tar.gz --no-dry-run --project xyz --dataset staging',\n description: 'execute the migration using a dataset export as the source',\n },\n ]\n\n static override flags = {\n 'api-version': Flags.string({\n description: `API version to use when migrating. Defaults to ${DEFAULT_API_VERSION}.`,\n }),\n concurrency: Flags.integer({\n default: DEFAULT_MUTATION_CONCURRENCY,\n description: `How many mutation requests to run in parallel. Must be between 1 and ${MAX_MUTATION_CONCURRENCY}. Default: ${DEFAULT_MUTATION_CONCURRENCY}.`,\n }),\n confirm: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Prompt for confirmation before running the migration (default: true). Use --no-confirm to skip.',\n }),\n dataset: Flags.string({\n description:\n 'Dataset to migrate. Defaults to the dataset configured in your Sanity CLI config.',\n }),\n 'dry-run': Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'By default the migration runs in dry mode. Use --no-dry-run to migrate dataset.',\n }),\n 'from-export': Flags.string({\n description:\n 'Use a local dataset export as source for migration instead of calling the Sanity API. Note: this is only supported for dry runs.',\n }),\n progress: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Display progress during migration (default: true). Use --no-progress to hide output.',\n }),\n project: Flags.string({\n description:\n 'Project ID of the dataset to migrate. Defaults to the projectId configured in your Sanity CLI config.',\n }),\n }\n\n static override hiddenAliases = ['migration:run']\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(RunMigrationCommand)\n const {directory: workDir} = await this.getProjectRoot()\n const id = args.id\n const migrationsDirectoryPath = path.join(workDir, MIGRATIONS_DIRECTORY)\n\n // Listing migrations (no id given) only needs a project root, mirroring\n // `sanity migrations list` — it must not require api.projectId/dataset.\n if (!id) {\n this.warn(styleText('red', 'Error: Migration ID must be provided'))\n\n let migrations: Awaited<ReturnType<typeof resolveMigrations>> = []\n try {\n migrations = await resolveMigrations(workDir)\n } catch (error) {\n // A missing migrations folder is expected for a fresh project; surface\n // any other failure (e.g. a syntax error in a migration file).\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n this.error(\n `Failed to list migrations: ${error instanceof Error ? error.message : String(error)}`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n }\n\n if (migrations.length === 0) {\n this.log('\\nNo migrations found in the project')\n this.log(\n `Run ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\n this.exit(exitCodes.RUNTIME_ERROR)\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'title', title: 'Title'},\n ],\n title: `Migrations found in project`,\n })\n\n for (const definedMigration of migrations) {\n table.addRow({id: definedMigration.id, title: definedMigration.migration.title})\n }\n table.printTable()\n this.log('\\nRun `sanity migration run <ID>` to run a migration')\n\n this.exit(exitCodes.RUNTIME_ERROR)\n }\n\n const cliConfig = await this.getCliConfig()\n const projectId = await this.getProjectId({deprecatedFlagName: 'project'})\n const datasetFromConfig = cliConfig.api?.dataset\n\n const fromExport = flags['from-export']\n const dry = flags['dry-run']\n const dataset = flags.dataset\n const project = flags.project\n const apiVersion = ensureApiVersionFormat(flags['api-version'] ?? DEFAULT_API_VERSION)\n\n if ((dataset && !project) || (project && !dataset)) {\n this.error('If either --dataset or --project is provided, both must be provided', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (!project && !projectId) {\n this.error(\n 'sanity.cli.js does not contain a project identifier (\"api.projectId\") and no --project option was provided.',\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n\n if (!dataset && !datasetFromConfig) {\n this.error(\n 'sanity.cli.js does not contain a dataset identifier (\"api.dataset\") and no --dataset option was provided.',\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n\n const candidates = await resolveMigrationScript(workDir, id)\n const resolvedScripts = candidates.filter((candidate) => isLoadableMigrationScript(candidate))\n\n if (resolvedScripts.length > 1) {\n // todo: consider prompt user about which one to run? note: it's likely a mistake if multiple files resolve to the same name\n this.error(\n `Found multiple migrations for \"${id}\" in ${styleText('cyan', migrationsDirectoryPath)}: \\n - ${candidates\n .map((candidate) => path.relative(migrationsDirectoryPath, candidate.absolutePath))\n .join('\\n - ')}`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n\n const script = resolvedScripts[0]\n if (!script) {\n this.error(\n `No migration found for \"${id}\" in ${styleText('cyan', migrationsDirectoryPath)}. Make sure that the migration file exists and exports a valid migration as its default export.\\n\n Tried the following files:\\n - ${candidates\n .map((candidate) => path.relative(migrationsDirectoryPath, candidate.absolutePath))\n .join('\\n - ')}`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n\n const mod = script.mod\n if ('up' in mod || 'down' in mod) {\n // todo: consider adding support for up/down as separate named exports\n // For now, make sure we reserve the names for future use\n this.error(\n 'Named \"up\"/\"down\" migration exports are not supported at this time, please export your migration as the default export',\n {\n exit: exitCodes.RUNTIME_ERROR,\n },\n )\n }\n\n const migration: Migration = mod.default\n\n if (fromExport && !dry) {\n this.error('Can only dry run migrations from a dataset export file', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n const concurrency = flags.concurrency\n if (concurrency !== undefined) {\n if (concurrency > MAX_MUTATION_CONCURRENCY) {\n this.error(`Concurrency exceeds the maximum allowed value of ${MAX_MUTATION_CONCURRENCY}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (concurrency < 1) {\n this.error(`Concurrency must be a positive number, got ${concurrency}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n const projectClient = await getProjectCliClient({\n apiVersion,\n projectId: (project ?? projectId)!,\n requireUser: true,\n })\n const projectConfig = projectClient.config()\n\n const apiConfig: APIConfig = {\n apiHost: projectConfig.apiHost,\n apiVersion,\n dataset: (dataset ?? datasetFromConfig)!,\n projectId: (project ?? projectId)!,\n token: projectConfig.token!,\n } as const\n if (dry) {\n await this.dryRunHandler(id, migration, apiConfig, fromExport)\n return\n }\n\n this.log(\n `\\n${styleText(['yellow', 'bold'], 'Note: During migrations, your webhooks stay active.')}`,\n )\n this.log(\n `To adjust them, launch the management interface with ${styleText('cyan', 'sanity manage')}, navigate to the API settings, and toggle the webhooks before and after the migration as needed.\\n`,\n )\n\n if (flags.confirm) {\n await this.promptConfirmMigrate(apiConfig)\n }\n\n const spin = spinner(`Running migration \"${id}\"`).start()\n try {\n await run(\n {\n api: apiConfig,\n concurrency,\n onProgress: this.createProgress(spin, flags, id, dry, apiConfig, migration),\n },\n migration,\n )\n } finally {\n spin.stop()\n }\n }\n\n private createProgress(\n progressSpinner: ReturnType<typeof spinner>,\n flags: RunMigrationFlags,\n id: string,\n dry: boolean,\n apiConfig: APIConfig,\n migration: Migration,\n ) {\n return function onProgress(progress: MigrationProgress) {\n if (!flags.progress) {\n progressSpinner.stop()\n return\n }\n if (progress.done) {\n progressSpinner.text = `Migration \"${id}\" completed.\n\n Project id: ${styleText('bold', apiConfig.projectId)}\n Dataset: ${styleText('bold', apiConfig.dataset)}\n\n ${progress.documents} documents processed.\n ${progress.mutations} mutations generated.\n ${styleText('green', String(progress.completedTransactions.length))} transactions committed.`\n progressSpinner.stopAndPersist({symbol: styleText('green', '✔')})\n return\n }\n\n for (const transaction of [null, ...progress.currentTransactions]) {\n progressSpinner.text = `Running migration \"${id}\" ${dry ? 'in dry mode...' : '...'}\n\n Project id: ${styleText('bold', apiConfig.projectId)}\n Dataset: ${styleText('bold', apiConfig.dataset)}\n Document type: ${styleText('bold', migration.documentTypes?.join(',') ?? '')}\n\n ${progress.documents} documents processed…\n ${progress.mutations} mutations generated…\n ${styleText('blue', String(progress.pending))} requests pending…\n ${styleText('green', String(progress.completedTransactions.length))} transactions committed.\n\n ${\n transaction && !progress.done\n ? `» ${prettyFormat({indentSize: 2, migration, subject: transaction})}`\n : ''\n }`\n }\n }\n }\n\n private async dryRunHandler(\n id: string,\n migration: Migration,\n apiConfig: APIConfig,\n fromExport: string | undefined,\n ) {\n this.log(`Running migration \"${id}\" in dry mode`)\n\n if (fromExport) {\n this.log(`Using export ${styleText('cyan', fromExport)}`)\n }\n\n this.log()\n this.log(`Project id: ${styleText('bold', apiConfig.projectId)}`)\n this.log(`Dataset: ${styleText('bold', apiConfig.dataset)}`)\n\n for await (const mutation of dryRun({api: apiConfig, exportPath: fromExport}, migration)) {\n if (!mutation) continue\n this.log()\n this.log(\n prettyFormat({\n migration,\n subject: mutation,\n }),\n )\n }\n }\n\n private async promptConfirmMigrate(apiConfig: APIConfig) {\n const response = await confirm({\n message: `This migration will run on the ${styleText(\n ['yellow', 'bold'],\n apiConfig.dataset,\n )} dataset in ${styleText(['yellow', 'bold'], apiConfig.projectId)} project. Are you sure?`,\n })\n\n if (!response) {\n runMigrationDebug('User aborted migration')\n this.exit(exitCodes.RUNTIME_ERROR)\n }\n }\n}\n"],"names":["path","styleText","Args","Flags","exitCodes","getProjectCliClient","SanityCommand","subdebug","confirm","spinner","DEFAULT_MUTATION_CONCURRENCY","dryRun","MAX_MUTATION_CONCURRENCY","run","Table","DEFAULT_API_VERSION","MIGRATIONS_DIRECTORY","ensureApiVersionFormat","prettyFormat","resolveMigrations","isLoadableMigrationScript","resolveMigrationScript","runMigrationDebug","RunMigrationCommand","args","id","string","description","required","examples","command","flags","concurrency","integer","default","boolean","allowNo","dataset","progress","project","hiddenAliases","parse","directory","workDir","getProjectRoot","migrationsDirectoryPath","join","warn","migrations","error","code","Error","message","String","exit","RUNTIME_ERROR","length","log","table","columns","alignment","name","title","definedMigration","addRow","migration","printTable","cliConfig","getCliConfig","projectId","getProjectId","deprecatedFlagName","datasetFromConfig","api","fromExport","dry","apiVersion","candidates","resolvedScripts","filter","candidate","map","relative","absolutePath","script","mod","undefined","projectClient","requireUser","projectConfig","config","apiConfig","apiHost","token","dryRunHandler","promptConfirmMigrate","spin","start","onProgress","createProgress","stop","progressSpinner","done","text","documents","mutations","completedTransactions","stopAndPersist","symbol","transaction","currentTransactions","documentTypes","pending","indentSize","subject","mutation","exportPath","response"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxF,SAAQC,OAAO,EAAEC,OAAO,QAAO,sBAAqB;AACpD,SAEEC,4BAA4B,EAC5BC,MAAM,EACNC,wBAAwB,EAGxBC,GAAG,QACE,kBAAiB;AACxB,SAAQC,KAAK,QAAO,wBAAuB;AAE3C,SAAQC,mBAAmB,EAAEC,oBAAoB,QAAO,uCAAsC;AAC9F,SAAQC,sBAAsB,QAAO,oDAAmD;AACxF,SAAQC,YAAY,QAAO,qDAAoD;AAC/E,SAAQC,iBAAiB,QAAO,+CAA8C;AAC9E,SACEC,yBAAyB,EACzBC,sBAAsB,QACjB,oDAAmD;AAE1D,MAAMC,oBAAoBf,SAAS;AAInC,OAAO,MAAMgB,4BAA4BjB;IACvC,OAAgBkB,OAAO;QACrBC,IAAIvB,KAAKwB,MAAM,CAAC;YACdC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,oCAAmC;IAEjE,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtB,eAAe5B,MAAMuB,MAAM,CAAC;YAC1BC,aAAa,CAAC,+CAA+C,EAAEZ,oBAAoB,CAAC,CAAC;QACvF;QACAiB,aAAa7B,MAAM8B,OAAO,CAAC;YACzBC,SAASxB;YACTiB,aAAa,CAAC,qEAAqE,EAAEf,yBAAyB,WAAW,EAAEF,6BAA6B,CAAC,CAAC;QAC5J;QACAF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oBAAGhD;oBAAWiD,SAASL;gBAAW,IAAI,GACrE,IACJ;YACE;QACF;IACF;IAEA,MAAcf,cACZrE,EAAU,EACVwC,SAAoB,EACpB0B,SAAoB,EACpBjB,UAA8B,EAC9B;QACA,IAAI,CAACjB,GAAG,CAAC,CAAC,mBAAmB,EAAEhC,GAAG,aAAa,CAAC;QAEhD,IAAIiD,YAAY;YACd,IAAI,CAACjB,GAAG,CAAC,CAAC,aAAa,EAAExD,UAAU,QAAQyE,aAAa;QAC1D;QAEA,IAAI,CAACjB,GAAG;QACR,IAAI,CAACA,GAAG,CAAC,CAAC,aAAa,EAAExD,UAAU,QAAQ0F,UAAUtB,SAAS,GAAG;QACjE,IAAI,CAACZ,GAAG,CAAC,CAAC,aAAa,EAAExD,UAAU,QAAQ0F,UAAUtD,OAAO,GAAG;QAE/D,WAAW,MAAM8E,YAAYxG,OAAO;YAAC8D,KAAKkB;YAAWyB,YAAY1C;QAAU,GAAGT,WAAY;YACxF,IAAI,CAACkD,UAAU;YACf,IAAI,CAAC1D,GAAG;YACR,IAAI,CAACA,GAAG,CACNvC,aAAa;gBACX+C;gBACAiD,SAASC;YACX;QAEJ;IACF;IAEA,MAAcpB,qBAAqBJ,SAAoB,EAAE;QACvD,MAAM0B,WAAW,MAAM7G,QAAQ;YAC7B4C,SAAS,CAAC,+BAA+B,EAAEnD,UACzC;gBAAC;gBAAU;aAAO,EAClB0F,UAAUtD,OAAO,EACjB,YAAY,EAAEpC,UAAU;gBAAC;gBAAU;aAAO,EAAE0F,UAAUtB,SAAS,EAAE,uBAAuB,CAAC;QAC7F;QAEA,IAAI,CAACgD,UAAU;YACb/F,kBAAkB;YAClB,IAAI,CAACgC,IAAI,CAAClD,UAAUmD,aAAa;QACnC;IACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
2
|
+
import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
3
3
|
import open from 'open';
|
|
4
4
|
const getOpenapiDebug = subdebug('openapi:get');
|
|
5
5
|
export class GetOpenApiCommand extends SanityCommand {
|
|
@@ -59,11 +59,11 @@ export class GetOpenApiCommand extends SanityCommand {
|
|
|
59
59
|
getOpenapiDebug(`Error fetching OpenAPI spec ${slug}`, error);
|
|
60
60
|
if (error instanceof Response && error.status === 404) {
|
|
61
61
|
this.error(`OpenAPI specification not found. ${slug}`, {
|
|
62
|
-
exit:
|
|
62
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
this.error('The OpenAPI service is currently unavailable. Please try again later.', {
|
|
66
|
-
exit:
|
|
66
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/openapi/get.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport open from 'open'\n\nconst getOpenapiDebug = subdebug('openapi:get')\n\nexport class GetOpenApiCommand extends SanityCommand<typeof GetOpenApiCommand> {\n static override args = {\n slug: Args.string({\n description: 'Slug of the OpenAPI specification to retrieve',\n required: true,\n }),\n }\n\n static override description = 'Get an OpenAPI specification by slug'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> query',\n description: 'Get a specification (YAML format, default)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query --format=json',\n description: 'Get specification in JSON format',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query --web',\n description: 'Open specification in browser',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query > query-api.yaml',\n description: 'Pipe to file',\n },\n ]\n\n static override flags = {\n format: Flags.string({\n default: 'yaml',\n description: 'Output format: yaml (default), json',\n options: ['yaml', 'json'],\n }),\n web: Flags.boolean({\n char: 'w',\n description: 'Open in web browser',\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(GetOpenApiCommand)\n const {slug} = args\n const {format, web} = flags\n\n if (web) {\n const url = `https://www.sanity.io/docs/http-reference/${slug}`\n this.log(`Opening ${url}`)\n await open(url)\n return\n }\n\n try {\n const specContent = await this.getSpecContent(slug, format)\n\n this.log(specContent)\n } catch (error) {\n getOpenapiDebug(`Error fetching OpenAPI spec ${slug}`, error)\n\n if (error instanceof Response && error.status === 404) {\n this.error(`OpenAPI specification not found. ${slug}`, {exit:
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/openapi/get.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport open from 'open'\n\nconst getOpenapiDebug = subdebug('openapi:get')\n\nexport class GetOpenApiCommand extends SanityCommand<typeof GetOpenApiCommand> {\n static override args = {\n slug: Args.string({\n description: 'Slug of the OpenAPI specification to retrieve',\n required: true,\n }),\n }\n\n static override description = 'Get an OpenAPI specification by slug'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> query',\n description: 'Get a specification (YAML format, default)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query --format=json',\n description: 'Get specification in JSON format',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query --web',\n description: 'Open specification in browser',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query > query-api.yaml',\n description: 'Pipe to file',\n },\n ]\n\n static override flags = {\n format: Flags.string({\n default: 'yaml',\n description: 'Output format: yaml (default), json',\n options: ['yaml', 'json'],\n }),\n web: Flags.boolean({\n char: 'w',\n description: 'Open in web browser',\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(GetOpenApiCommand)\n const {slug} = args\n const {format, web} = flags\n\n if (web) {\n const url = `https://www.sanity.io/docs/http-reference/${slug}`\n this.log(`Opening ${url}`)\n await open(url)\n return\n }\n\n try {\n const specContent = await this.getSpecContent(slug, format)\n\n this.log(specContent)\n } catch (error) {\n getOpenapiDebug(`Error fetching OpenAPI spec ${slug}`, error)\n\n if (error instanceof Response && error.status === 404) {\n this.error(`OpenAPI specification not found. ${slug}`, {exit: exitCodes.RUNTIME_ERROR})\n }\n\n this.error('The OpenAPI service is currently unavailable. Please try again later.', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n private async getSpecContent(slug: string, format: string): Promise<string> {\n const url = new URL(`https://www.sanity.io/docs/api/openapi/${slug}`)\n url.searchParams.set('format', format)\n const response = await fetch(url, {\n signal: AbortSignal.timeout(10_000),\n })\n\n if (response.ok) {\n return response.text()\n }\n\n throw response\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","open","getOpenapiDebug","GetOpenApiCommand","args","slug","string","description","required","examples","command","flags","format","default","options","web","boolean","char","run","parse","url","log","specContent","getSpecContent","error","Response","status","exit","RUNTIME_ERROR","URL","searchParams","set","response","fetch","signal","AbortSignal","timeout","ok","text"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,OAAOC,UAAU,OAAM;AAEvB,MAAMC,kBAAkBF,SAAS;AAEjC,OAAO,MAAMG,0BAA0BJ;IACrC,OAAgBK,OAAO;QACrBC,MAAMT,KAAKU,MAAM,CAAC;YAChBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,uCAAsC;IAEpE,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;QACtBC,QAAQf,MAAMS,MAAM,CAAC;YACnBO,SAAS;YACTN,aAAa;YACbO,SAAS;gBAAC;gBAAQ;aAAO;QAC3B;QACAC,KAAKlB,MAAMmB,OAAO,CA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