@sanity/cli 3.72.1 → 3.72.2-canary.32

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.
@@ -26706,7 +26706,7 @@ async function applyEnvVariables(root2, envData, targetName = ".env") {
26706
26706
  });
26707
26707
  if (templatePath)
26708
26708
  try {
26709
- const templateContent = await fs.readFile(path$3.join(root2, templatePath), "utf8"), { projectId, dataset, readToken = "" } = envData, findAndReplaceVariable = (content, varRegex, value, useQuotes2) => {
26709
+ const templateContent = await fs.readFile(path$3.join(root2, templatePath), "utf8"), { projectId, dataset, readToken = "", writeToken = "" } = envData, findAndReplaceVariable = (content, varRegex, value, useQuotes2) => {
26710
26710
  const varPattern = typeof varRegex == "string" ? varRegex : varRegex.source, pattern = new RegExp(`.*${varPattern}=.*$`, "gm"), matches = content.matchAll(pattern);
26711
26711
  return Array.from(matches).reduce((updatedContent, match2) => {
26712
26712
  if (!match2[0]) return updatedContent;
@@ -26721,7 +26721,8 @@ async function applyEnvVariables(root2, envData, targetName = ".env") {
26721
26721
  const vars = [
26722
26722
  { pattern: ENV_VAR.PROJECT_ID, value: projectId },
26723
26723
  { pattern: ENV_VAR.DATASET, value: dataset },
26724
- { pattern: ENV_VAR.READ_TOKEN, value: readToken }
26724
+ { pattern: ENV_VAR.READ_TOKEN, value: readToken },
26725
+ { pattern: ENV_VAR.WRITE_TOKEN, value: writeToken }
26725
26726
  ], useQuotes = templateContent.includes('="');
26726
26727
  for (const { pattern, value } of vars)
26727
26728
  envContent = findAndReplaceVariable(envContent, pattern, value, useQuotes);
@@ -46513,23 +46514,8 @@ var typescriptExports = requireTypescript(), typescript = /* @__PURE__ */ loadEn
46513
46514
  __proto__: null,
46514
46515
  default: typescript
46515
46516
  }, [typescriptExports]);
46516
- const defaultTemplate$1 = `
46517
- import {defineCliConfig} from 'sanity/cli'
46518
-
46519
- export default defineCliConfig({
46520
- api: {
46521
- projectId: '%projectId%',
46522
- dataset: '%dataset%'
46523
- },
46524
- /**
46525
- * Enable auto-updates for studios.
46526
- * Learn more at https://www.sanity.io/docs/cli#auto-updates
46527
- */
46528
- autoUpdates: __BOOL__autoUpdates__,
46529
- })
46530
- `;
46531
- function createCliConfig(options2) {
46532
- const variables = options2, template = defaultTemplate$1.trimStart(), ast = mainExports.parse(template, { parser });
46517
+ function processTemplate(options2) {
46518
+ const { template, variables, includeBooleanTransform = !1 } = options2, ast = mainExports.parse(template.trimStart(), { parser });
46533
46519
  return traverse__default.default(ast, {
46534
46520
  StringLiteral: {
46535
46521
  enter({ node }) {
@@ -46543,24 +46529,60 @@ function createCliConfig(options2) {
46543
46529
  node.value = typeof newValue == "string" ? newValue : "";
46544
46530
  }
46545
46531
  },
46546
- Identifier: {
46547
- enter(path2) {
46548
- if (!path2.node.name.startsWith("__BOOL__"))
46549
- return;
46550
- const variableName = path2.node.name.replace(
46551
- /^__BOOL__(.+?)__$/,
46552
- "$1"
46553
- );
46554
- if (!(variableName in variables))
46555
- throw new Error(`Template variable '${variableName}' not defined`);
46556
- const value = variables[variableName];
46557
- if (typeof value != "boolean")
46558
- throw new Error(`Expected boolean value for '${variableName}'`);
46559
- path2.replaceWith({ type: "BooleanLiteral", value });
46532
+ ...includeBooleanTransform && {
46533
+ Identifier: {
46534
+ enter(path2) {
46535
+ if (!path2.node.name.startsWith("__BOOL__"))
46536
+ return;
46537
+ const variableName = path2.node.name.replace(/^__BOOL__(.+?)__$/, "$1");
46538
+ if (!(variableName in variables))
46539
+ throw new Error(`Template variable '${variableName.toString()}' not defined`);
46540
+ const value = variables[variableName];
46541
+ if (typeof value != "boolean")
46542
+ throw new Error(`Expected boolean value for '${variableName.toString()}'`);
46543
+ path2.replaceWith({ type: "BooleanLiteral", value });
46544
+ }
46560
46545
  }
46561
46546
  }
46562
46547
  }), mainExports.print(ast, { quote: "single" }).code;
46563
46548
  }
46549
+ const defaultTemplate$1 = `
46550
+ import {defineCliConfig} from 'sanity/cli'
46551
+
46552
+ export default defineCliConfig({
46553
+ api: {
46554
+ projectId: '%projectId%',
46555
+ dataset: '%dataset%'
46556
+ },
46557
+ /**
46558
+ * Enable auto-updates for studios.
46559
+ * Learn more at https://www.sanity.io/docs/cli#auto-updates
46560
+ */
46561
+ autoUpdates: __BOOL__autoUpdates__,
46562
+ })
46563
+ `;
46564
+ function createCliConfig(options2) {
46565
+ return processTemplate({
46566
+ template: defaultTemplate$1,
46567
+ variables: options2,
46568
+ includeBooleanTransform: !0
46569
+ });
46570
+ }
46571
+ const defaultCoreAppTemplate = `
46572
+ import {defineCliConfig} from 'sanity/cli'
46573
+
46574
+ export default defineCliConfig({
46575
+ __experimental_coreAppConfiguration: {
46576
+ appLocation: '%appLocation%'
46577
+ },
46578
+ })
46579
+ `;
46580
+ function createCoreAppCliConfig(options2) {
46581
+ return processTemplate({
46582
+ template: defaultCoreAppTemplate,
46583
+ variables: options2
46584
+ });
46585
+ }
46564
46586
  /*!
46565
46587
  * isobject <https://github.com/jonschlinkert/isobject>
46566
46588
  *
@@ -46629,7 +46651,7 @@ function createPackageManifest(data) {
46629
46651
  ...getCommonManifest(data),
46630
46652
  main: "package.json",
46631
46653
  keywords: ["sanity"],
46632
- scripts: {
46654
+ scripts: data.scripts || {
46633
46655
  dev: "sanity dev",
46634
46656
  start: "sanity start",
46635
46657
  build: "sanity build",
@@ -46698,25 +46720,42 @@ export default defineConfig({
46698
46720
  };
46699
46721
  function createStudioConfig(options2) {
46700
46722
  const variables = { ...defaultVariables, ...options2.variables };
46701
- if (typeof options2.template == "function")
46702
- return options2.template(variables).trimStart();
46703
- const template = (options2.template || defaultTemplate).trimStart(), ast = mainExports.parse(template, { parser });
46704
- return traverse__default.default(ast, {
46705
- StringLiteral: {
46706
- enter({ node }) {
46707
- const value = node.value;
46708
- if (!value.startsWith("%") || !value.endsWith("%"))
46709
- return;
46710
- const variableName = value.slice(1, -1);
46711
- if (!(variableName in variables))
46712
- throw new Error(`Template variable '${value}' not defined`);
46713
- const newValue = variables[variableName];
46714
- node.value = typeof newValue == "string" ? newValue : "";
46715
- }
46716
- }
46717
- }), mainExports.print(ast, { quote: "single" }).code;
46723
+ return typeof options2.template == "function" ? options2.template(variables).trimStart() : processTemplate({
46724
+ template: options2.template || defaultTemplate,
46725
+ variables
46726
+ });
46718
46727
  }
46719
- const blogTemplate = {}, cleanTemplate = {}, configTemplate$3 = `
46728
+ const coreAppTemplates = ["core-app"];
46729
+ function determineCoreAppTemplate(templateName) {
46730
+ return coreAppTemplates.includes(templateName);
46731
+ }
46732
+ const blogTemplate = {}, cleanTemplate = {}, coreAppTemplate = {
46733
+ dependencies: {
46734
+ "@sanity/sdk": "^0.0.0-alpha",
46735
+ "@sanity/sdk-react": "^0.0.0-alpha",
46736
+ react: "^19",
46737
+ "react-dom": "^19"
46738
+ },
46739
+ devDependencies: {
46740
+ /*
46741
+ * this will be changed to eslint-config sanity,
46742
+ * eslint.config generation will be a fast follow
46743
+ */
46744
+ "@sanity/eslint-config-studio": "^5.0.1",
46745
+ "@types/react": "^18.0.25",
46746
+ eslint: "^9.9.0",
46747
+ prettier: "^3.0.2",
46748
+ sanity: "^3",
46749
+ typescript: "^5.1.6"
46750
+ },
46751
+ appLocation: "./src/App.tsx",
46752
+ scripts: {
46753
+ // this will eventually run a concurrently process with another in-flight utility
46754
+ dev: "sanity app dev",
46755
+ build: "sanity app build",
46756
+ start: "sanity app start"
46757
+ }
46758
+ }, configTemplate$3 = `
46720
46759
  import {defineConfig, isDev} from 'sanity'
46721
46760
  import {visionTool} from '@sanity/vision'
46722
46761
  import {structureTool} from 'sanity/structure'
@@ -46894,6 +46933,7 @@ export default defineConfig({
46894
46933
  }, templates = {
46895
46934
  blog: blogTemplate,
46896
46935
  clean: cleanTemplate,
46936
+ "core-app": coreAppTemplate,
46897
46937
  "get-started": getStartedTemplate,
46898
46938
  moviedb: movieTemplate,
46899
46939
  shopify: shopifyTemplate$1,
@@ -46914,7 +46954,7 @@ async function updateInitialTemplateMetadata(apiClient, projectId, templateName)
46914
46954
  }
46915
46955
  }
46916
46956
  async function bootstrapLocalTemplate(opts, context) {
46917
- const { apiClient, cliRoot, output } = context, templatesDir = path__default.default.join(cliRoot, "templates"), { outputPath, templateName, useTypeScript, packageName, variables } = opts, sourceDir = path__default.default.join(templatesDir, templateName), sharedDir = path__default.default.join(templatesDir, "shared"), template = templates[templateName];
46957
+ const { apiClient, cliRoot, output } = context, templatesDir = path__default.default.join(cliRoot, "templates"), { outputPath, templateName, useTypeScript, packageName, variables } = opts, sourceDir = path__default.default.join(templatesDir, templateName), sharedDir = path__default.default.join(templatesDir, "shared"), isCoreAppTemplate = determineCoreAppTemplate(templateName), template = templates[templateName];
46918
46958
  if (!template)
46919
46959
  throw new Error(`Template "${templateName}" not defined`);
46920
46960
  loadEnv.debug('Copying files from template "%s" to "%s"', templateName, outputPath);
@@ -46929,19 +46969,20 @@ async function bootstrapLocalTemplate(opts, context) {
46929
46969
  schemaUrl: opts.schemaUrl
46930
46970
  })), spinner.succeed(), spinner = output.spinner("Resolving latest module versions").start();
46931
46971
  const dependencyVersions = await resolveLatestVersions({
46932
- ...studioDependencies.dependencies,
46933
- ...studioDependencies.devDependencies,
46934
- ...template.dependencies || {}
46972
+ ...isCoreAppTemplate ? {} : studioDependencies.dependencies,
46973
+ ...isCoreAppTemplate ? {} : studioDependencies.devDependencies,
46974
+ ...template.dependencies || {},
46975
+ ...template.devDependencies || {}
46935
46976
  });
46936
46977
  spinner.succeed();
46937
46978
  const dependencies = Object.keys({
46938
- ...studioDependencies.dependencies,
46979
+ ...isCoreAppTemplate ? {} : studioDependencies.dependencies,
46939
46980
  ...template.dependencies
46940
46981
  }).reduce(
46941
46982
  (deps, dependency) => (deps[dependency] = dependencyVersions[dependency], deps),
46942
46983
  {}
46943
46984
  ), devDependencies = Object.keys({
46944
- ...studioDependencies.devDependencies,
46985
+ ...isCoreAppTemplate ? {} : studioDependencies.devDependencies,
46945
46986
  ...template.devDependencies
46946
46987
  }).reduce(
46947
46988
  (deps, dependency) => (deps[dependency] = dependencyVersions[dependency], deps),
@@ -46951,27 +46992,30 @@ async function bootstrapLocalTemplate(opts, context) {
46951
46992
  const packageManifest = await createPackageManifest({
46952
46993
  name: packageName,
46953
46994
  dependencies,
46954
- devDependencies
46955
- }), studioConfig = await createStudioConfig({
46995
+ devDependencies,
46996
+ scripts: template.scripts
46997
+ }), studioConfig = createStudioConfig({
46956
46998
  template: template.configTemplate,
46957
46999
  variables
46958
- }), cliConfig = await createCliConfig({
47000
+ }), cliConfig = isCoreAppTemplate ? createCoreAppCliConfig({ appLocation: template.appLocation }) : createCliConfig({
46959
47001
  projectId: variables.projectId,
46960
47002
  dataset: variables.dataset,
46961
47003
  autoUpdates: variables.autoUpdates
46962
47004
  }), codeExt = useTypeScript ? "ts" : "js";
46963
- return await Promise.all([
46964
- writeFileIfNotExists(`sanity.config.${codeExt}`, studioConfig),
46965
- writeFileIfNotExists(`sanity.cli.${codeExt}`, cliConfig),
46966
- writeFileIfNotExists("package.json", packageManifest),
46967
- writeFileIfNotExists(
46968
- "eslint.config.mjs",
46969
- `import studio from '@sanity/eslint-config-studio'
47005
+ return await Promise.all(
47006
+ [
47007
+ isCoreAppTemplate ? Promise.resolve(null) : writeFileIfNotExists(`sanity.config.${codeExt}`, studioConfig),
47008
+ writeFileIfNotExists(`sanity.cli.${codeExt}`, cliConfig),
47009
+ writeFileIfNotExists("package.json", packageManifest),
47010
+ writeFileIfNotExists(
47011
+ "eslint.config.mjs",
47012
+ `import studio from '@sanity/eslint-config-studio'
46970
47013
 
46971
47014
  export default [...studio]
46972
47015
  `
46973
- )
46974
- ]), loadEnv.debug("Updating initial template metadata"), await updateInitialTemplateMetadata(apiClient, variables.projectId, `cli-${templateName}`), spinner.succeed(), template;
47016
+ )
47017
+ ].filter(Boolean)
47018
+ ), loadEnv.debug("Updating initial template metadata"), await updateInitialTemplateMetadata(apiClient, variables.projectId, `cli-${templateName}`), spinner.succeed(), template;
46975
47019
  async function writeFileIfNotExists(fileName, content) {
46976
47020
  const filePath = path__default.default.join(outputPath, fileName);
46977
47021
  try {
@@ -51925,7 +51969,7 @@ async function bootstrapRemoteTemplate(opts, context) {
51925
51969
  }), port = getDefaultPortForFramework(packageFramework?.slug);
51926
51970
  corsAdded.includes(port) === !1 && (loadEnv.debug("Setting CORS origin to http://localhost:%d", port), await setCorsOrigin(`http://localhost:${port}`, variables.projectId, apiClient), corsAdded.push(port)), loadEnv.debug("Applying environment variables to %s", pkg);
51927
51971
  const envName = packageFramework?.slug === "nextjs" ? ".env.local" : ".env";
51928
- await applyEnvVariables(packagePath, { ...variables, readToken }, envName);
51972
+ await applyEnvVariables(packagePath, { ...variables, readToken, writeToken }, envName);
51929
51973
  }
51930
51974
  loadEnv.debug("Setting package name to %s", packageName), await tryApplyPackageName(outputPath, packageName), loadEnv.debug("Initializing git repository"), tryGitInit(outputPath, INITIAL_COMMIT_MESSAGE), loadEnv.debug("Updating initial template metadata"), await updateInitialTemplateMetadata(apiClient, variables.projectId, `external-${name}`), spinner.succeed(), corsAdded.length && output.success(`CORS origins added (${corsAdded.map((p) => `localhost:${p}`).join(", ")})`), readToken && output.success(`API token generated (${READ_TOKEN_LABEL})`), writeToken && output.success(`API token generated (${WRITE_TOKEN_LABEL})`);
51931
51975
  }
@@ -52590,7 +52634,7 @@ ${err.message}`);
52590
52634
  } else unattended || (trace.log({ step: "login" }), await getOrCreateUser());
52591
52635
  let introMessage = "Fetching existing projects";
52592
52636
  cliFlags.quickstart && (introMessage = "Eject your existing project's Sanity configuration"), success(introMessage), print("");
52593
- const flags = await prepareFlags(), { projectId, displayName, isFirstProject, datasetName, schemaUrl } = await getProjectDetails(), sluggedName = lodashExports.deburr(displayName.toLowerCase()).replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
52637
+ const flags = await prepareFlags(), isCoreAppTemplate = cliFlags.template ? determineCoreAppTemplate(cliFlags.template) : !1, { projectId, displayName, isFirstProject, datasetName, schemaUrl } = await getProjectDetails(), sluggedName = lodashExports.deburr(displayName.toLowerCase()).replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
52594
52638
  if (bareOutput) {
52595
52639
  success("Below are your project details"), print(""), print(`Project ID: ${chalk2.cyan(projectId)}`), print(`Dataset: ${chalk2.cyan(datasetName)}`), print(
52596
52640
  `
@@ -52780,11 +52824,15 @@ ${chalk2.green("Success!")} Your Sanity configuration files has been added to th
52780
52824
  }[pkgManager];
52781
52825
  outputPath === process.cwd() ? (print(`
52782
52826
  ${chalk2.green("Success!")} Now, use this command to continue:
52783
- `), print(`${chalk2.cyan(devCommand)} - to run Sanity Studio
52784
- `)) : (print(`
52827
+ `), print(
52828
+ `${chalk2.cyan(devCommand)} - to run ${isCoreAppTemplate ? "your Sanity application" : "Sanity Studio"}
52829
+ `
52830
+ )) : (print(`
52785
52831
  ${chalk2.green("Success!")} Now, use these commands to continue:
52786
- `), print(`First: ${chalk2.cyan(`cd ${outputPath}`)} - to enter project\u2019s directory`), print(`Then: ${chalk2.cyan(devCommand)} - to run Sanity Studio
52787
- `)), print("Other helpful commands"), print("npx sanity docs - to open the documentation in a browser"), print("npx sanity manage - to open the project settings in a browser"), print("npx sanity help - to explore the CLI manual");
52832
+ `), print(`First: ${chalk2.cyan(`cd ${outputPath}`)} - to enter project\u2019s directory`), print(
52833
+ `Then: ${chalk2.cyan(devCommand)} -to run ${isCoreAppTemplate ? "your Sanity application" : "Sanity Studio"}
52834
+ `
52835
+ )), print("Other helpful commands"), print("npx sanity docs - to open the documentation in a browser"), print("npx sanity manage - to open the project settings in a browser"), print("npx sanity help - to explore the CLI manual");
52788
52836
  const sendInvite = isFirstProject && await prompt2.single({
52789
52837
  type: "confirm",
52790
52838
  message: "We have an excellent developer community, would you like us to send you an invitation to join?",
@@ -52811,6 +52859,13 @@ ${chalk2.green("Success!")} Now, use these commands to continue:
52811
52859
  isFirstProject: data.isFirstProject
52812
52860
  }), data;
52813
52861
  }
52862
+ if (isCoreAppTemplate)
52863
+ return {
52864
+ projectId: "",
52865
+ displayName: "",
52866
+ isFirstProject: !1,
52867
+ datasetName: ""
52868
+ };
52814
52869
  loadEnv.debug("Prompting user to select or create a project");
52815
52870
  const project = await getOrCreateProject();
52816
52871
  loadEnv.debug(`Project with name ${project.displayName} selected`), loadEnv.debug("Prompting user to select or create a dataset");