@sanity/cli 7.9.0 → 7.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/README.md +163 -22
  2. package/dist/actions/auth/ensureAuthenticated.js +2 -0
  3. package/dist/actions/auth/ensureAuthenticated.js.map +1 -1
  4. package/dist/actions/auth/login/getProvider.js +7 -2
  5. package/dist/actions/auth/login/getProvider.js.map +1 -1
  6. package/dist/actions/auth/login/loginInstructions.js +19 -0
  7. package/dist/actions/auth/login/loginInstructions.js.map +1 -0
  8. package/dist/actions/dataset/create.js +2 -2
  9. package/dist/actions/dataset/create.js.map +1 -1
  10. package/dist/actions/dataset/resolveDataset.js +7 -1
  11. package/dist/actions/dataset/resolveDataset.js.map +1 -1
  12. package/dist/actions/deploy/createUserApplication.js +8 -5
  13. package/dist/actions/deploy/createUserApplication.js.map +1 -1
  14. package/dist/actions/deploy/deployApp.js +47 -24
  15. package/dist/actions/deploy/deployApp.js.map +1 -1
  16. package/dist/actions/deploy/deployStudio.js +2 -0
  17. package/dist/actions/deploy/deployStudio.js.map +1 -1
  18. package/dist/actions/graphql/resolveApiGeneration.js +9 -6
  19. package/dist/actions/graphql/resolveApiGeneration.js.map +1 -1
  20. package/dist/actions/init/initAction.js +23 -15
  21. package/dist/actions/init/initAction.js.map +1 -1
  22. package/dist/actions/manifest/extractCoreAppManifest.js +11 -4
  23. package/dist/actions/manifest/extractCoreAppManifest.js.map +1 -1
  24. package/dist/actions/migration/constants.js +10 -0
  25. package/dist/actions/migration/constants.js.map +1 -0
  26. package/dist/actions/migration/ensureApiVersionFormat.js +16 -0
  27. package/dist/actions/migration/ensureApiVersionFormat.js.map +1 -0
  28. package/dist/actions/migration/fileExists.js +13 -0
  29. package/dist/actions/migration/fileExists.js.map +1 -0
  30. package/dist/actions/migration/prettyMutationFormatter.js +155 -0
  31. package/dist/actions/migration/prettyMutationFormatter.js.map +1 -0
  32. package/dist/actions/migration/resolveMigrationScript.js +75 -0
  33. package/dist/actions/migration/resolveMigrationScript.js.map +1 -0
  34. package/dist/actions/migration/resolveMigrations.js +50 -0
  35. package/dist/actions/migration/resolveMigrations.js.map +1 -0
  36. package/dist/actions/migration/templates/index.js +7 -0
  37. package/dist/actions/migration/templates/index.js.map +1 -0
  38. package/dist/actions/migration/templates/minimalAdvanced.js +21 -0
  39. package/dist/actions/migration/templates/minimalAdvanced.js.map +1 -0
  40. package/dist/actions/migration/templates/minimalSimple.js +61 -0
  41. package/dist/actions/migration/templates/minimalSimple.js.map +1 -0
  42. package/dist/actions/migration/templates/renameField.js +20 -0
  43. package/dist/actions/migration/templates/renameField.js.map +1 -0
  44. package/dist/actions/migration/templates/renameType.js +19 -0
  45. package/dist/actions/migration/templates/renameType.js.map +1 -0
  46. package/dist/actions/migration/templates/stringToPTE.js +32 -0
  47. package/dist/actions/migration/templates/stringToPTE.js.map +1 -0
  48. package/dist/actions/migration/tree.js +111 -0
  49. package/dist/actions/migration/tree.js.map +1 -0
  50. package/dist/actions/organizations/getOrganization.js +7 -3
  51. package/dist/actions/organizations/getOrganization.js.map +1 -1
  52. package/dist/actions/organizations/validateOrganizationSlug.js +20 -0
  53. package/dist/actions/organizations/validateOrganizationSlug.js.map +1 -0
  54. package/dist/actions/preview/previewAction.js +33 -1
  55. package/dist/actions/preview/previewAction.js.map +1 -1
  56. package/dist/actions/schema/listSchemas.js +6 -4
  57. package/dist/actions/schema/listSchemas.js.map +1 -1
  58. package/dist/actions/tokens/validateRole.js +2 -1
  59. package/dist/actions/tokens/validateRole.js.map +1 -1
  60. package/dist/actions/undeploy/runUndeploy.js +13 -4
  61. package/dist/actions/undeploy/runUndeploy.js.map +1 -1
  62. package/dist/commands/backups/disable.js +5 -1
  63. package/dist/commands/backups/disable.js.map +1 -1
  64. package/dist/commands/backups/download.js +30 -6
  65. package/dist/commands/backups/download.js.map +1 -1
  66. package/dist/commands/backups/enable.js +5 -1
  67. package/dist/commands/backups/enable.js.map +1 -1
  68. package/dist/commands/backups/list.js +5 -1
  69. package/dist/commands/backups/list.js.map +1 -1
  70. package/dist/commands/cors/add.js +15 -7
  71. package/dist/commands/cors/add.js.map +1 -1
  72. package/dist/commands/cors/delete.js +6 -1
  73. package/dist/commands/cors/delete.js.map +1 -1
  74. package/dist/commands/datasets/alias/create.js +25 -18
  75. package/dist/commands/datasets/alias/create.js.map +1 -1
  76. package/dist/commands/datasets/alias/delete.js +15 -8
  77. package/dist/commands/datasets/alias/delete.js.map +1 -1
  78. package/dist/commands/datasets/alias/link.js +39 -17
  79. package/dist/commands/datasets/alias/link.js.map +1 -1
  80. package/dist/commands/datasets/alias/unlink.js +23 -2
  81. package/dist/commands/datasets/alias/unlink.js.map +1 -1
  82. package/dist/commands/datasets/copy.js +18 -2
  83. package/dist/commands/datasets/copy.js.map +1 -1
  84. package/dist/commands/datasets/create.js +8 -2
  85. package/dist/commands/datasets/create.js.map +1 -1
  86. package/dist/commands/datasets/delete.js +14 -17
  87. package/dist/commands/datasets/delete.js.map +1 -1
  88. package/dist/commands/datasets/embeddings/disable.js +3 -0
  89. package/dist/commands/datasets/embeddings/disable.js.map +1 -1
  90. package/dist/commands/datasets/embeddings/enable.js +5 -2
  91. package/dist/commands/datasets/embeddings/enable.js.map +1 -1
  92. package/dist/commands/datasets/embeddings/status.js +3 -0
  93. package/dist/commands/datasets/embeddings/status.js.map +1 -1
  94. package/dist/commands/datasets/export.js +27 -15
  95. package/dist/commands/datasets/export.js.map +1 -1
  96. package/dist/commands/datasets/import.js +3 -3
  97. package/dist/commands/datasets/import.js.map +1 -1
  98. package/dist/commands/datasets/visibility/get.js +2 -2
  99. package/dist/commands/datasets/visibility/get.js.map +1 -1
  100. package/dist/commands/datasets/visibility/set.js +2 -2
  101. package/dist/commands/datasets/visibility/set.js.map +1 -1
  102. package/dist/commands/docs/read.js +3 -3
  103. package/dist/commands/docs/read.js.map +1 -1
  104. package/dist/commands/documents/create.js +18 -13
  105. package/dist/commands/documents/create.js.map +1 -1
  106. package/dist/commands/documents/delete.js +3 -3
  107. package/dist/commands/documents/delete.js.map +1 -1
  108. package/dist/commands/documents/get.js +3 -3
  109. package/dist/commands/documents/get.js.map +1 -1
  110. package/dist/commands/documents/query.js +3 -3
  111. package/dist/commands/documents/query.js.map +1 -1
  112. package/dist/commands/documents/validate.js +29 -26
  113. package/dist/commands/documents/validate.js.map +1 -1
  114. package/dist/commands/graphql/deploy.js +20 -16
  115. package/dist/commands/graphql/deploy.js.map +1 -1
  116. package/dist/commands/graphql/undeploy.js +15 -18
  117. package/dist/commands/graphql/undeploy.js.map +1 -1
  118. package/dist/commands/hooks/create.js +4 -0
  119. package/dist/commands/hooks/create.js.map +1 -1
  120. package/dist/commands/hooks/delete.js +6 -1
  121. package/dist/commands/hooks/delete.js.map +1 -1
  122. package/dist/commands/hooks/logs.js +6 -1
  123. package/dist/commands/hooks/logs.js.map +1 -1
  124. package/dist/commands/install.js +1 -1
  125. package/dist/commands/install.js.map +1 -1
  126. package/dist/commands/login.js +2 -1
  127. package/dist/commands/login.js.map +1 -1
  128. package/dist/commands/media/create-aspect.js +20 -8
  129. package/dist/commands/media/create-aspect.js.map +1 -1
  130. package/dist/commands/media/delete-aspect.js +31 -16
  131. package/dist/commands/media/delete-aspect.js.map +1 -1
  132. package/dist/commands/media/deploy-aspect.js +10 -5
  133. package/dist/commands/media/deploy-aspect.js.map +1 -1
  134. package/dist/commands/media/export.js +9 -4
  135. package/dist/commands/media/export.js.map +1 -1
  136. package/dist/commands/media/import.js +6 -1
  137. package/dist/commands/media/import.js.map +1 -1
  138. package/dist/commands/migrations/create.js +150 -0
  139. package/dist/commands/migrations/create.js.map +1 -0
  140. package/dist/commands/migrations/list.js +64 -0
  141. package/dist/commands/migrations/list.js.map +1 -0
  142. package/dist/commands/migrations/run.js +306 -0
  143. package/dist/commands/migrations/run.js.map +1 -0
  144. package/dist/commands/organizations/create.js +79 -0
  145. package/dist/commands/organizations/create.js.map +1 -0
  146. package/dist/commands/organizations/delete.js +100 -0
  147. package/dist/commands/organizations/delete.js.map +1 -0
  148. package/dist/commands/organizations/get.js +48 -0
  149. package/dist/commands/organizations/get.js.map +1 -0
  150. package/dist/commands/organizations/list.js +60 -0
  151. package/dist/commands/organizations/list.js.map +1 -0
  152. package/dist/commands/organizations/update.js +115 -0
  153. package/dist/commands/organizations/update.js.map +1 -0
  154. package/dist/commands/preview.js +1 -0
  155. package/dist/commands/preview.js.map +1 -1
  156. package/dist/commands/projects/create.js +3 -1
  157. package/dist/commands/projects/create.js.map +1 -1
  158. package/dist/commands/schemas/delete.js +23 -2
  159. package/dist/commands/schemas/delete.js.map +1 -1
  160. package/dist/commands/schemas/deploy.js +6 -4
  161. package/dist/commands/schemas/deploy.js.map +1 -1
  162. package/dist/commands/schemas/extract.js +22 -1
  163. package/dist/commands/schemas/extract.js.map +1 -1
  164. package/dist/commands/schemas/list.js +8 -8
  165. package/dist/commands/schemas/list.js.map +1 -1
  166. package/dist/commands/tokens/{add.js → create.js} +25 -18
  167. package/dist/commands/tokens/create.js.map +1 -0
  168. package/dist/commands/tokens/delete.js +41 -23
  169. package/dist/commands/tokens/delete.js.map +1 -1
  170. package/dist/commands/undeploy.js +2 -7
  171. package/dist/commands/undeploy.js.map +1 -1
  172. package/dist/commands/users/invite.js +25 -3
  173. package/dist/commands/users/invite.js.map +1 -1
  174. package/dist/prompts/promptForOrganizationName.js +2 -1
  175. package/dist/prompts/promptForOrganizationName.js.map +1 -1
  176. package/dist/services/organizations.js +45 -2
  177. package/dist/services/organizations.js.map +1 -1
  178. package/dist/services/userApplications.js.map +1 -1
  179. package/dist/topicAliases.js +10 -0
  180. package/dist/topicAliases.js.map +1 -1
  181. package/dist/util/formatCliErrorMessages.js +5 -0
  182. package/dist/util/formatCliErrorMessages.js.map +1 -0
  183. package/dist/util/organizationAliases.js +12 -0
  184. package/dist/util/organizationAliases.js.map +1 -0
  185. package/oclif.config.js +6 -1
  186. package/oclif.manifest.json +464 -11
  187. package/package.json +28 -28
  188. package/dist/commands/tokens/add.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/init/initAction.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {type SanityOrgUser, subdebug, type TelemetryUserProperties} from '@sanity/cli-core'\nimport {logSymbols, spinner} from '@sanity/cli-core/ux'\nimport {type TelemetryTrace} from '@sanity/telemetry'\nimport {type Framework, frameworks} from '@vercel/frameworks'\nimport deburr from 'lodash-es/deburr.js'\n\nimport {promptForConfigFiles} from '../../prompts/init/nextjs.js'\nimport {getCliUser} from '../../services/user.js'\nimport {CLIInitStepCompleted, type InitStepResult} from '../../telemetry/init.telemetry.js'\nimport {detectFrameworkRecord} from '../../util/detectFramework.js'\nimport {getProjectDefaults} from '../../util/getProjectDefaults.js'\nimport {validateSession} from '../auth/ensureAuthenticated.js'\nimport {getProviderName} from '../auth/getProviderName.js'\nimport {login} from '../auth/login/login.js'\nimport {detectAvailableEditors} from '../mcp/detectAvailableEditors.js'\nimport {setupMCP} from '../mcp/setupMCP.js'\nimport {setupSkills} from '../skills/setupSkills.js'\nimport {checkNextJsReactCompatibility} from './checkNextJsReactCompatibility.js'\nimport {determineAppTemplate} from './determineAppTemplate.js'\nimport {createOrAppendEnvVars} from './env/createOrAppendEnvVars.js'\nimport {initApp} from './initApp.js'\nimport {InitError} from './initError.js'\nimport {flagOrDefault, shouldPrompt, writeStagingEnvIfNeeded} from './initHelpers.js'\nimport {initNextJs} from './initNextJs.js'\nimport {initStudio} from './initStudio.js'\nimport {getPlan} from './plan/getPlan.js'\nimport {createProjectFromName} from './project/createProjectFromName.js'\nimport {getProjectDetails} from './project/getProjectDetails.js'\nimport {getProjectOutputPath} from './project/getProjectOutputPath.js'\nimport {checkIsRemoteTemplate, getGitHubRepoInfo, type RepoInfo} from './remoteTemplate.js'\nimport {type InitContext, type InitOptions} from './types.js'\n\nconst debug = subdebug('init')\n\nexport async function initAction(options: InitOptions, context: InitContext): Promise<void> {\n const {output, workDir} = context\n\n if (options.argType) {\n throw new InitError(\n options.argType === 'plugin'\n ? 'Initializing plugins through the CLI is no longer supported'\n : `Unknown init type \"${options.argType}\"`,\n 1,\n )\n }\n\n const trace = context.telemetry.trace(CLIInitStepCompleted)\n\n if (options.reconfigure) {\n throw new InitError('--reconfigure is deprecated - manual configuration is now required', 1)\n }\n\n if (options.project && options.organization) {\n throw new InitError(\n 'You have specified both a project and an organization. To move a project to an organization please visit https://www.sanity.io/manage',\n 1,\n )\n }\n\n const defaultConfig = options.datasetDefault\n let showDefaultConfigPrompt = !defaultConfig\n if (options.dataset || options.visibility || options.datasetDefault || options.unattended) {\n showDefaultConfigPrompt = false\n }\n\n const detectedFramework = await detectFrameworkRecord({\n frameworkList: frameworks as readonly Framework[],\n rootPath: workDir,\n })\n const isNextJs = detectedFramework?.slug === 'nextjs'\n\n let remoteTemplateInfo: RepoInfo | undefined\n if (options.template && checkIsRemoteTemplate(options.template)) {\n remoteTemplateInfo = await getGitHubRepoInfo(options.template, options.templateToken)\n }\n\n if (detectedFramework && detectedFramework.slug !== 'sanity' && remoteTemplateInfo) {\n throw new InitError(\n `A remote template cannot be used with a detected framework. Detected: ${detectedFramework.name}`,\n 1,\n )\n }\n\n const isAppTemplate = options.template ? determineAppTemplate(options.template) : false\n\n if (options.unattended) {\n checkFlagsInUnattendedMode(options, {isAppTemplate, isNextJs})\n }\n\n trace.start()\n trace.log({\n flags: {\n bare: options.bare,\n coupon: options.coupon,\n defaultConfig,\n env: options.env,\n git: typeof options.git === 'string' ? options.git : undefined,\n plan: options.projectPlan,\n reconfigure: options.reconfigure,\n unattended: options.unattended,\n },\n step: 'start',\n })\n\n const planId = await getPlan(options, output, trace)\n\n let envFilenameDefault = '.env'\n if (detectedFramework && detectedFramework.slug === 'nextjs') {\n envFilenameDefault = '.env.local'\n }\n const envFilename = typeof options.env === 'string' ? options.env : envFilenameDefault\n\n const {user} = await ensureAuthenticated(options, output, trace)\n if (!isAppTemplate) {\n output.log(`${logSymbols.success} Fetching existing projects`)\n output.log('')\n }\n\n let newProject: string | undefined\n if (options.projectName) {\n newProject = await createProjectFromName({\n coupon: options.coupon,\n createProjectName: options.projectName,\n dataset: options.dataset,\n organization: options.organization,\n planId,\n user,\n visibility: options.visibility,\n })\n }\n\n const {datasetName, displayName, isFirstProject, organizationId, projectId} =\n await getProjectDetails({\n coupon: options.coupon,\n dataset: options.dataset,\n datasetDefault: options.datasetDefault,\n isAppTemplate,\n newProject,\n organization: options.organization,\n output,\n planId,\n project: options.project,\n showDefaultConfigPrompt,\n trace,\n unattended: options.unattended,\n user,\n visibility: options.visibility,\n })\n\n if (options.bare) {\n output.log(`${logSymbols.success} Below are your project details`)\n output.log('')\n output.log(`Project ID: ${styleText('cyan', projectId)}`)\n output.log(`Dataset: ${styleText('cyan', datasetName)}`)\n output.log(\n `\\nYou can find your project on Sanity Manage — https://www.sanity.io/manage/project/${projectId}\\n`,\n )\n trace.complete()\n return\n }\n\n // Detect editors once, then share the result with MCP and skills setup so\n // we don't pay the detection cost (filesystem probes + CLI execa calls) twice.\n const detectedEditors =\n options.mcpMode === 'skip' && options.skillsMode === 'skip'\n ? []\n : await detectAvailableEditors()\n\n const mcpResult = await setupMCP({\n editors: detectedEditors,\n mode: options.mcpMode,\n output,\n skillsMode: options.skillsMode,\n })\n\n trace.log({\n configuredEditors: mcpResult.configuredEditors,\n detectedEditors: mcpResult.detectedEditors,\n skipped: mcpResult.skipped,\n step: 'mcpSetup',\n })\n if (mcpResult.error) {\n trace.error(mcpResult.error)\n }\n const mcpConfigured = mcpResult.configuredEditors\n\n async function installSkills(): Promise<void> {\n if (mcpResult.skillsToInstall.length === 0) return\n try {\n const skillsResult = await setupSkills({agents: mcpResult.skillsToInstall, output})\n trace.log({\n installedAgents: skillsResult.installedAgents,\n skipped: skillsResult.skipped,\n step: 'skillsSetup',\n })\n if (skillsResult.error) {\n trace.error(skillsResult.error)\n }\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error))\n debug('Unexpected error from setupSkills %O', err)\n output.warn(`Could not install Sanity agent skills: ${err.message}`)\n trace.error(err)\n }\n }\n\n // Install skills right after the MCP/skills prompt so the progress + result\n // surface in sequence, rather than trailing the studio \"Success!\" output.\n await installSkills()\n\n const {alreadyConfiguredEditors} = mcpResult\n if (alreadyConfiguredEditors.length > 0) {\n const label =\n alreadyConfiguredEditors.length === 1\n ? `${alreadyConfiguredEditors[0]} already configured for Sanity MCP`\n : `${alreadyConfiguredEditors.length} editors already configured for Sanity MCP`\n spinner(label).start().succeed()\n }\n\n let initNext = flagOrDefault(options.nextjsAddConfigFiles, false)\n if (isNextJs && shouldPrompt(options.unattended, options.nextjsAddConfigFiles)) {\n initNext = await promptForConfigFiles()\n }\n\n trace.log({\n detectedFramework: detectedFramework?.name,\n selectedOption: initNext ? 'yes' : 'no',\n step: 'useDetectedFramework',\n })\n\n const sluggedName = deburr(displayName.toLowerCase())\n .replaceAll(/\\s+/g, '-')\n .replaceAll(/[^a-z0-9-]/g, '')\n\n const initFramework = initNext\n\n const defaults = await getProjectDefaults({isPlugin: false, workDir})\n\n const outputPath = await getProjectOutputPath({\n initFramework,\n outputPath: options.outputPath,\n sluggedName,\n unattended: options.unattended,\n useEnv: Boolean(options.env),\n workDir,\n })\n\n if (isNextJs) {\n await checkNextJsReactCompatibility({\n detectedFramework,\n output,\n outputPath,\n })\n }\n\n if (initNext) {\n await initNextJs({\n datasetName,\n detectedFramework,\n envFilename,\n mcpConfigured,\n options,\n output,\n projectId,\n trace,\n workDir,\n })\n trace.complete()\n return\n }\n\n if (options.env) {\n await createOrAppendEnvVars({\n envVars: {\n DATASET: datasetName,\n PROJECT_ID: projectId,\n },\n filename: envFilename,\n framework: detectedFramework,\n log: false,\n output,\n outputPath,\n })\n await writeStagingEnvIfNeeded(output, outputPath)\n trace.complete()\n return\n }\n\n // Workbench is opt-in (no prompt): the flag swaps the scaffolded\n // `sanity.cli.*` over to `unstable_defineApp` — the branded app is the sole\n // workbench opt-in.\n const workbench = flagOrDefault(options.unstableWorkbench, false)\n\n const sharedParams = {\n defaults,\n mcpConfigured,\n options,\n organizationId,\n output,\n outputPath,\n remoteTemplateInfo,\n sluggedName,\n trace,\n workbench,\n workDir,\n }\n\n await (isAppTemplate\n ? initApp({...sharedParams, datasetName, projectId})\n : initStudio({\n ...sharedParams,\n datasetName,\n displayName,\n isFirstProject,\n projectId,\n }))\n\n trace.complete()\n}\n\nfunction checkFlagsInUnattendedMode(\n options: InitOptions,\n {isAppTemplate, isNextJs}: {isAppTemplate: boolean; isNextJs: boolean},\n): void {\n debug('Unattended mode, validating required options')\n\n if (options.projectName && !options.organization) {\n throw new InitError('`--project-name` requires `--organization <id>` in unattended mode', 1)\n }\n\n if (isAppTemplate) {\n if (!options.outputPath) {\n throw new InitError('`--output-path` must be specified in unattended mode', 1)\n }\n\n const hasProjectFlag = Boolean(options.project || options.projectName)\n\n if (!hasProjectFlag && !options.organization) {\n throw new InitError(\n 'The --organization flag is required for app templates in unattended mode. ' +\n 'Use --organization <id>, or pass --project <id> / --project-name <name>.',\n 1,\n )\n }\n\n return\n }\n\n if (!isNextJs && !options.bare && !options.outputPath) {\n throw new InitError('`--output-path` must be specified in unattended mode', 1)\n }\n\n if (!options.project && !options.projectName) {\n throw new InitError(\n '`--project <id>` or `--project-name <name>` must be specified in unattended mode',\n 1,\n )\n }\n}\n\nasync function ensureAuthenticated(\n options: InitOptions,\n output: InitContext['output'],\n trace: TelemetryTrace<TelemetryUserProperties, InitStepResult>,\n): Promise<{user: SanityOrgUser}> {\n const user = await validateSession()\n\n if (user) {\n trace.log({alreadyLoggedIn: true, step: 'login'})\n output.log(\n `${logSymbols.success} You are logged in as ${user.email} using ${getProviderName(user.provider)}`,\n )\n return {user}\n }\n\n if (options.unattended) {\n throw new InitError(\n 'Must be logged in to run this command in unattended mode, run `sanity login`',\n 1,\n )\n }\n\n trace.log({step: 'login'})\n\n try {\n await login({\n output,\n telemetry: trace.newContext('login'),\n })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new InitError(`Login failed: ${message}`, 1)\n }\n\n const loggedInUser = await getCliUser()\n\n output.log(\n `${logSymbols.success} You are logged in as ${loggedInUser.email} using ${getProviderName(loggedInUser.provider)}`,\n )\n return {user: loggedInUser}\n}\n"],"names":["styleText","subdebug","logSymbols","spinner","frameworks","deburr","promptForConfigFiles","getCliUser","CLIInitStepCompleted","detectFrameworkRecord","getProjectDefaults","validateSession","getProviderName","login","detectAvailableEditors","setupMCP","setupSkills","checkNextJsReactCompatibility","determineAppTemplate","createOrAppendEnvVars","initApp","InitError","flagOrDefault","shouldPrompt","writeStagingEnvIfNeeded","initNextJs","initStudio","getPlan","createProjectFromName","getProjectDetails","getProjectOutputPath","checkIsRemoteTemplate","getGitHubRepoInfo","debug","initAction","options","context","output","workDir","argType","trace","telemetry","reconfigure","project","organization","defaultConfig","datasetDefault","showDefaultConfigPrompt","dataset","visibility","unattended","detectedFramework","frameworkList","rootPath","isNextJs","slug","remoteTemplateInfo","template","templateToken","name","isAppTemplate","checkFlagsInUnattendedMode","start","log","flags","bare","coupon","env","git","undefined","plan","projectPlan","step","planId","envFilenameDefault","envFilename","user","ensureAuthenticated","success","newProject","projectName","createProjectName","datasetName","displayName","isFirstProject","organizationId","projectId","complete","detectedEditors","mcpMode","skillsMode","mcpResult","editors","mode","configuredEditors","skipped","error","mcpConfigured","installSkills","skillsToInstall","length","skillsResult","agents","installedAgents","err","Error","String","warn","message","alreadyConfiguredEditors","label","succeed","initNext","nextjsAddConfigFiles","selectedOption","sluggedName","toLowerCase","replaceAll","initFramework","defaults","isPlugin","outputPath","useEnv","Boolean","envVars","DATASET","PROJECT_ID","filename","framework","workbench","unstableWorkbench","sharedParams","hasProjectFlag","alreadyLoggedIn","email","provider","newContext","loggedInUser"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAA4BC,QAAQ,QAAqC,mBAAkB;AAC3F,SAAQC,UAAU,EAAEC,OAAO,QAAO,sBAAqB;AAEvD,SAAwBC,UAAU,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AQsF,UAAU,EAAE;QACrD,MAAM,IAAIpG,UAAU,wDAAwD;IAC9E;IAEA,IAAI,CAACc,QAAQQ,OAAO,IAAI,CAACR,QAAQ6C,WAAW,EAAE;QAC5C,MAAM,IAAI3D,UACR,oFACA;IAEJ;AACF;AAEA,eAAewD,oBACb1C,OAAoB,EACpBE,MAA6B,EAC7BG,KAA8D;IAE9D,MAAMoC,OAAO,MAAMjE;IAEnB,IAAIiE,MAAM;QACRpC,MAAMuB,GAAG,CAAC;YAACsE,iBAAiB;YAAM7D,MAAM;QAAO;QAC/CnC,OAAO0B,GAAG,CACR,GAAG7D,WAAW4E,OAAO,CAAC,sBAAsB,EAAEF,KAAK0D,KAAK,CAAC,OAAO,EAAE1H,gBAAgBgE,KAAK2D,QAAQ,GAAG;QAEpG,OAAO;YAAC3D;QAAI;IACd;IAEA,IAAIzC,QAAQe,UAAU,EAAE;QACtB,MAAM,IAAI7B,UACR,gFACA;IAEJ;IAEAmB,MAAMuB,GAAG,CAAC;QAACS,MAAM;IAAO;IAExB,IAAI;QACF,MAAM3D,MAAM;YACVwB;YACAI,WAAWD,MAAMgG,UAAU,CAAC;QAC9B;IACF,EAAE,OAAOxC,OAAO;QACd,MAAMY,UAAUZ,iBAAiBS,QAAQT,MAAMY,OAAO,GAAGF,OAAOV;QAChE,MAAM,IAAI3E,UAAU,CAAC,cAAc,EAAEuF,SAAS,EAAE;IAClD;IAEA,MAAM6B,eAAe,MAAMlI;IAE3B8B,OAAO0B,GAAG,CACR,GAAG7D,WAAW4E,OAAO,CAAC,sBAAsB,EAAE2D,aAAaH,KAAK,CAAC,OAAO,EAAE1H,gBAAgB6H,aAAaF,QAAQ,GAAG;IAEpH,OAAO;QAAC3D,MAAM6D;IAAY;AAC5B"}
1
+ {"version":3,"sources":["../../../src/actions/init/initAction.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {\n exitCodes,\n type SanityOrgUser,\n subdebug,\n type TelemetryUserProperties,\n} from '@sanity/cli-core'\nimport {logSymbols, spinner} from '@sanity/cli-core/ux'\nimport {type TelemetryTrace} from '@sanity/telemetry'\nimport {type Framework, frameworks} from '@vercel/frameworks'\nimport deburr from 'lodash-es/deburr.js'\n\nimport {promptForConfigFiles} from '../../prompts/init/nextjs.js'\nimport {getCliUser} from '../../services/user.js'\nimport {CLIInitStepCompleted, type InitStepResult} from '../../telemetry/init.telemetry.js'\nimport {detectFrameworkRecord} from '../../util/detectFramework.js'\nimport {formatCliErrorMessages} from '../../util/formatCliErrorMessages.js'\nimport {getProjectDefaults} from '../../util/getProjectDefaults.js'\nimport {validateSession} from '../auth/ensureAuthenticated.js'\nimport {getProviderName} from '../auth/getProviderName.js'\nimport {login} from '../auth/login/login.js'\nimport {LOGIN_REQUIRED_MESSAGE} from '../auth/login/loginInstructions.js'\nimport {detectAvailableEditors} from '../mcp/detectAvailableEditors.js'\nimport {setupMCP} from '../mcp/setupMCP.js'\nimport {setupSkills} from '../skills/setupSkills.js'\nimport {checkNextJsReactCompatibility} from './checkNextJsReactCompatibility.js'\nimport {determineAppTemplate} from './determineAppTemplate.js'\nimport {createOrAppendEnvVars} from './env/createOrAppendEnvVars.js'\nimport {initApp} from './initApp.js'\nimport {InitError} from './initError.js'\nimport {flagOrDefault, shouldPrompt, writeStagingEnvIfNeeded} from './initHelpers.js'\nimport {initNextJs} from './initNextJs.js'\nimport {initStudio} from './initStudio.js'\nimport {getPlan} from './plan/getPlan.js'\nimport {createProjectFromName} from './project/createProjectFromName.js'\nimport {getProjectDetails} from './project/getProjectDetails.js'\nimport {getProjectOutputPath} from './project/getProjectOutputPath.js'\nimport {checkIsRemoteTemplate, getGitHubRepoInfo, type RepoInfo} from './remoteTemplate.js'\nimport {type InitContext, type InitOptions} from './types.js'\n\nconst debug = subdebug('init')\n\nexport async function initAction(options: InitOptions, context: InitContext): Promise<void> {\n const {output, workDir} = context\n\n if (options.argType) {\n throw new InitError(\n options.argType === 'plugin'\n ? 'Initializing plugins through the CLI is no longer supported'\n : `Unknown init type \"${options.argType}\"`,\n 1,\n )\n }\n\n const trace = context.telemetry.trace(CLIInitStepCompleted)\n\n if (options.reconfigure) {\n throw new InitError('--reconfigure is deprecated - manual configuration is now required', 1)\n }\n\n if (options.project && options.organization) {\n throw new InitError(\n 'You have specified both a project and an organization. To move a project to an organization please visit https://www.sanity.io/manage',\n 1,\n )\n }\n\n const defaultConfig = options.datasetDefault\n let showDefaultConfigPrompt = !defaultConfig\n if (options.dataset || options.visibility || options.datasetDefault || options.unattended) {\n showDefaultConfigPrompt = false\n }\n\n const detectedFramework = await detectFrameworkRecord({\n frameworkList: frameworks as readonly Framework[],\n rootPath: workDir,\n })\n const isNextJs = detectedFramework?.slug === 'nextjs'\n\n let remoteTemplateInfo: RepoInfo | undefined\n if (options.template && checkIsRemoteTemplate(options.template)) {\n remoteTemplateInfo = await getGitHubRepoInfo(options.template, options.templateToken)\n }\n\n if (detectedFramework && detectedFramework.slug !== 'sanity' && remoteTemplateInfo) {\n throw new InitError(\n `A remote template cannot be used with a detected framework. Detected: ${detectedFramework.name}`,\n 1,\n )\n }\n\n const isAppTemplate = options.template ? determineAppTemplate(options.template) : false\n\n if (options.unattended) {\n checkFlagsInUnattendedMode(options, {isAppTemplate, isNextJs})\n }\n\n trace.start()\n trace.log({\n flags: {\n bare: options.bare,\n coupon: options.coupon,\n defaultConfig,\n env: options.env,\n git: typeof options.git === 'string' ? options.git : undefined,\n plan: options.projectPlan,\n reconfigure: options.reconfigure,\n unattended: options.unattended,\n },\n step: 'start',\n })\n\n const planId = await getPlan(options, output, trace)\n\n let envFilenameDefault = '.env'\n if (detectedFramework && detectedFramework.slug === 'nextjs') {\n envFilenameDefault = '.env.local'\n }\n const envFilename = typeof options.env === 'string' ? options.env : envFilenameDefault\n\n const {user} = await ensureAuthenticated(options, output, trace)\n if (!isAppTemplate) {\n output.log(`${logSymbols.success} Fetching existing projects`)\n output.log('')\n }\n\n let newProject: string | undefined\n if (options.projectName) {\n newProject = await createProjectFromName({\n coupon: options.coupon,\n createProjectName: options.projectName,\n dataset: options.dataset,\n organization: options.organization,\n planId,\n user,\n visibility: options.visibility,\n })\n }\n\n const {datasetName, displayName, isFirstProject, organizationId, projectId} =\n await getProjectDetails({\n coupon: options.coupon,\n dataset: options.dataset,\n datasetDefault: options.datasetDefault,\n isAppTemplate,\n newProject,\n organization: options.organization,\n output,\n planId,\n project: options.project,\n showDefaultConfigPrompt,\n trace,\n unattended: options.unattended,\n user,\n visibility: options.visibility,\n })\n\n if (options.bare) {\n output.log(`${logSymbols.success} Below are your project details`)\n output.log('')\n output.log(`Project ID: ${styleText('cyan', projectId)}`)\n output.log(`Dataset: ${styleText('cyan', datasetName)}`)\n output.log(\n `\\nYou can find your project on Sanity Manage — https://www.sanity.io/manage/project/${projectId}\\n`,\n )\n trace.complete()\n return\n }\n\n // Detect editors once, then share the result with MCP and skills setup so\n // we don't pay the detection cost (filesystem probes + CLI execa calls) twice.\n const detectedEditors =\n options.mcpMode === 'skip' && options.skillsMode === 'skip'\n ? []\n : await detectAvailableEditors()\n\n const mcpResult = await setupMCP({\n editors: detectedEditors,\n mode: options.mcpMode,\n output,\n skillsMode: options.skillsMode,\n })\n\n trace.log({\n configuredEditors: mcpResult.configuredEditors,\n detectedEditors: mcpResult.detectedEditors,\n skipped: mcpResult.skipped,\n step: 'mcpSetup',\n })\n if (mcpResult.error) {\n trace.error(mcpResult.error)\n }\n const mcpConfigured = mcpResult.configuredEditors\n\n async function installSkills(): Promise<void> {\n if (mcpResult.skillsToInstall.length === 0) return\n try {\n const skillsResult = await setupSkills({\n agents: mcpResult.skillsToInstall,\n output,\n })\n trace.log({\n installedAgents: skillsResult.installedAgents,\n skipped: skillsResult.skipped,\n step: 'skillsSetup',\n })\n if (skillsResult.error) {\n trace.error(skillsResult.error)\n }\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error))\n debug('Unexpected error from setupSkills %O', err)\n output.warn(`Could not install Sanity agent skills: ${err.message}`)\n trace.error(err)\n }\n }\n\n // Install skills right after the MCP/skills prompt so the progress + result\n // surface in sequence, rather than trailing the studio \"Success!\" output.\n await installSkills()\n\n const {alreadyConfiguredEditors} = mcpResult\n if (alreadyConfiguredEditors.length > 0) {\n const label =\n alreadyConfiguredEditors.length === 1\n ? `${alreadyConfiguredEditors[0]} already configured for Sanity MCP`\n : `${alreadyConfiguredEditors.length} editors already configured for Sanity MCP`\n spinner(label).start().succeed()\n }\n\n let initNext = flagOrDefault(options.nextjsAddConfigFiles, false)\n if (isNextJs && shouldPrompt(options.unattended, options.nextjsAddConfigFiles)) {\n initNext = await promptForConfigFiles()\n }\n\n trace.log({\n detectedFramework: detectedFramework?.name,\n selectedOption: initNext ? 'yes' : 'no',\n step: 'useDetectedFramework',\n })\n\n const sluggedName = deburr(displayName.toLowerCase())\n .replaceAll(/\\s+/g, '-')\n .replaceAll(/[^a-z0-9-]/g, '')\n\n const initFramework = initNext\n\n const defaults = await getProjectDefaults({isPlugin: false, workDir})\n\n const outputPath = await getProjectOutputPath({\n initFramework,\n outputPath: options.outputPath,\n sluggedName,\n unattended: options.unattended,\n useEnv: Boolean(options.env),\n workDir,\n })\n\n if (isNextJs) {\n await checkNextJsReactCompatibility({\n detectedFramework,\n output,\n outputPath,\n })\n }\n\n if (initNext) {\n await initNextJs({\n datasetName,\n detectedFramework,\n envFilename,\n mcpConfigured,\n options,\n output,\n projectId,\n trace,\n workDir,\n })\n trace.complete()\n return\n }\n\n if (options.env) {\n await createOrAppendEnvVars({\n envVars: {\n DATASET: datasetName,\n PROJECT_ID: projectId,\n },\n filename: envFilename,\n framework: detectedFramework,\n log: false,\n output,\n outputPath,\n })\n await writeStagingEnvIfNeeded(output, outputPath)\n trace.complete()\n return\n }\n\n // Workbench is opt-in (no prompt): the flag swaps the scaffolded\n // `sanity.cli.*` over to `unstable_defineApp` — the branded app is the sole\n // workbench opt-in.\n const workbench = flagOrDefault(options.unstableWorkbench, false)\n\n const sharedParams = {\n defaults,\n mcpConfigured,\n options,\n organizationId,\n output,\n outputPath,\n remoteTemplateInfo,\n sluggedName,\n trace,\n workbench,\n workDir,\n }\n\n await (isAppTemplate\n ? initApp({...sharedParams, datasetName, projectId})\n : initStudio({\n ...sharedParams,\n datasetName,\n displayName,\n isFirstProject,\n projectId,\n }))\n\n trace.complete()\n}\n\nfunction checkFlagsInUnattendedMode(\n options: InitOptions,\n {isAppTemplate, isNextJs}: {isAppTemplate: boolean; isNextJs: boolean},\n): void {\n debug('Unattended mode, validating required options')\n\n const errors: string[] = []\n\n if (isAppTemplate) {\n if (!options.outputPath) {\n errors.push(\n 'Output path is required in unattended mode. Pass it with `--output-path <path>`.',\n )\n }\n\n if (options.projectName && !options.organization) {\n errors.push(\n 'Organization is required when creating a project in unattended mode. Pass it with `--organization <id>`.',\n )\n } else if (!options.project && !options.organization) {\n errors.push(\n 'Project or organization is required for app templates in unattended mode. ' +\n 'Pass `--project <id>` or `--organization <id>`. To create a project, pass ' +\n '`--project-name <name>` with `--organization <id>`.',\n )\n }\n } else {\n if (!isNextJs && !options.bare && !options.outputPath) {\n errors.push(\n 'Output path is required in unattended mode. Pass it with `--output-path <path>`.',\n )\n }\n\n if (!options.project && !options.projectName) {\n errors.push(\n 'Project is required in unattended mode. Pass it with `--project <id>` or `--project-name <name>`.',\n )\n }\n\n if (!options.project && !options.organization) {\n errors.push(\n 'Organization is required when creating a project in unattended mode. Pass it with `--organization <id>`.',\n )\n }\n }\n\n if (errors.length > 0) {\n throw new InitError(formatCliErrorMessages(errors), exitCodes.USAGE_ERROR)\n }\n}\n\nasync function ensureAuthenticated(\n options: InitOptions,\n output: InitContext['output'],\n trace: TelemetryTrace<TelemetryUserProperties, InitStepResult>,\n): Promise<{user: SanityOrgUser}> {\n const user = await validateSession()\n\n if (user) {\n trace.log({alreadyLoggedIn: true, step: 'login'})\n output.log(\n `${logSymbols.success} You are logged in as ${user.email} using ${getProviderName(user.provider)}`,\n )\n return {user}\n }\n\n if (options.unattended) {\n throw new InitError(LOGIN_REQUIRED_MESSAGE, exitCodes.RUNTIME_ERROR)\n }\n\n trace.log({step: 'login'})\n output.warn(LOGIN_REQUIRED_MESSAGE)\n\n try {\n await login({\n output,\n telemetry: trace.newContext('login'),\n })\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new InitError(`Login failed: ${message}`, 1)\n }\n\n const loggedInUser = await getCliUser()\n\n output.log(\n `${logSymbols.success} You are logged in as ${loggedInUser.email} using ${getProviderName(loggedInUser.provider)}`,\n )\n return {user: loggedInUser}\n}\n"],"names":["styleText","exitCodes","subdebug","logSymbols","spinner","frameworks","deburr","promptForConfigFiles","getCliUser","CLIInitStepCompleted","detectFrameworkRecord","formatCliErrorMessages","getProjectDefaults","validateSession","getProviderName","login","LOGIN_REQUIRED_MESSAGE","detectAvailableEditors","setupMCP","setupSkills","checkNextJsReactCompatibility","determineAppTemplate","createOrAppendEnvVars","initApp","InitError","flagOrDefault","shouldPrompt","writeStagingEnvIfNeeded","initNextJs","initStudio","getPlan","createProjectFromName","getProjectDetails","getProjectOutputPath","checkIsRemoteTemplate","getGitHubRepoInfo","debug","initAction","options","context","output","workDir","argType","trace","telemetry","reconfigure","project","organization","defaultConfig","datasetDefault","showDefaultConfigPrompt","dataset","visibility","unattended","detectedFramework","frameworkList","rootPath","isNextJs","slug","remoteTemplateInfo","template","templateToken","name","isAppTemplate","checkFlagsInUnattendedMode","start","log","flags","bare","coupon","env","git","undefined","plan","projectPlan","step","planId","envFilenameDefault","envFilename","user","ensureAuthenticated","success","newProject","projectName","createProjectName","datasetName","displayName","isFirstProject","organizationId","projectId","complete","detectedEditors","mcpMode","skillsMode","mcpResult","editors","mode","configuredEditors","skipped","error","mcpConfigured","installSkills","skillsToInstall","length","skillsResult","agents","installedAgents","err","Error","String","warn","message","alreadyConfiguredEditors","label","succeed","initNext","nextjsAddConfigFiles","selectedOption","sluggedName","toLowerCase","replaceAll","initFramework","defaults","isPlugin","outputPath","useEnv","Boolean","envVars","DATASET","PROJECT_ID","filename","framework","workbench","unstableWorkbench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OAAO;QACd,MAAMY,UAAUZ,iBAAiBS,QAAQT,MAAMY,OAAO,GAAGF,OAAOV;QAChE,MAAM,IAAI3E,UAAU,CAAC,cAAc,EAAEuF,SAAS,EAAE;IAClD;IAEA,MAAMgC,eAAe,MAAMvI;IAE3BgC,OAAO0B,GAAG,CACR,GAAG/D,WAAW8E,OAAO,CAAC,sBAAsB,EAAE8D,aAAaJ,KAAK,CAAC,OAAO,EAAE7H,gBAAgBiI,aAAaH,QAAQ,GAAG;IAEpH,OAAO;QAAC7D,MAAMgE;IAAY;AAC5B"}
@@ -3,6 +3,7 @@ import { relative, resolve } from 'node:path';
3
3
  import { doImport, getCliConfigUncached } from '@sanity/cli-core';
4
4
  import { getErrorMessage } from '@sanity/cli-core/errors';
5
5
  import { spinner } from '@sanity/cli-core/ux';
6
+ import { isWorkbenchApp } from '@sanity/workbench-cli';
6
7
  import { coreAppManifestSchema } from './types.js';
7
8
  /**
8
9
  * The title change a deploy would sync from the manifest to the user
@@ -30,13 +31,15 @@ const sanitizeIconPath = new URL('sanitizeIcon.js', import.meta.url).href;
30
31
  return mod.sanitizeIcon;
31
32
  }
32
33
  /**
33
- * Resolves app.icon from config (a file path) to an SVG string for the manifest.
34
- * The manifest expects the SVG string inline, not a path.
34
+ * Resolves app.icon from config (a file path) to a sanitized SVG string. Used
35
+ * both for the manifest and, on deploy, for the icon shipped to Brett the
36
+ * manifest expects the SVG inline, not a path.
35
37
  *
36
38
  * The file is sanitized through the same allowlist as the studio manifest's
37
39
  * icon resolver (see {@link lazySanitizeIcon}) so both manifest paths inline the
38
40
  * same trusted subset of SVG markup.
39
- */ async function readIconFromPath(workDir, iconPath) {
41
+ * @internal
42
+ */ export async function readIconFromPath(workDir, iconPath) {
40
43
  const resolvedPath = resolve(workDir, iconPath);
41
44
  const pathRelativeToWorkDir = relative(workDir, resolvedPath);
42
45
  if (pathRelativeToWorkDir.startsWith('..')) {
@@ -77,6 +80,7 @@ const sanitizeIconPath = new URL('sanitizeIcon.js', import.meta.url).href;
77
80
  spin.info('Manifest creation skipped: no icon or title found in app configuration');
78
81
  return undefined;
79
82
  }
83
+ const slug = isWorkbenchApp(app) ? app.slug : undefined;
80
84
  const manifest = coreAppManifestSchema.parse({
81
85
  version: '1',
82
86
  ...icon ? {
@@ -90,7 +94,10 @@ const sanitizeIconPath = new URL('sanitizeIcon.js', import.meta.url).href;
90
94
  } : {},
91
95
  ...app.priority === undefined ? {} : {
92
96
  priority: app.priority
93
- }
97
+ },
98
+ ...slug ? {
99
+ slug
100
+ } : {}
94
101
  });
95
102
  spin.succeed(`Extracted manifest`);
96
103
  return manifest;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/manifest/extractCoreAppManifest.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\nimport {relative, resolve} from 'node:path'\n\nimport {doImport, getCliConfigUncached} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\n\nimport {type sanitizeIcon as sanitizeIconFn} from './sanitizeIcon.js'\nimport {type CoreAppManifest, coreAppManifestSchema} from './types.js'\n\ninterface ExtractCoreAppManifestOptions {\n workDir: string\n}\n\n/**\n * The title change a deploy would sync from the manifest to the user\n * application, or null when the titles already match (or none is set).\n *\n * @internal\n */\nexport function resolveTitleUpdate(\n manifest: CoreAppManifest | undefined,\n application: {title: string | null},\n): {from: string | null; to: string} | null {\n if (manifest?.title === undefined || manifest.title === application.title) {\n return null\n }\n return {from: application.title, to: manifest.title}\n}\n\nconst sanitizeIconPath = new URL('sanitizeIcon.js', import.meta.url).href\n\n/**\n * Lazy-load {@link sanitizeIconFn} so `isomorphic-dompurify` (and its jsdom\n * dependency) stays out of the CLI's eager import graph. The studio manifest\n * resolver lazy-loads its icon machinery for the same reason; this path runs in\n * the main process (not the manifest worker), so only an app deploy that\n * actually has an icon pays the cost.\n */\nasync function lazySanitizeIcon(): Promise<typeof sanitizeIconFn> {\n const mod = await doImport(sanitizeIconPath)\n return mod.sanitizeIcon\n}\n\n/**\n * Resolves app.icon from config (a file path) to an SVG string for the manifest.\n * The manifest expects the SVG string inline, not a path.\n *\n * The file is sanitized through the same allowlist as the studio manifest's\n * icon resolver (see {@link lazySanitizeIcon}) so both manifest paths inline the\n * same trusted subset of SVG markup.\n */\nasync function readIconFromPath(workDir: string, iconPath: string): Promise<string> {\n const resolvedPath = resolve(workDir, iconPath)\n const pathRelativeToWorkDir = relative(workDir, resolvedPath)\n if (pathRelativeToWorkDir.startsWith('..')) {\n throw new Error(\n `Icon path \"${iconPath}\" resolves outside the project directory and is not allowed.`,\n )\n }\n\n let content: string\n try {\n content = await readFile(resolvedPath, 'utf8')\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(\n `Could not read icon file at \"${iconPath}\" (resolved: ${resolvedPath}): ${message}`,\n {cause: err},\n )\n }\n\n const trimmed = content.trim()\n if (!/<svg[\\s>]/i.test(trimmed)) {\n throw new Error(\n `Icon file at \"${iconPath}\" does not contain an SVG element. App manifest icons must be SVG files.`,\n )\n }\n\n const sanitizeIcon = await lazySanitizeIcon()\n return sanitizeIcon(trimmed)\n}\n\n/**\n * Unlike studio manifest extraction, skips schema/tool parsing. The config's\n * `app.icon` is a file path; its content is read and inlined in the manifest.\n */\nexport async function extractCoreAppManifest(\n options: ExtractCoreAppManifestOptions,\n): Promise<CoreAppManifest | undefined> {\n const {workDir} = options\n const {app} = await getCliConfigUncached(workDir)\n if (!app) {\n return undefined\n }\n\n const spin = spinner('Extracting manifest').start()\n\n try {\n let icon: string | undefined\n if (app.icon) {\n icon = await readIconFromPath(workDir, app.icon)\n }\n\n if (!icon && !app.title) {\n spin.info('Manifest creation skipped: no icon or title found in app configuration')\n return undefined\n }\n\n const manifest: CoreAppManifest = coreAppManifestSchema.parse({\n version: '1',\n ...(icon ? {icon} : {}),\n ...(app.title ? {title: app.title} : {}),\n ...(app.group ? {group: app.group} : {}),\n ...(app.priority === undefined ? {} : {priority: app.priority}),\n })\n\n spin.succeed(`Extracted manifest`)\n\n return manifest\n } catch (err) {\n const message = getErrorMessage(err)\n spin.fail(message)\n throw err\n }\n}\n"],"names":["readFile","relative","resolve","doImport","getCliConfigUncached","getErrorMessage","spinner","coreAppManifestSchema","resolveTitleUpdate","manifest","application","title","undefined","from","to","sanitizeIconPath","URL","url","href","lazySanitizeIcon","mod","sanitizeIcon","readIconFromPath","workDir","iconPath","resolvedPath","pathRelativeToWorkDir","startsWith","Error","content","err","message","String","cause","trimmed","trim","test","extractCoreAppManifest","options","app","spin","start","icon","info","parse","version","group","priority","succeed","fail"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,SAAQC,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAE3C,SAAQC,QAAQ,EAAEC,oBAAoB,QAAO,mBAAkB;AAC/D,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,OAAO,QAAO,sBAAqB;AAG3C,SAA8BC,qBAAqB,QAAO,aAAY;AAMtE;;;;;CAKC,GACD,OAAO,SAASC,mBACdC,QAAqC,EACrCC,WAAmC;IAEnC,IAAID,UAAUE,UAAUC,aAAaH,SAASE,KAAK,KAAKD,YAAYC,KAAK,EAAE;QACzE,OAAO;IACT;IACA,OAAO;QAACE,MAAMH,YAAYC,KAAK;QAAEG,IAAIL,SAASE,KAAK;IAAA;AACrD;AAEA,MAAMI,mBAAmB,IAAIC,IAAI,mBAAmB,YAAYC,GAAG,EAAEC,IAAI;AAEzE;;;;;;CAMC,GACD,eAAeC;IACb,MAAMC,MAAM,MAAMjB,SAASY;IAC3B,OAAOK,IAAIC,YAAY;AACzB;AAEA;;;;;;;CAOC,GACD,eAAeC,iBAAiBC,OAAe,EAAEC,QAAgB;IAC/D,MAAMC,eAAevB,QAAQqB,SAASC;IACtC,MAAME,wBAAwBzB,SAASsB,SAASE;IAChD,IAAIC,sBAAsBC,UAAU,CAAC,OAAO;QAC1C,MAAM,IAAIC,MACR,CAAC,WAAW,EAAEJ,SAA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AAIP,IAAIQ,QAAQ,KAAKnC,YAAY,CAAC,IAAI;gBAACmC,UAAUR,IAAIQ,QAAQ;YAAA,CAAC;QAChE;QAEAP,KAAKQ,OAAO,CAAC,CAAC,kBAAkB,CAAC;QAEjC,OAAOvC;IACT,EAAE,OAAOqB,KAAK;QACZ,MAAMC,UAAU1B,gBAAgByB;QAChCU,KAAKS,IAAI,CAAClB;QACV,MAAMD;IACR;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/manifest/extractCoreAppManifest.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\nimport {relative, resolve} from 'node:path'\n\nimport {doImport, getCliConfigUncached} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {isWorkbenchApp} from '@sanity/workbench-cli'\n\nimport {type sanitizeIcon as sanitizeIconFn} from './sanitizeIcon.js'\nimport {type CoreAppManifest, coreAppManifestSchema} from './types.js'\n\ninterface ExtractCoreAppManifestOptions {\n workDir: string\n}\n\n/**\n * The title change a deploy would sync from the manifest to the user\n * application, or null when the titles already match (or none is set).\n *\n * @internal\n */\nexport function resolveTitleUpdate(\n manifest: CoreAppManifest | undefined,\n application: {title: string | null},\n): {from: string | null; to: string} | null {\n if (manifest?.title === undefined || manifest.title === application.title) {\n return null\n }\n return {from: application.title, to: manifest.title}\n}\n\nconst sanitizeIconPath = new URL('sanitizeIcon.js', import.meta.url).href\n\n/**\n * Lazy-load {@link sanitizeIconFn} so `isomorphic-dompurify` (and its jsdom\n * dependency) stays out of the CLI's eager import graph. The studio manifest\n * resolver lazy-loads its icon machinery for the same reason; this path runs in\n * the main process (not the manifest worker), so only an app deploy that\n * actually has an icon pays the cost.\n */\nasync function lazySanitizeIcon(): Promise<typeof sanitizeIconFn> {\n const mod = await doImport(sanitizeIconPath)\n return mod.sanitizeIcon\n}\n\n/**\n * Resolves app.icon from config (a file path) to a sanitized SVG string. Used\n * both for the manifest and, on deploy, for the icon shipped to Brett — the\n * manifest expects the SVG inline, not a path.\n *\n * The file is sanitized through the same allowlist as the studio manifest's\n * icon resolver (see {@link lazySanitizeIcon}) so both manifest paths inline the\n * same trusted subset of SVG markup.\n * @internal\n */\nexport async function readIconFromPath(workDir: string, iconPath: string): Promise<string> {\n const resolvedPath = resolve(workDir, iconPath)\n const pathRelativeToWorkDir = relative(workDir, resolvedPath)\n if (pathRelativeToWorkDir.startsWith('..')) {\n throw new Error(\n `Icon path \"${iconPath}\" resolves outside the project directory and is not allowed.`,\n )\n }\n\n let content: string\n try {\n content = await readFile(resolvedPath, 'utf8')\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(\n `Could not read icon file at \"${iconPath}\" (resolved: ${resolvedPath}): ${message}`,\n {cause: err},\n )\n }\n\n const trimmed = content.trim()\n if (!/<svg[\\s>]/i.test(trimmed)) {\n throw new Error(\n `Icon file at \"${iconPath}\" does not contain an SVG element. App manifest icons must be SVG files.`,\n )\n }\n\n const sanitizeIcon = await lazySanitizeIcon()\n return sanitizeIcon(trimmed)\n}\n\n/**\n * Unlike studio manifest extraction, skips schema/tool parsing. The config's\n * `app.icon` is a file path; its content is read and inlined in the manifest.\n */\nexport async function extractCoreAppManifest(\n options: ExtractCoreAppManifestOptions,\n): Promise<CoreAppManifest | undefined> {\n const {workDir} = options\n const {app} = await getCliConfigUncached(workDir)\n if (!app) {\n return undefined\n }\n\n const spin = spinner('Extracting manifest').start()\n\n try {\n let icon: string | undefined\n if (app.icon) {\n icon = await readIconFromPath(workDir, app.icon)\n }\n\n if (!icon && !app.title) {\n spin.info('Manifest creation skipped: no icon or title found in app configuration')\n return undefined\n }\n\n const slug = isWorkbenchApp(app) ? app.slug : undefined\n\n const manifest: CoreAppManifest = coreAppManifestSchema.parse({\n version: '1',\n ...(icon ? {icon} : {}),\n ...(app.title ? {title: app.title} : {}),\n ...(app.group ? {group: app.group} : {}),\n ...(app.priority === undefined ? {} : {priority: app.priority}),\n ...(slug ? {slug} : {}),\n })\n\n spin.succeed(`Extracted manifest`)\n\n return manifest\n } catch (err) {\n const message = getErrorMessage(err)\n spin.fail(message)\n throw err\n }\n}\n"],"names":["readFile","relative","resolve","doImport","getCliConfigUncached","getErrorMessage","spinner","isWorkbenchApp","coreAppManifestSchema","resolveTitleUpdate","manifest","application","title","undefined","from","to","sanitizeIconPath","URL","url","href","lazySanitizeIcon","mod","sanitizeIcon","readIconFromPath","workDir","iconPath","resolvedPath","pathRelativeToWorkDir","startsWith","Error","content","err","message","String","cause","trimmed","trim","test","extractCoreAppManifest","options","app","spin","start","icon","info","slug","parse","version","group","priority","succeed","fail"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,SAAQC,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAE3C,SAAQC,QAAQ,EAAEC,oBAAoB,QAAO,mBAAkB;AAC/D,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,cAAc,QAAO,wBAAuB;AAGpD,SAA8BC,qBAAqB,QAAO,aAAY;AAMtE;;;;;CAKC,GACD,OAAO,SAASC,mBACdC,QAAqC,EACrCC,WAAmC;IAEnC,IAAID,UAAUE,UAAUC,aAAaH,SAASE,KAAK,KAAKD,YAAYC,KAAK,EAAE;QACzE,OAAO;IACT;IACA,OAAO;QAACE,MAAMH,YAAYC,KAAK;QAAEG,IAAIL,SAASE,KAAK;IAAA;AACrD;AAEA,MAAMI,mBAAmB,IAAIC,IAAI,mBAAmB,YAAYC,GAAG,EAAEC,IAAI;AAEzE;;;;;;CAMC,GACD,eAAeC;IACb,MAAMC,MAAM,MAAMlB,SAASa;IAC3B,OAAOK,IAAIC,YAAY;AACzB;AAEA;;;;;;;;;CASC,GACD,OAAO,eAAeC,iBAAiBC,OAAe,EAAEC,QAAgB;IACtE,MAAMC,eAAexB,QAAQsB,SAASC;IACtC,MAAME,wBAAwB1B,SAASuB,SAASE;IAChD,IAAIC,sBAAsBC,UAAU,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B,KAAK;YAAA,IAAI,CAAC,CAAC;YACvC,GAAI4B,IAAIQ,KAAK,GAAG;gBAACA,OAAOR,IAAIQ,KAAK;YAAA,IAAI,CAAC,CAAC;YACvC,GAAIR,IAAIS,QAAQ,KAAKpC,YAAY,CAAC,IAAI;gBAACoC,UAAUT,IAAIS,QAAQ;YAAA,CAAC;YAC9D,GAAIJ,OAAO;gBAACA;YAAI,IAAI,CAAC,CAAC;QACxB;QAEAJ,KAAKS,OAAO,CAAC,CAAC,kBAAkB,CAAC;QAEjC,OAAOxC;IACT,EAAE,OAAOqB,KAAK;QACZ,MAAMC,UAAU3B,gBAAgB0B;QAChCU,KAAKU,IAAI,CAACnB;QACV,MAAMD;IACR;AACF"}
@@ -0,0 +1,10 @@
1
+ export const MIGRATIONS_DIRECTORY = 'migrations';
2
+ export const MIGRATION_SCRIPT_EXTENSIONS = [
3
+ 'mjs',
4
+ 'js',
5
+ 'ts',
6
+ 'cjs'
7
+ ];
8
+ export const DEFAULT_API_VERSION = 'v2024-01-29';
9
+
10
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/migration/constants.ts"],"sourcesContent":["export const MIGRATIONS_DIRECTORY = 'migrations'\nexport const MIGRATION_SCRIPT_EXTENSIONS = ['mjs', 'js', 'ts', 'cjs']\nexport const DEFAULT_API_VERSION = 'v2024-01-29'\n"],"names":["MIGRATIONS_DIRECTORY","MIGRATION_SCRIPT_EXTENSIONS","DEFAULT_API_VERSION"],"mappings":"AAAA,OAAO,MAAMA,uBAAuB,aAAY;AAChD,OAAO,MAAMC,8BAA8B;IAAC;IAAO;IAAM;IAAM;CAAM,CAAA;AACrE,OAAO,MAAMC,sBAAsB,cAAa"}
@@ -0,0 +1,16 @@
1
+ const VERSION_PATTERN = /^v\d+-\d+-\d+$|^vX$/ // Matches version strings like vYYYY-MM-DD or vX
2
+ ;
3
+ /**
4
+ * Ensures that the provided API version string is in the correct format.
5
+ * If the version does not start with 'v', it will be prefixed with 'v'.
6
+ * If the version does not match the expected pattern, an error will be thrown.
7
+ */ export function ensureApiVersionFormat(version) {
8
+ const normalizedVersion = version.startsWith('v') ? version : `v${version}`;
9
+ // Check if the version matches the expected pattern
10
+ if (!VERSION_PATTERN.test(normalizedVersion)) {
11
+ throw new Error(`Invalid API version format: ${normalizedVersion}. Expected format: vYYYY-MM-DD or vX`);
12
+ }
13
+ return normalizedVersion;
14
+ }
15
+
16
+ //# sourceMappingURL=ensureApiVersionFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/migration/ensureApiVersionFormat.ts"],"sourcesContent":["import {type APIConfig} from '@sanity/migrate'\n\ntype ApiVersion = APIConfig['apiVersion']\n\nconst VERSION_PATTERN = /^v\\d+-\\d+-\\d+$|^vX$/ // Matches version strings like vYYYY-MM-DD or vX\n\n/**\n * Ensures that the provided API version string is in the correct format.\n * If the version does not start with 'v', it will be prefixed with 'v'.\n * If the version does not match the expected pattern, an error will be thrown.\n */\nexport function ensureApiVersionFormat(version: string): ApiVersion {\n const normalizedVersion = version.startsWith('v') ? version : `v${version}`\n\n // Check if the version matches the expected pattern\n if (!VERSION_PATTERN.test(normalizedVersion)) {\n throw new Error(\n `Invalid API version format: ${normalizedVersion}. Expected format: vYYYY-MM-DD or vX`,\n )\n }\n\n return normalizedVersion as ApiVersion\n}\n"],"names":["VERSION_PATTERN","ensureApiVersionFormat","version","normalizedVersion","startsWith","test","Error"],"mappings":"AAIA,MAAMA,kBAAkB,sBAAsB,iDAAiD;;AAE/F;;;;CAIC,GACD,OAAO,SAASC,uBAAuBC,OAAe;IACpD,MAAMC,oBAAoBD,QAAQE,UAAU,CAAC,OAAOF,UAAU,CAAC,CAAC,EAAEA,SAAS;IAE3E,oDAAoD;IACpD,IAAI,CAACF,gBAAgBK,IAAI,CAACF,oBAAoB;QAC5C,MAAM,IAAIG,MACR,CAAC,4BAA4B,EAAEH,kBAAkB,oCAAoC,CAAC;IAE1F;IAEA,OAAOA;AACT"}
@@ -0,0 +1,13 @@
1
+ import { access } from 'node:fs/promises';
2
+ /**
3
+ * Checks if a file exists and can be "accessed".
4
+ * Prone to race conditions, but good enough for our use cases.
5
+ *
6
+ * @param filePath - The path to the file to check
7
+ * @returns A promise that resolves to true if the file exists, false otherwise
8
+ * @internal
9
+ */ export function fileExists(filePath) {
10
+ return access(filePath).then(()=>true, ()=>false);
11
+ }
12
+
13
+ //# sourceMappingURL=fileExists.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/migration/fileExists.ts"],"sourcesContent":["import {access} from 'node:fs/promises'\n\n/**\n * Checks if a file exists and can be \"accessed\".\n * Prone to race conditions, but good enough for our use cases.\n *\n * @param filePath - The path to the file to check\n * @returns A promise that resolves to true if the file exists, false otherwise\n * @internal\n */\nexport function fileExists(filePath: string): Promise<boolean> {\n return access(filePath).then(\n () => true,\n () => false,\n )\n}\n"],"names":["access","fileExists","filePath","then"],"mappings":"AAAA,SAAQA,MAAM,QAAO,mBAAkB;AAEvC;;;;;;;CAOC,GACD,OAAO,SAASC,WAAWC,QAAgB;IACzC,OAAOF,OAAOE,UAAUC,IAAI,CAC1B,IAAM,MACN,IAAM;AAEV"}
@@ -0,0 +1,155 @@
1
+ import { isatty } from 'node:tty';
2
+ import { styleText } from 'node:util';
3
+ import { convertToTree, formatTree, maxKeyLength } from './tree.js';
4
+ const isTty = isatty(1);
5
+ export function prettyFormat({ indentSize = 0, migration, subject }) {
6
+ return (Array.isArray(subject) ? subject : [
7
+ subject
8
+ ]).map((subjectEntry)=>{
9
+ if (subjectEntry.type === 'transaction') {
10
+ return [
11
+ [
12
+ badge('transaction', 'info'),
13
+ subjectEntry.id === undefined ? null : styleText('underline', subjectEntry.id)
14
+ ].filter(Boolean).join(' '),
15
+ indent(prettyFormat({
16
+ indentSize: indentSize,
17
+ migration,
18
+ subject: subjectEntry.mutations
19
+ }))
20
+ ].join('\n\n');
21
+ }
22
+ return prettyFormatMutation({
23
+ indentSize,
24
+ migration,
25
+ subject: subjectEntry
26
+ });
27
+ }).join('\n\n');
28
+ }
29
+ function encodeItemRef(ref) {
30
+ return typeof ref === 'number' ? ref : ref._key;
31
+ }
32
+ function badgeStyle(variant, label) {
33
+ const styles = {
34
+ destructive: styleText([
35
+ 'bgRed',
36
+ 'black',
37
+ 'bold'
38
+ ], label),
39
+ incremental: styleText([
40
+ 'bgGreen',
41
+ 'black',
42
+ 'bold'
43
+ ], label),
44
+ info: styleText([
45
+ 'bgWhite',
46
+ 'black'
47
+ ], label),
48
+ maybeDestructive: styleText([
49
+ 'bgYellow',
50
+ 'black',
51
+ 'bold'
52
+ ], label)
53
+ };
54
+ return styles[variant];
55
+ }
56
+ function badge(label, variant) {
57
+ if (!isTty) {
58
+ return `[${label}]`;
59
+ }
60
+ return badgeStyle(variant, ` ${label} `);
61
+ }
62
+ const mutationImpact = {
63
+ create: 'incremental',
64
+ createIfNotExists: 'incremental',
65
+ createOrReplace: 'maybeDestructive',
66
+ delete: 'destructive',
67
+ patch: 'maybeDestructive'
68
+ };
69
+ function documentId(mutation) {
70
+ if ('id' in mutation) {
71
+ return mutation.id;
72
+ }
73
+ if ('document' in mutation) {
74
+ return mutation.document._id;
75
+ }
76
+ return undefined;
77
+ }
78
+ const listFormatter = new Intl.ListFormat('en-US', {
79
+ type: 'disjunction'
80
+ });
81
+ function mutationHeader(mutation, migration) {
82
+ const mutationType = badge(mutation.type, mutationImpact[mutation.type]);
83
+ const documentType = 'document' in mutation || migration.documentTypes ? badge('document' in mutation ? mutation.document._type : listFormatter.format(migration.documentTypes ?? []), 'info') : null;
84
+ // TODO: Should we list documentType when a mutation can be yielded for any document type?
85
+ return [
86
+ mutationType,
87
+ documentType,
88
+ styleText('underline', documentId(mutation) ?? '')
89
+ ].filter(Boolean).join(' ');
90
+ }
91
+ function prettyFormatMutation({ indentSize = 0, migration, subject }) {
92
+ const lock = 'options' in subject ? styleText('cyan', `(if revision==${subject.options?.ifRevision})`) : '';
93
+ const header = [
94
+ mutationHeader(subject, migration),
95
+ lock
96
+ ].join(' ');
97
+ const padding = ' '.repeat(indentSize);
98
+ if (subject.type === 'create' || subject.type === 'createIfNotExists' || subject.type === 'createOrReplace') {
99
+ return [
100
+ header,
101
+ '\n',
102
+ indent(JSON.stringify(subject.document, null, 2), indentSize)
103
+ ].join('');
104
+ }
105
+ if (subject.type === 'patch') {
106
+ const tree = convertToTree(subject.patches.flat());
107
+ const paddingLength = Math.max(maxKeyLength(tree.children) + 2, 30);
108
+ return [
109
+ header,
110
+ '\n',
111
+ formatTree({
112
+ getMessage: (patch)=>formatPatchMutation(patch),
113
+ indent: padding,
114
+ node: tree.children,
115
+ paddingLength
116
+ })
117
+ ].join('');
118
+ }
119
+ return header;
120
+ }
121
+ function formatPatchMutation(patch) {
122
+ const { op } = patch;
123
+ const formattedType = styleText('bold', op.type);
124
+ if (op.type === 'unset') {
125
+ return `${styleText('red', formattedType)}()`;
126
+ }
127
+ if (op.type === 'diffMatchPatch') {
128
+ return `${styleText('yellow', formattedType)}(${op.value})`;
129
+ }
130
+ if (op.type === 'inc' || op.type === 'dec') {
131
+ return `${styleText('yellow', formattedType)}(${op.amount})`;
132
+ }
133
+ if (op.type === 'set') {
134
+ return `${styleText('yellow', formattedType)}(${JSON.stringify(op.value)})`;
135
+ }
136
+ if (op.type === 'setIfMissing') {
137
+ return `${styleText('green', formattedType)}(${JSON.stringify(op.value)})`;
138
+ }
139
+ if (op.type === 'insert') {
140
+ return `${styleText('green', formattedType)}(${op.position}, ${encodeItemRef(op.referenceItem)}, ${JSON.stringify(op.items)})`;
141
+ }
142
+ if (op.type === 'replace') {
143
+ return `${styleText('yellow', formattedType)}(${encodeItemRef(op.referenceItem)}, ${JSON.stringify(op.items)})`;
144
+ }
145
+ if (op.type === 'truncate') {
146
+ return `${styleText('red', formattedType)}(${op.startIndex}, ${op.endIndex})`;
147
+ }
148
+ throw new Error(`Invalid operation type: ${op.type}`);
149
+ }
150
+ function indent(subject, size = 2) {
151
+ const padding = ' '.repeat(size);
152
+ return subject.split('\n').map((line)=>padding + line).join('\n');
153
+ }
154
+
155
+ //# sourceMappingURL=prettyMutationFormatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/migration/prettyMutationFormatter.ts"],"sourcesContent":["import {isatty} from 'node:tty'\nimport {styleText} from 'node:util'\n\nimport {type Migration, type Mutation, type NodePatch, type Transaction} from '@sanity/migrate'\nimport {type KeyedSegment} from '@sanity/types'\n\nimport {convertToTree, formatTree, maxKeyLength} from './tree.js'\n\ntype ItemRef = number | string\ntype Impact = 'destructive' | 'incremental' | 'maybeDestructive'\ntype Variant = 'info' | Impact\n\nconst isTty = isatty(1)\n\ninterface FormatterOptions<Subject> {\n migration: Migration\n subject: Subject\n\n indentSize?: number\n}\n\nexport function prettyFormat({\n indentSize = 0,\n migration,\n subject,\n}: FormatterOptions<(Mutation | Transaction)[] | Mutation | Transaction>): string {\n return (Array.isArray(subject) ? subject : [subject])\n .map((subjectEntry) => {\n if (subjectEntry.type === 'transaction') {\n return [\n [\n badge('transaction', 'info'),\n subjectEntry.id === undefined ? null : styleText('underline', subjectEntry.id),\n ]\n .filter(Boolean)\n .join(' '),\n indent(\n prettyFormat({\n indentSize: indentSize,\n migration,\n subject: subjectEntry.mutations,\n }),\n ),\n ].join('\\n\\n')\n }\n return prettyFormatMutation({\n indentSize,\n migration,\n subject: subjectEntry,\n })\n })\n .join('\\n\\n')\n}\n\nfunction encodeItemRef(ref: KeyedSegment | number): ItemRef {\n return typeof ref === 'number' ? ref : ref._key\n}\n\nfunction badgeStyle(variant: Variant, label: string) {\n const styles: Record<Variant, string> = {\n destructive: styleText(['bgRed', 'black', 'bold'], label),\n incremental: styleText(['bgGreen', 'black', 'bold'], label),\n info: styleText(['bgWhite', 'black'], label),\n maybeDestructive: styleText(['bgYellow', 'black', 'bold'], label),\n }\n\n return styles[variant]\n}\n\nfunction badge(label: string, variant: Variant): string {\n if (!isTty) {\n return `[${label}]`\n }\n\n return badgeStyle(variant, ` ${label} `)\n}\n\nconst mutationImpact: Record<Mutation['type'], Impact> = {\n create: 'incremental',\n createIfNotExists: 'incremental',\n createOrReplace: 'maybeDestructive',\n delete: 'destructive',\n patch: 'maybeDestructive',\n}\n\nfunction documentId(mutation: Mutation): string | undefined {\n if ('id' in mutation) {\n return mutation.id\n }\n\n if ('document' in mutation) {\n return mutation.document._id\n }\n\n return undefined\n}\n\nconst listFormatter = new Intl.ListFormat('en-US', {\n type: 'disjunction',\n})\n\nfunction mutationHeader(mutation: Mutation, migration: Migration): string {\n const mutationType = badge(mutation.type, mutationImpact[mutation.type])\n\n const documentType =\n 'document' in mutation || migration.documentTypes\n ? badge(\n 'document' in mutation\n ? mutation.document._type\n : listFormatter.format(migration.documentTypes ?? []),\n 'info',\n )\n : null\n\n // TODO: Should we list documentType when a mutation can be yielded for any document type?\n return [mutationType, documentType, styleText('underline', documentId(mutation) ?? '')]\n .filter(Boolean)\n .join(' ')\n}\n\nfunction prettyFormatMutation({\n indentSize = 0,\n migration,\n subject,\n}: FormatterOptions<Mutation>): string {\n const lock =\n 'options' in subject ? styleText('cyan', `(if revision==${subject.options?.ifRevision})`) : ''\n const header = [mutationHeader(subject, migration), lock].join(' ')\n const padding = ' '.repeat(indentSize)\n\n if (\n subject.type === 'create' ||\n subject.type === 'createIfNotExists' ||\n subject.type === 'createOrReplace'\n ) {\n return [header, '\\n', indent(JSON.stringify(subject.document, null, 2), indentSize)].join('')\n }\n\n if (subject.type === 'patch') {\n const tree = convertToTree<NodePatch>(subject.patches.flat())\n const paddingLength = Math.max(maxKeyLength(tree.children) + 2, 30)\n\n return [\n header,\n '\\n',\n formatTree<NodePatch>({\n getMessage: (patch: NodePatch) => formatPatchMutation(patch),\n indent: padding,\n node: tree.children,\n paddingLength,\n }),\n ].join('')\n }\n\n return header\n}\n\nfunction formatPatchMutation(patch: NodePatch): string {\n const {op} = patch\n const formattedType = styleText('bold', op.type)\n if (op.type === 'unset') {\n return `${styleText('red', formattedType)}()`\n }\n if (op.type === 'diffMatchPatch') {\n return `${styleText('yellow', formattedType)}(${op.value})`\n }\n if (op.type === 'inc' || op.type === 'dec') {\n return `${styleText('yellow', formattedType)}(${op.amount})`\n }\n if (op.type === 'set') {\n return `${styleText('yellow', formattedType)}(${JSON.stringify(op.value)})`\n }\n if (op.type === 'setIfMissing') {\n return `${styleText('green', formattedType)}(${JSON.stringify(op.value)})`\n }\n if (op.type === 'insert') {\n return `${styleText('green', formattedType)}(${op.position}, ${encodeItemRef(\n op.referenceItem,\n )}, ${JSON.stringify(op.items)})`\n }\n if (op.type === 'replace') {\n return `${styleText('yellow', formattedType)}(${encodeItemRef(op.referenceItem)}, ${JSON.stringify(\n op.items,\n )})`\n }\n if (op.type === 'truncate') {\n return `${styleText('red', formattedType)}(${op.startIndex}, ${op.endIndex})`\n }\n\n throw new Error(`Invalid operation type: ${(op as {type: string}).type}`)\n}\n\nfunction indent(subject: string, size = 2): string {\n const padding = ' '.repeat(size)\n\n return subject\n .split('\\n')\n .map((line) => padding + line)\n .join('\\n')\n}\n"],"names":["isatty","styleText","convertToTree","formatTree","maxKeyLength","isTty","prettyFormat","indentSize","migration","subject","Array","isArray","map","subjectEntry","type","badge","id","undefined","filter","Boolean","join","indent","mutations","prettyFormatMutation","encodeItemRef","ref","_key","badgeStyle","variant","label","styles","destructive","incremental","info","maybeDestructive","mutationImpact","create","createIfNotExists","createOrReplace","delete","patch","documentId","mutation","document","_id","listFormatter","Intl","ListFormat","mutationHeader","mutationType","documentType","documentTypes","_type","format","lock","options","ifRevision","header","padding","repeat","JSON","stringify","tree","patches","flat","paddingLength","Math","max","children","getMessage","formatPatchMutation","node","op","formattedType","value","amount","position","referenceItem","items","startIndex","endIndex","Error","size","split","line"],"mappings":"AAAA,SAAQA,MAAM,QAAO,WAAU;AAC/B,SAAQC,SAAS,QAAO,YAAW;AAKnC,SAAQC,aAAa,EAAEC,UAAU,EAAEC,YAAY,QAAO,YAAW;AAMjE,MAAMC,QAA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B,OAAO,GAAGb,UAAU,SAASwE,eAAe,CAAC,EAAED,GAAGI,QAAQ,CAAC,EAAE,EAAEpD,cAC7DgD,GAAGK,aAAa,EAChB,EAAE,EAAEjB,KAAKC,SAAS,CAACW,GAAGM,KAAK,EAAE,CAAC,CAAC;IACnC;IACA,IAAIN,GAAG1D,IAAI,KAAK,WAAW;QACzB,OAAO,GAAGb,UAAU,UAAUwE,eAAe,CAAC,EAAEjD,cAAcgD,GAAGK,aAAa,EAAE,EAAE,EAAEjB,KAAKC,SAAS,CAChGW,GAAGM,KAAK,EACR,CAAC,CAAC;IACN;IACA,IAAIN,GAAG1D,IAAI,KAAK,YAAY;QAC1B,OAAO,GAAGb,UAAU,OAAOwE,eAAe,CAAC,EAAED,GAAGO,UAAU,CAAC,EAAE,EAAEP,GAAGQ,QAAQ,CAAC,CAAC,CAAC;IAC/E;IAEA,MAAM,IAAIC,MAAM,CAAC,wBAAwB,EAAE,AAACT,GAAsB1D,IAAI,EAAE;AAC1E;AAEA,SAASO,OAAOZ,OAAe,EAAEyE,OAAO,CAAC;IACvC,MAAMxB,UAAU,IAAIC,MAAM,CAACuB;IAE3B,OAAOzE,QACJ0E,KAAK,CAAC,MACNvE,GAAG,CAAC,CAACwE,OAAS1B,UAAU0B,MACxBhE,IAAI,CAAC;AACV"}
@@ -0,0 +1,75 @@
1
+ import path from 'node:path';
2
+ import { importModule, subdebug } from '@sanity/cli-core';
3
+ import { MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY } from './constants.js';
4
+ import { fileExists } from './fileExists.js';
5
+ const debug = subdebug('migration:resolveMigrationScript');
6
+ /**
7
+ * Resolves the potential paths to a migration script.
8
+ * Considers the following paths (where `<ext>` is 'mjs', 'js', 'ts' or 'cjs'):
9
+ *
10
+ * - `<migrationsDir>/<migrationName>.<ext>`
11
+ * - `<migrationsDir>/<migrationName>/index.<ext>`
12
+ *
13
+ * Note that all possible paths are returned, even if the files do not exist.
14
+ * Check the `mod` property to see if a module could actually be loaded.
15
+ *
16
+ * @param workDir - Working directory of the studio
17
+ * @param migrationName - The name of the migration directory to resolve
18
+ * @returns An array of potential migration scripts
19
+ * @internal
20
+ */ export async function resolveMigrationScript(workDir, migrationName) {
21
+ const locations = [
22
+ migrationName,
23
+ path.join(migrationName, 'index')
24
+ ];
25
+ const results = [];
26
+ for (const location of locations){
27
+ for (const ext of MIGRATION_SCRIPT_EXTENSIONS){
28
+ const relativePath = path.join(MIGRATIONS_DIRECTORY, `${location}.${ext}`);
29
+ const absolutePath = path.resolve(workDir, relativePath);
30
+ let mod;
31
+ // Check if the file exists before trying to import it
32
+ const exists = await fileExists(absolutePath);
33
+ if (!exists) {
34
+ continue;
35
+ }
36
+ try {
37
+ debug(`importing migration from ${absolutePath}`);
38
+ const imported = await importModule(absolutePath, {
39
+ default: false
40
+ });
41
+ // Handle both ESM and CJS default exports
42
+ mod = imported;
43
+ } catch (err) {
44
+ debug(`error importing migration from ${absolutePath}`, err);
45
+ // Ignore MODULE_NOT_FOUND errors, but throw others
46
+ if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ERR_MODULE_NOT_FOUND') {
47
+ throw new Error(`Error loading migration: ${err.message}`, {
48
+ cause: err
49
+ });
50
+ }
51
+ }
52
+ results.push({
53
+ absolutePath,
54
+ mod,
55
+ relativePath
56
+ });
57
+ }
58
+ }
59
+ return results;
60
+ }
61
+ /**
62
+ * Checks whether or not the passed resolved migration script is actually loadable (eg has a default export)
63
+ *
64
+ * @param script - The resolved migration script to check
65
+ * @returns `true` if the script is loadable, `false` otherwise
66
+ * @internal
67
+ */ export function isLoadableMigrationScript(script) {
68
+ if (script.mod === undefined || typeof script.mod.default !== 'object' || script.mod.default === null || Array.isArray(script.mod.default)) {
69
+ return false;
70
+ }
71
+ const mod = script.mod.default;
72
+ return typeof mod.title === 'string' && mod.migrate !== undefined;
73
+ }
74
+
75
+ //# sourceMappingURL=resolveMigrationScript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/migration/resolveMigrationScript.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {importModule, subdebug} from '@sanity/cli-core'\nimport {type Migration} from '@sanity/migrate'\n\nimport {MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY} from './constants.js'\nimport {fileExists} from './fileExists.js'\n\ninterface ResolvedMigrationScript {\n /**\n * Absolute path to the migration script\n */\n absolutePath: string\n /**\n * Relative path from the working directory to the migration script\n */\n relativePath: string\n\n /**\n * The migration module, if it could be resolved - otherwise `undefined`\n */\n mod?: {default: Migration; down?: unknown; up?: unknown}\n}\n\nconst debug = subdebug('migration:resolveMigrationScript')\n\n/**\n * Resolves the potential paths to a migration script.\n * Considers the following paths (where `<ext>` is 'mjs', 'js', 'ts' or 'cjs'):\n *\n * - `<migrationsDir>/<migrationName>.<ext>`\n * - `<migrationsDir>/<migrationName>/index.<ext>`\n *\n * Note that all possible paths are returned, even if the files do not exist.\n * Check the `mod` property to see if a module could actually be loaded.\n *\n * @param workDir - Working directory of the studio\n * @param migrationName - The name of the migration directory to resolve\n * @returns An array of potential migration scripts\n * @internal\n */\nexport async function resolveMigrationScript(\n workDir: string,\n migrationName: string,\n): Promise<ResolvedMigrationScript[]> {\n const locations = [migrationName, path.join(migrationName, 'index')]\n const results: ResolvedMigrationScript[] = []\n\n for (const location of locations) {\n for (const ext of MIGRATION_SCRIPT_EXTENSIONS) {\n const relativePath = path.join(MIGRATIONS_DIRECTORY, `${location}.${ext}`)\n const absolutePath = path.resolve(workDir, relativePath)\n let mod: {default: Migration; down?: unknown; up?: unknown} | undefined\n\n // Check if the file exists before trying to import it\n const exists = await fileExists(absolutePath)\n if (!exists) {\n continue\n }\n\n try {\n debug(`importing migration from ${absolutePath}`)\n const imported = await importModule<{default: Migration; down?: unknown; up?: unknown}>(\n absolutePath,\n {\n default: false,\n },\n )\n // Handle both ESM and CJS default exports\n mod = imported\n } catch (err) {\n debug(`error importing migration from ${absolutePath}`, err)\n // Ignore MODULE_NOT_FOUND errors, but throw others\n if (\n (err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND' &&\n (err as NodeJS.ErrnoException).code !== 'ERR_MODULE_NOT_FOUND'\n ) {\n throw new Error(`Error loading migration: ${(err as Error).message}`, {cause: err})\n }\n }\n\n results.push({absolutePath, mod, relativePath})\n }\n }\n\n return results\n}\n\n/**\n * Checks whether or not the passed resolved migration script is actually loadable (eg has a default export)\n *\n * @param script - The resolved migration script to check\n * @returns `true` if the script is loadable, `false` otherwise\n * @internal\n */\nexport function isLoadableMigrationScript(\n script: ResolvedMigrationScript,\n): script is Required<ResolvedMigrationScript> {\n if (\n script.mod === undefined ||\n typeof script.mod.default !== 'object' ||\n script.mod.default === null ||\n Array.isArray(script.mod.default)\n ) {\n return false\n }\n\n const mod = script.mod.default\n return typeof mod.title === 'string' && mod.migrate !== undefined\n}\n"],"names":["path","importModule","subdebug","MIGRATION_SCRIPT_EXTENSIONS","MIGRATIONS_DIRECTORY","fileExists","debug","resolveMigrationScript","workDir","migrationName","locations","join","results","location","ext","relativePath","absolutePath","resolve","mod","exists","imported","default","err","code","Error","message","cause","push","isLoadableMigrationScript","script","undefined","Array","isArray","title","migrate"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,YAAY,EAAEC,QAAQ,QAAO,mBAAkB;AAGvD,SAAQC,2BAA2B,EAAEC,oBAAoB,QAAO,iBAAgB;AAChF,SAAQC,UAAU,QAAO,kBAAiB;AAkB1C,MAAMC,QAAQJ,SAAS;AAEvB;;;;;;;;;;;;;;CAcC,GACD,OAAO,eAAeK,uBACpBC,OAAe,EACfC,aAAqB;IAErB,MAAMC,YAAY;QAACD;QAAeT,KAAKW,IAAI,CAACF,eAAe;KAAS;IACpE,MAAMG,UAAqC,EAAE;IAE7C,KAAK,MAAMC,YAAYH,UAAW;QAChC,KAAK,MAAMI,OAAOX,4BAA6B;YAC7C,MAAMY,eAAef,KAAKW,IAAI,CAACP,sBAAsB,GAAGS,SAAS,CAAC,EAAEC,KAAK;YACzE,MAAME,eAAehB,KAAKiB,OAAO,CAACT,SAASO;YAC3C,IAAIG;YAEJ,sDAAsD;YACtD,MAAMC,SAAS,MAAMd,WAAWW;YAChC,IAAI,CAACG,QAAQ;gBACX;YACF;YAEA,IAAI;gBACFb,MAAM,CAAC,yBAAyB,EAAEU,cAAc;gBAChD,MAAMI,WAAW,MAAMnB,aACrBe,cACA;oBACEK,SAAS;gBACX;gBAEF,0CAA0C;gBAC1CH,MAAME;YACR,EAAE,OAAOE,KAAK;gBACZhB,MAAM,CAAC,+BAA+B,EAAEU,cAAc,EAAEM;gBACxD,mDAAmD;gBACnD,IACE,AAACA,IAA8BC,IAAI,KAAK,sBACxC,AAACD,IAA8BC,IAAI,KAAK,wBACxC;oBACA,MAAM,IAAIC,MAAM,CAAC,yBAAyB,EAAE,AAACF,IAAcG,OAAO,EAAE,EAAE;wBAACC,OAAOJ;oBAAG;gBACnF;YACF;YAEAV,QAAQe,IAAI,CAAC;gBAACX;gBAAcE;gBAAKH;YAAY;QAC/C;IACF;IAEA,OAAOH;AACT;AAEA;;;;;;CAMC,GACD,OAAO,SAASgB,0BACdC,MAA+B;IAE/B,IACEA,OAAOX,GAAG,KAAKY,aACf,OAAOD,OAAOX,GAAG,CAACG,OAAO,KAAK,YAC9BQ,OAAOX,GAAG,CAACG,OAAO,KAAK,QACvBU,MAAMC,OAAO,CAACH,OAAOX,GAAG,CAACG,OAAO,GAChC;QACA,OAAO;IACT;IAEA,MAAMH,MAAMW,OAAOX,GAAG,CAACG,OAAO;IAC9B,OAAO,OAAOH,IAAIe,KAAK,KAAK,YAAYf,IAAIgB,OAAO,KAAKJ;AAC1D"}
@@ -0,0 +1,50 @@
1
+ import { readdir } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY } from './constants.js';
4
+ import { isLoadableMigrationScript, resolveMigrationScript } from './resolveMigrationScript.js';
5
+ /**
6
+ * Removes migration script extensions from a filename
7
+ *
8
+ * @param fileName - The filename to process
9
+ * @returns The filename without the extension
10
+ * @internal
11
+ */ function removeMigrationScriptExtension(fileName) {
12
+ // Remove `.ts`, `.js` etc from the end of a filename
13
+ const ext = MIGRATION_SCRIPT_EXTENSIONS.find((e)=>fileName.endsWith(`.${e}`));
14
+ return ext ? path.basename(fileName, `.${ext}`) : fileName;
15
+ }
16
+ /**
17
+ * Resolves all migrations in the studio working directory
18
+ *
19
+ * @param workDir - The studio working directory
20
+ * @returns Array of migrations and their respective paths
21
+ * @internal
22
+ */ export async function resolveMigrations(workDir) {
23
+ const migrationsDir = path.join(workDir, MIGRATIONS_DIRECTORY);
24
+ const migrationEntries = await readdir(migrationsDir, {
25
+ withFileTypes: true
26
+ });
27
+ const migrations = [];
28
+ const seen = new Set();
29
+ for (const entry of migrationEntries){
30
+ const entryName = entry.isDirectory() ? entry.name : removeMigrationScriptExtension(entry.name);
31
+ // A file (e.g. `foo.ts`) and a directory (e.g. `foo/`) can both map to the
32
+ // same id; only resolve each id once.
33
+ if (seen.has(entryName)) {
34
+ continue;
35
+ }
36
+ // `resolveMigrationScript` may return several loadable candidates for a
37
+ // single id (e.g. both `foo.ts` and `foo/index.ts`). List it just once.
38
+ const candidate = (await resolveMigrationScript(workDir, entryName)).find((script)=>isLoadableMigrationScript(script));
39
+ if (candidate) {
40
+ seen.add(entryName);
41
+ migrations.push({
42
+ id: entryName,
43
+ migration: candidate.mod.default
44
+ });
45
+ }
46
+ }
47
+ return migrations;
48
+ }
49
+
50
+ //# sourceMappingURL=resolveMigrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/migration/resolveMigrations.ts"],"sourcesContent":["import {readdir} from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {type Migration} from '@sanity/migrate'\n\nimport {MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY} from './constants.js'\nimport {isLoadableMigrationScript, resolveMigrationScript} from './resolveMigrationScript.js'\n\n/**\n * A resolved migration, where you are guaranteed that the migration file exists\n *\n * @internal\n */\ninterface ResolvedMigration {\n id: string\n migration: Migration\n}\n\n/**\n * Removes migration script extensions from a filename\n *\n * @param fileName - The filename to process\n * @returns The filename without the extension\n * @internal\n */\nfunction removeMigrationScriptExtension(fileName: string): string {\n // Remove `.ts`, `.js` etc from the end of a filename\n const ext = MIGRATION_SCRIPT_EXTENSIONS.find((e) => fileName.endsWith(`.${e}`))\n return ext ? path.basename(fileName, `.${ext}`) : fileName\n}\n\n/**\n * Resolves all migrations in the studio working directory\n *\n * @param workDir - The studio working directory\n * @returns Array of migrations and their respective paths\n * @internal\n */\nexport async function resolveMigrations(workDir: string): Promise<ResolvedMigration[]> {\n const migrationsDir = path.join(workDir, MIGRATIONS_DIRECTORY)\n const migrationEntries = await readdir(migrationsDir, {withFileTypes: true})\n\n const migrations: ResolvedMigration[] = []\n const seen = new Set<string>()\n for (const entry of migrationEntries) {\n const entryName = entry.isDirectory() ? entry.name : removeMigrationScriptExtension(entry.name)\n // A file (e.g. `foo.ts`) and a directory (e.g. `foo/`) can both map to the\n // same id; only resolve each id once.\n if (seen.has(entryName)) {\n continue\n }\n\n // `resolveMigrationScript` may return several loadable candidates for a\n // single id (e.g. both `foo.ts` and `foo/index.ts`). List it just once.\n const candidate = (await resolveMigrationScript(workDir, entryName)).find((script) =>\n isLoadableMigrationScript(script),\n )\n if (candidate) {\n seen.add(entryName)\n migrations.push({id: entryName, migration: candidate.mod.default})\n }\n }\n\n return migrations\n}\n"],"names":["readdir","path","MIGRATION_SCRIPT_EXTENSIONS","MIGRATIONS_DIRECTORY","isLoadableMigrationScript","resolveMigrationScript","removeMigrationScriptExtension","fileName","ext","find","e","endsWith","basename","resolveMigrations","workDir","migrationsDir","join","migrationEntries","withFileTypes","migrations","seen","Set","entry","entryName","isDirectory","name","has","candidate","script","add","push","id","migration","mod","default"],"mappings":"AAAA,SAAQA,OAAO,QAAO,mBAAkB;AACxC,OAAOC,UAAU,YAAW;AAI5B,SAAQC,2BAA2B,EAAEC,oBAAoB,QAAO,iBAAgB;AAChF,SAAQC,yBAAyB,EAAEC,sBAAsB,QAAO,8BAA6B;AAY7F;;;;;;CAMC,GACD,SAASC,+BAA+BC,QAAgB;IACtD,qDAAqD;IACrD,MAAMC,MAAMN,4BAA4BO,IAAI,CAAC,CAACC,IAAMH,SAASI,QAAQ,CAAC,CAAC,CAAC,EAAED,GAAG;IAC7E,OAAOF,MAAMP,KAAKW,QAAQ,CAACL,UAAU,CAAC,CAAC,EAAEC,KAAK,IAAID;AACpD;AAEA;;;;;;CAMC,GACD,OAAO,eAAeM,kBAAkBC,OAAe;IACrD,MAAMC,gBAAgBd,KAAKe,IAAI,CAACF,SAASX;IACzC,MAAMc,mBAAmB,MAAMjB,QAAQe,eAAe;QAACG,eAAe;IAAI;IAE1E,MAAMC,aAAkC,EAAE;IAC1C,MAAMC,OAAO,IAAIC;IACjB,KAAK,MAAMC,SAASL,iBAAkB;QACpC,MAAMM,YAAYD,MAAME,WAAW,KAAKF,MAAMG,IAAI,GAAGnB,+BAA+BgB,MAAMG,IAAI;QAC9F,2EAA2E;QAC3E,sCAAsC;QACtC,IAAIL,KAAKM,GAAG,CAACH,YAAY;YACvB;QACF;QAEA,wEAAwE;QACxE,wEAAwE;QACxE,MAAMI,YAAY,AAAC,CAAA,MAAMtB,uBAAuBS,SAASS,UAAS,EAAGd,IAAI,CAAC,CAACmB,SACzExB,0BAA0BwB;QAE5B,IAAID,WAAW;YACbP,KAAKS,GAAG,CAACN;YACTJ,WAAWW,IAAI,CAAC;gBAACC,IAAIR;gBAAWS,WAAWL,UAAUM,GAAG,CAACC,OAAO;YAAA;QAClE;IACF;IAEA,OAAOf;AACT"}
@@ -0,0 +1,7 @@
1
+ export { minimalAdvanced } from './minimalAdvanced.js';
2
+ export { minimalSimple } from './minimalSimple.js';
3
+ export { renameField } from './renameField.js';
4
+ export { renameType } from './renameType.js';
5
+ export { stringToPTE } from './stringToPTE.js';
6
+
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/actions/migration/templates/index.ts"],"sourcesContent":["export {minimalAdvanced} from './minimalAdvanced.js'\nexport {minimalSimple} from './minimalSimple.js'\nexport {renameField} from './renameField.js'\nexport {renameType} from './renameType.js'\nexport {stringToPTE} from './stringToPTE.js'\n"],"names":["minimalAdvanced","minimalSimple","renameField","renameType","stringToPTE"],"mappings":"AAAA,SAAQA,eAAe,QAAO,uBAAsB;AACpD,SAAQC,aAAa,QAAO,qBAAoB;AAChD,SAAQC,WAAW,QAAO,mBAAkB;AAC5C,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,WAAW,QAAO,mBAAkB"}