@sanity/cli 3.75.0 → 3.75.1-canary.151

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.
@@ -46584,7 +46584,8 @@ import {defineCliConfig} from 'sanity/cli'
46584
46584
 
46585
46585
  export default defineCliConfig({
46586
46586
  __experimental_coreAppConfiguration: {
46587
- appLocation: '%appLocation%'
46587
+ organizationId: '%organizationId%',
46588
+ appLocation: '%appLocation%',
46588
46589
  },
46589
46590
  })
46590
46591
  `;
@@ -47008,7 +47009,10 @@ async function bootstrapLocalTemplate(opts, context) {
47008
47009
  }), studioConfig = createStudioConfig({
47009
47010
  template: template.configTemplate,
47010
47011
  variables
47011
- }), cliConfig = isCoreAppTemplate ? createCoreAppCliConfig({ appLocation: template.appLocation }) : createCliConfig({
47012
+ }), cliConfig = isCoreAppTemplate ? createCoreAppCliConfig({
47013
+ appLocation: template.appLocation,
47014
+ organizationId: variables.organizationId
47015
+ }) : createCliConfig({
47012
47016
  projectId: variables.projectId,
47013
47017
  dataset: variables.dataset,
47014
47018
  autoUpdates: variables.autoUpdates
@@ -47048,7 +47052,7 @@ const portMap = {
47048
47052
  blitzjs: 3e3,
47049
47053
  gatsby: 8e3,
47050
47054
  remix: 3e3,
47051
- astro: 3e3,
47055
+ astro: 4321,
47052
47056
  hexo: 4e3,
47053
47057
  eleventy: 8080,
47054
47058
  docusaurus: 3e3,
@@ -52642,9 +52646,10 @@ ${err.message}`);
52642
52646
  const user = await getUserData(apiClient);
52643
52647
  success("You are logged in as %s using %s", user.email, getProviderName(user.provider));
52644
52648
  } else unattended || (trace.log({ step: "login" }), await getOrCreateUser());
52649
+ const isCoreAppTemplate = cliFlags.template ? determineCoreAppTemplate(cliFlags.template) : !1;
52645
52650
  let introMessage = "Fetching existing projects";
52646
- cliFlags.quickstart && (introMessage = "Eject your existing project's Sanity configuration"), success(introMessage), print("");
52647
- 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, "");
52651
+ cliFlags.quickstart && (introMessage = "Eject your existing project's Sanity configuration"), isCoreAppTemplate || (success(introMessage), print(""));
52652
+ 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, "");
52648
52653
  if (bareOutput) {
52649
52654
  success("Below are your project details"), print(""), print(`Project ID: ${chalk2.cyan(projectId)}`), print(`Dataset: ${chalk2.cyan(datasetName)}`), print(
52650
52655
  `
@@ -52867,13 +52872,16 @@ ${chalk2.green("Success!")} Now, use these commands to continue:
52867
52872
  isFirstProject: data.isFirstProject
52868
52873
  }), data;
52869
52874
  }
52870
- if (isCoreAppTemplate)
52875
+ if (isCoreAppTemplate) {
52876
+ const organizations = await apiClient({ requireUser: !0, requireProject: !1 }).request({ uri: "/organizations" });
52871
52877
  return {
52872
52878
  projectId: "",
52873
52879
  displayName: "",
52880
+ datasetName: "",
52874
52881
  isFirstProject: !1,
52875
- datasetName: ""
52882
+ organizationId: await getOrganizationId(organizations)
52876
52883
  };
52884
+ }
52877
52885
  loadEnv.debug("Prompting user to select or create a project");
52878
52886
  const project = await getOrCreateProject();
52879
52887
  loadEnv.debug(`Project with name ${project.displayName} selected`), loadEnv.debug("Prompting user to select or create a dataset");
@@ -53090,7 +53098,8 @@ The default dataset configuration has a public dataset named "production".`;
53090
53098
  autoUpdates,
53091
53099
  dataset: datasetName,
53092
53100
  projectId,
53093
- projectName: displayName || answers.projectName
53101
+ projectName: displayName || answers.projectName,
53102
+ organizationId
53094
53103
  };
53095
53104
  return remoteTemplateInfo ? bootstrapRemoteTemplate(
53096
53105
  {
@@ -53176,10 +53185,10 @@ The default dataset configuration has a public dataset named "production".`;
53176
53185
  return cliFlags;
53177
53186
  }
53178
53187
  async function getOrganizationId(organizations) {
53179
- let organizationId = flags.organization;
53188
+ let orgId = flags.organization;
53180
53189
  if (unattended)
53181
- return organizationId || void 0;
53182
- if (organizations.length > 0 && !organizationId) {
53190
+ return orgId || void 0;
53191
+ if (organizations.length > 0 && !orgId) {
53183
53192
  loadEnv.debug(`User has ${organizations.length} organization(s), checking attach access`);
53184
53193
  const withGrant = await getOrganizationsWithAttachGrant(organizations);
53185
53194
  if (withGrant.length === 0) {
@@ -53195,17 +53204,17 @@ The default dataset configuration has a public dataset named "production".`;
53195
53204
  name: `${organization.name} [${organization.id}]`
53196
53205
  }))
53197
53206
  ], chosenOrg = await prompt2.single({
53198
- message: "Select organization to attach project to",
53207
+ message: `Select organization to attach ${isCoreAppTemplate ? "application" : "project"} to`,
53199
53208
  type: "list",
53200
53209
  choices: organizationChoices
53201
53210
  });
