@sanity/cli 3.86.1 → 3.87.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.
@@ -53468,7 +53468,7 @@ ${err.message}`);
53468
53468
  const isAppTemplate = cliFlags.template ? determineAppTemplate(cliFlags.template) : !1;
53469
53469
  let introMessage = "Fetching existing projects";
53470
53470
  cliFlags.quickstart && (introMessage = "Eject your existing project's Sanity configuration"), isAppTemplate || (success(introMessage), print(""));
53471
- const flags = await prepareFlags(), { projectId, displayName, isFirstProject, datasetName, schemaUrl, organizationId } = await getProjectDetails(), sluggedName = lodashExports.deburr(displayName.toLowerCase()).replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
53471
+ 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, "");
53472
53472
  if (bareOutput) {
53473
53473
  success("Below are your project details"), print(""), print(`Project ID: ${chalk2.cyan(projectId)}`), print(`Dataset: ${chalk2.cyan(datasetName)}`), print(
53474
53474
  `
@@ -53478,8 +53478,7 @@ You can find your project on Sanity Manage \u2014 https://www.sanity.io/manage/p
53478
53478
  return;
53479
53479
  }
53480
53480
  let initNext = !1;
53481
- const isNextJs = detectedFramework?.slug === "nextjs";
53482
- isNextJs && (initNext = await prompt2.single({
53481
+ isNextJs && (initNext = unattended || await prompt2.single({
53483
53482
  type: "confirm",
53484
53483
  message: "Would you like to add configuration files for a Sanity project in this Next.js folder?",
53485
53484
  default: !0
@@ -53692,13 +53691,19 @@ ${chalk2.green("Success!")} Now, use these commands to continue:
53692
53691
  }), data;
53693
53692
  }
53694
53693
  if (isAppTemplate) {
53695
- const organizations = await apiClient({ requireUser: !0, requireProject: !1 }).request({ uri: "/organizations" });
53694
+ const organizations = await apiClient({ requireUser: !0, requireProject: !1 }).request({
53695
+ uri: "/organizations",
53696
+ query: {
53697
+ includeMembers: "true",
53698
+ includeImplicitMemberships: "true"
53699
+ }
53700
+ });
53696
53701
  return {
53697
53702
  projectId: "",
53698
53703
  displayName: "",
53699
53704
  datasetName: "",
53700
53705
  isFirstProject: !1,
53701
- organizationId: await getOrganizationId(organizations)
53706
+ organizationId: await getOrganizationIdForAppTemplate(organizations)
53702
53707
  };
53703
53708
  }
53704
53709
  loadEnv.debug("Prompting user to select or create a project");
@@ -53985,13 +53990,16 @@ The default dataset configuration has a public dataset named "production".`;
53985
53990
  throw new Error("Please specify a project name (`--create-project <name>`)");
53986
53991
  if (typeof createProjectName == "string" && createProjectName.trim().length === 0)
53987
53992
  throw new Error("Please specify a project name (`--create-project <name>`)");
53988
- if (unattended && (loadEnv.debug("Unattended mode, validating required options"), ["dataset", "output-path"].forEach((flag) => {
53989
- if (!cliFlags[flag])
53990
- throw new Error(`\`--${flag}\` must be specified in unattended mode`);
53991
- }), !cliFlags.project && !createProjectName))
53992
- throw new Error(
53993
- "`--project <id>` or `--create-project <name>` must be specified in unattended mode"
53994
- );
53993
+ if (unattended) {
53994
+ if (loadEnv.debug("Unattended mode, validating required options"), !cliFlags.dataset)
53995
+ throw new Error("`--dataset` must be specified in unattended mode");
53996
+ if (!isNextJs && !cliFlags["output-path"])
53997
+ throw new Error("`--output-path` must be specified in unattended mode");
53998
+ if (!cliFlags.project && !createProjectName)
53999
+ throw new Error(
54000
+ "`--project <id>` or `--create-project <name>` must be specified in unattended mode"
54001
+ );
54002
+ }
53995
54003
  if (createProjectName) {
53996
54004
  loadEnv.debug("--create-project specified, creating a new project");
53997
54005
  const createdProject = await createProject(apiClient, {
@@ -54025,6 +54033,23 @@ The default dataset configuration has a public dataset named "production".`;
54025
54033
  });
54026
54034
  return spinner.succeed(), organization;
54027
54035
  }
54036
+ async function getOrganizationIdForAppTemplate(organizations) {
54037
+ const organizationChoices = [
54038
+ ...organizations.map((organization) => ({
54039
+ value: organization.id,
54040
+ name: `${organization.name} [${organization.id}]`
54041
+ })),
54042
+ new prompt2.Separator(),
54043
+ { value: "-new-", name: "Create new organization" },
54044
+ new prompt2.Separator()
54045
+ ], defaultOrganizationId = organizations.length === 1 ? organizations[0].id : organizations.find((org) => org.name === user?.name)?.id, chosenOrg = await prompt2.single({
54046
+ message: "Select organization:",
54047
+ type: "list",
54048
+ default: defaultOrganizationId || void 0,
54049
+ choices: organizationChoices
54050
+ });
54051
+ return chosenOrg === "-new-" ? createOrganization().then((org) => org.id) : chosenOrg || void 0;
54052
+ }
54028
54053
  async function getOrganizationId(organizations) {
54029
54054
  if (unattended || flags.organization)
54030
54055
  return flags.organization || void 0;
@@ -79523,9 +79548,11 @@ async function runCli(cliRoot, { cliVersion }) {
79523
79548
  } catch (err) {
79524
79549
  console.error(chalk__default.default.red(err.message)), process.exit(1);
79525
79550
  }
79526
- loadAndSetEnvFromDotEnvFiles({ workDir, cmd: args.groupOrCommand }), maybeFixMissingWindowsEnvVar(), await runUpdateCheck({ pkg, cwd, workDir }).notify(), telemetryDisclosure(), loadEnv.debug(`Reading CLI config from "${workDir}"`);
79527
- const cliConfig = await getCliConfig.getCliConfig(workDir, { forked: !0 });
79551
+ await runUpdateCheck({ pkg, cwd, workDir }).notify(), telemetryDisclosure(), loadEnv.debug(`Reading CLI config from "${workDir}"`);
79552
+ let cliConfig = await getCliConfig.getCliConfig(workDir, { forked: !0 });
79528
79553
  cliConfig || loadEnv.debug("No CLI config found");
79554
+ const isApp = !!(cliConfig && "app" in cliConfig);
79555
+ loadAndSetEnvFromDotEnvFiles({ workDir, cmd: args.groupOrCommand, isApp }), maybeFixMissingWindowsEnvVar(), cliConfig = await getCliConfig.getCliConfig(workDir, { forked: !0 });
79529
79556
  const { logger: telemetry2, flush: flushTelemetry } = createTelemetryStore({
79530
79557
  projectId: cliConfig?.config?.api?.projectId,
79531
79558
  env: process.env
@@ -79649,7 +79676,11 @@ function warnOnNonProductionEnvironment() {
79649
79676
  )
79650
79677
  );
79651
79678
  }
79652
- function loadAndSetEnvFromDotEnvFiles({ workDir, cmd }) {
79679
+ function loadAndSetEnvFromDotEnvFiles({
79680
+ workDir,
79681
+ cmd,
79682
+ isApp
79683
+ }) {
79653
79684
  if (fs$1.existsSync(path__default.default.join(workDir, "sanity.json"))) {
79654
79685
  loadEnv.debug("sanity.json exists, assuming v2 project and loading .env files using old behavior");
79655
79686
  const env = process.env.SANITY_ACTIVE_ENV || process.env.NODE_ENV || "development";
@@ -79661,7 +79692,7 @@ function loadAndSetEnvFromDotEnvFiles({ workDir, cmd }) {
79661
79692
  let mode2 = process.env.SANITY_ACTIVE_ENV;
79662
79693
  !mode2 && (isProdCmd || process.env.NODE_ENV === "production") ? mode2 = "production" : mode2 || (mode2 = "development"), mode2 === "production" && !isProdCmd && console.warn(chalk__default.default.yellow(`[WARN] Running in ${sanityEnv} environment mode
79663
79694
  `)), loadEnv.debug("Loading environment files using %s mode", mode2);
79664
- const studioEnv = loadEnv.loadEnv(mode2, workDir, ["SANITY_STUDIO_"]);
79695
+ const studioEnv = loadEnv.loadEnv(mode2, workDir, [isApp ? "SANITY_APP_" : "SANITY_STUDIO_"]);
79665
79696
  process.env = { ...process.env, ...studioEnv };
79666
79697
  }
79667
79698
  function maybeFixMissingWindowsEnvVar() {