@sanity/cli 3.94.1-next.0.6739e10a32 → 3.94.1-next.2.feb8c151eb

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.
@@ -47976,6 +47976,10 @@ export default [...studio]
47976
47976
  ), loadEnv.debug("Updating initial template metadata"), await updateInitialTemplateMetadata(apiClient, variables.projectId, `cli-${templateName}`), spinner.succeed(), template;
47977
47977
  async function writeFileIfNotExists(fileName, content) {
47978
47978
  const filePath = path__default.default.join(outputPath, fileName);
47979
+ if (opts.overwriteFiles) {
47980
+ await fs__default.default.writeFile(filePath, content);
47981
+ return;
47982
+ }
47979
47983
  try {
47980
47984
  await fs__default.default.writeFile(filePath, content, { flag: "wx" });
47981
47985
  } catch (err) {
@@ -53590,6 +53594,25 @@ ${err.message}`);
53590
53594
  const isAppTemplate = cliFlags.template ? determineAppTemplate(cliFlags.template) : !1;
53591
53595
  let introMessage = "Fetching existing projects";
53592
53596
  cliFlags.quickstart && (introMessage = "Eject your existing project's Sanity configuration"), isAppTemplate || (success(introMessage), print(""));
53597
+ function shouldPromptFor(setting) {
53598
+ return !unattended && cliFlags[setting] === void 0;
53599
+ }
53600
+ function flagOrDefault(flag, defaultValue) {
53601
+ return typeof cliFlags[flag] == "boolean" ? cliFlags[flag] : defaultValue;
53602
+ }
53603
+ async function resolvePackageManager(targetDir) {
53604
+ if (packageManager && ALLOWED_PACKAGE_MANAGERS.includes(packageManager))
53605
+ return packageManager;
53606
+ const chosen = (await getPackageManagerChoice(targetDir, {
53607
+ prompt: prompt2,
53608
+ interactive: unattended ? !1 : isInteractive$1
53609
+ })).chosen;
53610
+ return packageManager && (output.warn(
53611
+ chalk2.yellow(
53612
+ `Given package manager "${packageManager}" is not supported. Supported package managers are ${allowedPackageManagersString}.`
53613
+ )
53614
+ ), output.print(`Using ${chosen} as package manager`)), chosen;
53615
+ }
53593
53616
  const isNextJs = detectedFramework?.slug === "nextjs", flags = await prepareFlags(), { projectId, displayName, isFirstProject, datasetName, schemaUrl, organizationId } = await getProjectDetails(), sluggedName = lodashExports.deburr(displayName.toLowerCase()).replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
53594
53617
  if (bareOutput) {
53595
53618
  success("Below are your project details"), print(""), print(`Project ID: ${chalk2.cyan(projectId)}`), print(`Dataset: ${chalk2.cyan(datasetName)}`), print(
@@ -53599,12 +53622,12 @@ You can find your project on Sanity Manage \u2014 https://www.sanity.io/manage/p
53599
53622
  );
53600
53623
  return;
53601
53624
  }
53602
- let initNext = !1;
53603
- isNextJs && (initNext = unattended || await prompt2.single({
53625
+ let initNext = flagOrDefault("nextjs-add-config-files", !1);
53626
+ isNextJs && (shouldPromptFor("nextjs-add-config-files") && (initNext = await prompt2.single({
53604
53627
  type: "confirm",
53605
53628
  message: "Would you like to add configuration files for a Sanity project in this Next.js folder?",
53606
53629
  default: !0
53607
- }), trace.log({
53630
+ })), trace.log({
53608
53631
  step: "useDetectedFramework",
53609
53632
  selectedOption: initNext ? "yes" : "no",
53610
53633
  detectedFramework: detectedFramework?.name
@@ -53619,10 +53642,12 @@ You can find your project on Sanity Manage \u2014 https://www.sanity.io/manage/p
53619
53642
  semver__default.default.coerce(detectedFramework?.detectedVersion)?.major === 15 && isUsingReact19 && (warn("\u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E"), warn("\u2502 \u2502"), warn("\u2502 It looks like you are using Next.js 15 and React 19 \u2502"), warn("\u2502 Please read our compatibility guide. \u2502"), warn("\u2502 https://www.sanity.io/help/react-19 \u2502"), warn("\u2502 \u2502"), warn("\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F"));
53620
53643
  }
53621
53644
  }
53645
+ let useTypeScript = flagOrDefault("typescript", !0);
53622
53646
  if (initNext) {
53623
- const useTypeScript2 = unattended ? !0 : await promptForTypeScript(prompt2);
53624
- trace.log({ step: "useTypeScript", selectedOption: useTypeScript2 ? "yes" : "no" });
53625
- const fileExtension = useTypeScript2 ? "ts" : "js", embeddedStudio = unattended ? !0 : await promptForEmbeddedStudio(prompt2);
53647
+ shouldPromptFor("typescript") && (useTypeScript = await promptForTypeScript(prompt2)), trace.log({ step: "useTypeScript", selectedOption: useTypeScript ? "yes" : "no" });
53648
+ const fileExtension = useTypeScript ? "ts" : "js";
53649
+ let embeddedStudio = flagOrDefault("nextjs-embed-studio", !0);
53650
+ shouldPromptFor("nextjs-embed-studio") && (embeddedStudio = await promptForEmbeddedStudio(prompt2));
53626
53651
  let hasSrcFolder = !1;
53627
53652
  if (embeddedStudio) {
53628
53653
  const appDir = "app";
@@ -53662,8 +53687,18 @@ You can find your project on Sanity Manage \u2014 https://www.sanity.io/manage/p
53662
53687
  ) : (await fs__default.default.mkdir(path__default.default.join(workDir, srcFolderPrefix ? "src" : "", "sanity", filePath), {
53663
53688
  recursive: !0
53664
53689
  }), typeof content == "object" && await writeSourceFiles(content, filePath, srcFolderPrefix));
53665
- }, templateToUse = unattended ? "clean" : await promptForNextTemplate(prompt2);
53666
- if (await writeSourceFiles(sanityFolder(useTypeScript2, templateToUse), void 0, hasSrcFolder), (unattended || await promptForAppendEnv(prompt2, envFilename)) && await createOrAppendEnvVars(envFilename, detectedFramework, { log: !0 }), embeddedStudio) {
53690
+ };
53691
+ let templateToUse = flags.template ?? "clean";
53692
+ if (shouldPromptFor("template") && (templateToUse = await promptForNextTemplate(prompt2)), ["clean", "blog"].includes(templateToUse))
53693
+ await writeSourceFiles(
53694
+ sanityFolder(useTypeScript, templateToUse),
53695
+ void 0,
53696
+ hasSrcFolder
53697
+ );
53698
+ else
53699
+ throw new Error(`Invalid template for nextjs: '${templateToUse}'. Pick 'clean' or 'blog'.`);
53700
+ let appendEnv = flagOrDefault("nextjs-append-env", !0);
53701
+ if (shouldPromptFor("nextjs-append-env") && (appendEnv = await promptForAppendEnv(prompt2, envFilename)), appendEnv && await createOrAppendEnvVars(envFilename, detectedFramework, { log: !0, targetDir: workDir }), embeddedStudio) {
53667
53702
  const nextjsLocalDevOrigin = "http://localhost:3000";
53668
53703
  (await apiClient({ api: { projectId } }).request({
53669
53704
  method: "GET",
@@ -53683,7 +53718,7 @@ You can find your project on Sanity Manage \u2014 https://www.sanity.io/manage/p
53683
53718
  print(`Failed to add ${nextjsLocalDevOrigin} to CORS origins`, error2);
53684
53719
  });
53685
53720
  }
53686
- const { chosen } = await getPackageManagerChoice(workDir, { interactive: !1 });
53721
+ const chosen = await resolvePackageManager(workDir);
53687
53722
  trace.log({ step: "selectPackageManager", selectedOption: chosen });
53688
53723
  const packages = ["@sanity/vision@3", "sanity@3", "@sanity/image-url@1", "styled-components@6"];
53689
53724
  templateToUse === "blog" && packages.push("@sanity/icons"), await installNewPackages(
@@ -53713,14 +53748,17 @@ ${chalk2.green("Success!")} Your Sanity configuration files has been added to th
53713
53748
  return path2.split(separator2).filter(Boolean).length;
53714
53749
  }
53715
53750
  async function writeOrOverwrite(filePath, content) {
53716
- if (fs$1.existsSync(filePath) && !await prompt2.single({
53717
- type: "confirm",
53718
- message: `File ${chalk2.yellow(
53719
- filePath.replace(workDir, "")
53720
- )} already exists. Do you want to overwrite it?`,
53721
- default: !1
53722
- }))
53723
- return;
53751
+ if (fs$1.existsSync(filePath)) {
53752
+ let overwrite = flagOrDefault("overwrite-files", !1);
53753
+ if (shouldPromptFor("overwrite-files") && (overwrite = await prompt2.single({
53754
+ type: "confirm",
53755
+ message: `File ${chalk2.yellow(
53756
+ filePath.replace(workDir, "")
53757
+ )} already exists. Do you want to overwrite it?`,
53758
+ default: !1
53759
+ })), !overwrite)
53760
+ return;
53761
+ }
53724
53762
  const folderPath = path__default.default.dirname(filePath);
53725
53763
  await fs__default.default.mkdir(folderPath, { recursive: !0 }).catch(() => loadEnv.debug("Error creating folder %s", folderPath)), await fs__default.default.writeFile(filePath, content, {
53726
53764
  encoding: "utf8"
@@ -53735,11 +53773,7 @@ ${chalk2.green("Success!")} Your Sanity configuration files has been added to th
53735
53773
  const template = templates[templateName];
53736
53774
  if (!remoteTemplateInfo && !template)
53737
53775
  throw new Error(`Template "${templateName}" not found`);
53738
- let useTypeScript = !0;
53739
- if (!remoteTemplateInfo && template) {
53740
- const typescriptOnly = template.typescriptOnly === !0;
53741
- !typescriptOnly && typeof cliFlags.typescript == "boolean" ? useTypeScript = cliFlags.typescript : !typescriptOnly && !unattended && (useTypeScript = await promptForTypeScript(prompt2), trace.log({ step: "useTypeScript", selectedOption: useTypeScript ? "yes" : "no" }));
53742
- }
53776
+ !remoteTemplateInfo && template && (template.typescriptOnly === !0 ? useTypeScript = !0 : shouldPromptFor("typescript") && (useTypeScript = await promptForTypeScript(prompt2), trace.log({ step: "useTypeScript", selectedOption: useTypeScript ? "yes" : "no" })));
53743
53777
  let autoUpdates = !0;
53744
53778
  typeof cliFlags["auto-updates"] == "boolean" && (autoUpdates = cliFlags["auto-updates"]);
53745
53779
  const shouldImport = !unattended && template?.datasetUrl && await promptForDatasetImport(template.importPrompt);
@@ -53750,15 +53784,8 @@ ${chalk2.green("Success!")} Your Sanity configuration files has been added to th
53750
53784
  ]);
53751
53785
  if (bootstrapPromise.status === "rejected" && bootstrapPromise.reason instanceof Error)
53752
53786
  throw bootstrapPromise.reason;
53753
- let pkgManager;
53754
- if (packageManager && ALLOWED_PACKAGE_MANAGERS.includes(packageManager) ? pkgManager = packageManager : (pkgManager = (await getPackageManagerChoice(outputPath, {
53755
- prompt: prompt2,
53756
- interactive: unattended ? !1 : isInteractive$1
53757
- })).chosen, packageManager && (output.warn(
53758
- chalk2.yellow(
53759
- `Given package manager "${packageManager}" is not supported. Supported package managers are ${allowedPackageManagersString}.`
53760
- )
53761
- ), output.print(`Using ${pkgManager} as package manager`))), trace.log({ step: "selectPackageManager", selectedOption: pkgManager }), await installDeclaredPackages(outputPath, pkgManager, context), useGit && tryGitInit(outputPath, typeof commitMessage == "string" ? commitMessage : void 0), shouldImport) {
53787
+ const pkgManager = await resolvePackageManager(outputPath);
53788
+ if (trace.log({ step: "selectPackageManager", selectedOption: pkgManager }), await installDeclaredPackages(outputPath, pkgManager, context), useGit && tryGitInit(outputPath, typeof commitMessage == "string" ? commitMessage : void 0), shouldImport) {
53762
53789
  const importCommand = getImportCommand(outputPath);
53763
53790
  await doDatasetImport({
53764
53791
  projectId,
@@ -54060,7 +54087,8 @@ The default dataset configuration has a public dataset named "production".`;
54060
54087
  templateName,
54061
54088
  schemaUrl,
54062
54089
  useTypeScript,
54063
- variables: bootstrapVariables
54090
+ variables: bootstrapVariables,
54091
+ overwriteFiles: flagOrDefault("overwrite-files", !1)
54064
54092
  },
54065
54093
  context
54066
54094
  );