53202
- chosenOrg && chosenOrg !== "none" && (organizationId = chosenOrg);
53203
- } else organizationId ? loadEnv.debug("User has defined organization flag explicitly (%s)", organizationId) : organizations.length === 0 && loadEnv.debug("User has no organizations, skipping selection prompt");
53204
- return organizationId || void 0;
53211
+ chosenOrg && chosenOrg !== "none" && (orgId = chosenOrg);
53212
+ } else orgId ? loadEnv.debug("User has defined organization flag explicitly (%s)", orgId) : organizations.length === 0 && loadEnv.debug("User has no organizations, skipping selection prompt");
53213
+ return orgId || void 0;
53205
53214
  }
53206
- async function hasProjectAttachGrant(organizationId) {
53215
+ async function hasProjectAttachGrant(orgId) {
53207
53216
  const requiredGrantGroup = "sanity.organization.projects", requiredGrant = "attach";
53208
- return ((await apiClient({ requireProject: !1, requireUser: !0 }).clone().config({ apiVersion: "v2021-06-07" }).request({ uri: `organizations/${organizationId}/grants` }))[requiredGrantGroup] || []).some(
53217
+ return ((await apiClient({ requireProject: !1, requireUser: !0 }).clone().config({ apiVersion: "v2021-06-07" }).request({ uri: `organizations/${orgId}/grants` }))[requiredGrantGroup] || []).some(
53209
53218
  (resource) => resource.grants && resource.grants.some((grant) => grant.name === requiredGrant)
53210
53219
  );
53211
53220
  }
@@ -78648,14 +78657,14 @@ function installProcessExitHack(finalTask) {
78648
78657
  }
78649
78658
  async function runCli(cliRoot, { cliVersion }) {
78650
78659
  installUnhandledRejectionsHandler();
78651
- const pkg = { name: "@sanity/cli", version: cliVersion }, args = parseArguments(), isInit = args.groupOrCommand === "init" && args.argsWithoutOptions[0] !== "plugin", cwd = getCurrentWorkingDirectory();
78660
+ const pkg = { name: "@sanity/cli", version: cliVersion }, args = parseArguments(), isInit = args.groupOrCommand === "init" && args.argsWithoutOptions[0] !== "plugin", isCoreApp = args.groupOrCommand === "app", cwd = getCurrentWorkingDirectory();
78652
78661
  let workDir;
78653
78662
  try {
78654
- workDir = isInit ? process.cwd() : loadEnv.resolveRootDir(cwd);
78663
+ workDir = isInit ? process.cwd() : loadEnv.resolveRootDir(cwd, isCoreApp);
78655
78664
  } catch (err) {
78656
78665
  console.error(chalk__default.default.red(err.message)), process.exit(1);
78657
78666
  }
78658
- loadAndSetEnvFromDotEnvFiles({ workDir, cmd: args.groupOrCommand }), maybeFixMissingWindowsEnvVar(), await runUpdateCheck({ pkg, cwd, workDir }).notify(), telemetryDisclosure(), loadEnv.debug(`Reading CLI config from "${workDir}"`);
78667
+ loadAndSetEnvFromDotEnvFiles({ workDir, cmd: args.groupOrCommand, isCoreApp }), maybeFixMissingWindowsEnvVar(), await runUpdateCheck({ pkg, cwd, workDir }).notify(), telemetryDisclosure(), loadEnv.debug(`Reading CLI config from "${workDir}"`);
78659
78668
  const cliConfig = await getCliConfig.getCliConfig(workDir, { forked: !0 });
78660
78669
  cliConfig || loadEnv.debug("No CLI config found");
78661
78670
  const { logger: telemetry2, flush: flushTelemetry } = createTelemetryStore({
@@ -78681,7 +78690,8 @@ async function runCli(cliRoot, { cliVersion }) {
78681
78690
  workDir,
78682
78691
  corePath: await getCoreModulePath(workDir, cliConfig),
78683
78692
  cliConfig,
78684
- telemetry: telemetry2
78693
+ telemetry: telemetry2,
78694
+ isCoreApp
78685
78695
  };
78686
78696
  warnOnNonProductionEnvironment(), warnOnInferredProjectDir(isInit, cwd, workDir);
78687
78697
  const core2 = args.coreOptions, commands = await mergeCommands(baseCommands, options2.corePath, { cliVersion });
@@ -78781,7 +78791,11 @@ function warnOnNonProductionEnvironment() {
78781
78791
  )
78782
78792
  );
78783
78793
  }
78784
- function loadAndSetEnvFromDotEnvFiles({ workDir, cmd }) {
78794
+ function loadAndSetEnvFromDotEnvFiles({
78795
+ workDir,
78796
+ cmd,
78797
+ isCoreApp
78798
+ }) {
78785
78799
  if (fs$1.existsSync(path__default.default.join(workDir, "sanity.json"))) {
78786
78800
  loadEnv.debug("sanity.json exists, assuming v2 project and loading .env files using old behavior");
78787
78801
  const env = process.env.SANITY_ACTIVE_ENV || process.env.NODE_ENV || "development";
@@ -78793,7 +78807,7 @@ function loadAndSetEnvFromDotEnvFiles({ workDir, cmd }) {
78793
78807
  let mode2 = process.env.SANITY_ACTIVE_ENV;
78794
78808
  !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
78795
78809
  `)), loadEnv.debug("Loading environment files using %s mode", mode2);
78796
- const studioEnv = loadEnv.loadEnv(mode2, workDir, ["SANITY_STUDIO_"]);
78810
+ const studioEnv = loadEnv.loadEnv(mode2, workDir, isCoreApp ? ["VITE_"] : ["SANITY_STUDIO_"]);
78797
78811
  process.env = { ...process.env, ...studioEnv };
78798
78812
  }
78799
78813
  function maybeFixMissingWindowsEnvVar() {