@sanity/cli 3.75.0 → 3.75.1-canary.110
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.
- package/lib/_chunks-cjs/cli.js +35 -21
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/_chunks-cjs/loadEnv.js +8 -8
- package/lib/_chunks-cjs/loadEnv.js.map +1 -1
- package/lib/index.d.mts +3 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +8 -8
- package/lib/index.esm.js.map +1 -1
- package/lib/index.mjs +8 -8
- package/lib/index.mjs.map +1 -1
- package/package.json +8 -8
- package/src/actions/init-project/bootstrapLocalTemplate.ts +4 -1
- package/src/actions/init-project/createCoreAppCliConfig.ts +2 -1
- package/src/actions/init-project/createStudioConfig.ts +1 -0
- package/src/actions/init-project/initProject.ts +29 -16
- package/src/cli.ts +14 -4
- package/src/types.ts +3 -0
- package/src/util/resolveRootDir.ts +9 -8
- package/templates/core-app/src/App.tsx +8 -7
- package/templates/core-app/src/ExampleComponent.tsx +11 -0
package/lib/_chunks-cjs/cli.js
CHANGED
@@ -46584,7 +46584,8 @@ import {defineCliConfig} from 'sanity/cli'
|
|
46584
46584
|
|
46585
46585
|
export default defineCliConfig({
|
46586
46586
|
__experimental_coreAppConfiguration: {
|
46587
|
-
|
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({
|
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
|
@@ -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(),
|
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
|
-
|
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
|
53188
|
+
let orgId = flags.organization;
|
53180
53189
|
if (unattended)
|
53181
|
-
return
|
53182
|
-
if (organizations.length > 0 && !
|
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) {
|
@@ -53199,13 +53208,13 @@ The default dataset configuration has a public dataset named "production".`;
|
|
53199
53208
|
type: "list",
|
53200
53209
|
choices: organizationChoices
|
53201
53210
|
});
|
53202
|
-
chosenOrg && chosenOrg !== "none" && (
|
53203
|
-
} else
|
53204
|
-
return
|
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(
|
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/${
|
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({
|
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() {
|