@@ -54227,7 +54255,7 @@ The default dataset configuration has a public dataset named "production".`;
54227
54255
  Detected framework ${chalk2.blue(framework?.name)}, using prefix '${framework.envPrefix}'`
54228
54256
  ), await writeEnvVarsToFile(filename, envVars, {
54229
54257
  framework,
54230
- outputPath,
54258
+ outputPath: options2?.targetDir || outputPath,
54231
54259
  log: options2?.log
54232
54260
  });
54233
54261
  } catch (err) {
@@ -54368,8 +54396,16 @@ Options
54368
54396
  --coupon <name> Optionally select a coupon for a new project (cannot be used with --project-plan)
54369
54397
  --no-typescript Do not use TypeScript for template files
54370
54398
  --package-manager <name> Specify which package manager to use [allowed: ${allowedPackageManagersString}]
54371
- --no-auto-updates Disable auto updates of studio versions
54399
+ --auto-updates Enable/disable auto updates of studio versions (default: true)
54400
+ --overwrite-files Overwrite existing files (default: false)
54401
+
54402
+ Some flags are used when initializing a project in a specific framework.
54372
54403
 
54404
+ Next.js
54405
+ --nextjs-add-config-files Add config files to Next.js project (default: true)
54406
+ --nextjs-embed-studio Embed the Studio in Next.js application (default: true)
54407
+ --nextjs-append-env Append project ID and dataset to .env file (default: true)
54408
+
54373
54409
  Examples
54374
54410
  # Initialize a new project, prompt for required information along the way
54375
54411
  sanity init