@sanity/cli 3.86.2-experimental.0 → 3.87.1-canary.4
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 +63 -25
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/_chunks-cjs/generateAction.js +96 -118
- package/lib/_chunks-cjs/generateAction.js.map +1 -1
- package/lib/_chunks-cjs/journeyConfig.js +5 -24
- package/lib/_chunks-cjs/journeyConfig.js.map +1 -1
- package/lib/_chunks-cjs/loadEnv.js +3 -3
- package/lib/_chunks-cjs/loadEnv.js.map +1 -1
- package/lib/workers/typegenGenerate.d.ts +36 -104
- package/lib/workers/typegenGenerate.js +111 -24
- package/lib/workers/typegenGenerate.js.map +1 -1
- package/package.json +21 -19
- package/src/actions/init-project/initProject.ts +88 -26
- package/src/actions/typegen/generate.telemetry.ts +3 -5
- package/src/actions/typegen/generateAction.ts +130 -165
- package/src/cli.ts +20 -6
- package/src/commands/projects/listProjectsCommand.ts +0 -0
- package/src/commands/projects/projectsGroup.ts +0 -0
- package/src/util/journeyConfig.ts +2 -3
- package/src/workers/typegenGenerate.ts +193 -55
- package/templates/app-sanity-ui/src/App.tsx +5 -5
- package/lib/_chunks-cjs/workerChannel.js +0 -84
- package/lib/_chunks-cjs/workerChannel.js.map +0 -1
- package/src/util/__tests__/workerChannel.test.ts +0 -222
- package/src/util/workerChannel.ts +0 -312
package/lib/_chunks-cjs/cli.js
CHANGED
@@ -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
|
-
|
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
|
@@ -53663,7 +53662,7 @@ ${chalk2.green("Success!")} Now, use this command to continue:
|
|
53663
53662
|
`
|
53664
53663
|
)) : (print(`
|
53665
53664
|
${chalk2.green("Success!")} Now, use these commands to continue:
|
53666
|
-
`), print(`First: ${chalk2.cyan(`cd ${outputPath}`)} - to enter project
|
53665
|
+
`), print(`First: ${chalk2.cyan(`cd ${outputPath}`)} - to enter project's directory`), print(
|
53667
53666
|
`Then: ${chalk2.cyan(devCommand)} -to run ${isAppTemplate ? "your Sanity application" : "Sanity Studio"}
|
53668
53667
|
`
|
53669
53668
|
)), 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");
|
@@ -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({
|
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
|
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
|
53989
|
-
if (!cliFlags
|
53990
|
-
throw new Error(
|
53991
|
-
|
53992
|
-
|
53993
|
-
|
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;
|
@@ -54051,18 +54076,25 @@ The default dataset configuration has a public dataset named "production".`;
|
|
54051
54076
|
return chosenOrg === "-new-" ? createOrganization().then((org) => org.id) : chosenOrg || void 0;
|
54052
54077
|
}
|
54053
54078
|
async function hasProjectAttachGrant(orgId) {
|
54054
|
-
const requiredGrantGroup = "sanity.organization.projects", requiredGrant = "attach";
|
54055
|
-
|
54056
|
-
(
|
54057
|
-
|
54079
|
+
const requiredGrantGroup = "sanity.organization.projects", requiredGrant = "attach", client2 = apiClient({ requireProject: !1, requireUser: !0 }).clone().config({ apiVersion: "v2021-06-07" });
|
54080
|
+
try {
|
54081
|
+
return ((await client2.request({ uri: `organizations/${orgId}/grants` }))[requiredGrantGroup] || []).some(
|
54082
|
+
(resource) => resource.grants && resource.grants.some((grant) => grant.name === requiredGrant)
|
54083
|
+
);
|
54084
|
+
} catch (err) {
|
54085
|
+
return err.statusCode === 401 ? (loadEnv.debug("No access to organization %s (401)", orgId), !1) : (loadEnv.debug("Error checking grants for organization %s: %s", orgId, err.message), !1);
|
54086
|
+
}
|
54058
54087
|
}
|
54059
54088
|
function getOrganizationsWithAttachGrantInfo(organizations) {
|
54060
54089
|
return pMap(
|
54061
54090
|
organizations,
|
54062
|
-
async (organization) =>
|
54063
|
-
|
54064
|
-
|
54065
|
-
|
54091
|
+
async (organization) => {
|
54092
|
+
try {
|
54093
|
+
return { hasAttachGrant: await hasProjectAttachGrant(organization.id), organization };
|
54094
|
+
} catch (err) {
|
54095
|
+
return loadEnv.debug("Error checking grants for organization %s: %s", organization.id, err.message), { hasAttachGrant: !1, organization };
|
54096
|
+
}
|
54097
|
+
},
|
54066
54098
|
{ concurrency: 3 }
|
54067
54099
|
);
|
54068
54100
|
}
|
@@ -79523,9 +79555,11 @@ async function runCli(cliRoot, { cliVersion }) {
|
|
79523
79555
|
} catch (err) {
|
79524
79556
|
console.error(chalk__default.default.red(err.message)), process.exit(1);
|
79525
79557
|
}
|
79526
|
-
|
79527
|
-
|
79558
|
+
await runUpdateCheck({ pkg, cwd, workDir }).notify(), telemetryDisclosure(), loadEnv.debug(`Reading CLI config from "${workDir}"`);
|
79559
|
+
let cliConfig = await getCliConfig.getCliConfig(workDir, { forked: !0 });
|
79528
79560
|
cliConfig || loadEnv.debug("No CLI config found");
|
79561
|
+
const isApp = !!(cliConfig && "app" in cliConfig);
|
79562
|
+
loadAndSetEnvFromDotEnvFiles({ workDir, cmd: args.groupOrCommand, isApp }), maybeFixMissingWindowsEnvVar(), cliConfig = await getCliConfig.getCliConfig(workDir, { forked: !0 });
|
79529
79563
|
const { logger: telemetry2, flush: flushTelemetry } = createTelemetryStore({
|
79530
79564
|
projectId: cliConfig?.config?.api?.projectId,
|
79531
79565
|
env: process.env
|
@@ -79649,7 +79683,11 @@ function warnOnNonProductionEnvironment() {
|
|
79649
79683
|
)
|
79650
79684
|
);
|
79651
79685
|
}
|
79652
|
-
function loadAndSetEnvFromDotEnvFiles({
|
79686
|
+
function loadAndSetEnvFromDotEnvFiles({
|
79687
|
+
workDir,
|
79688
|
+
cmd,
|
79689
|
+
isApp
|
79690
|
+
}) {
|
79653
79691
|
if (fs$1.existsSync(path__default.default.join(workDir, "sanity.json"))) {
|
79654
79692
|
loadEnv.debug("sanity.json exists, assuming v2 project and loading .env files using old behavior");
|
79655
79693
|
const env = process.env.SANITY_ACTIVE_ENV || process.env.NODE_ENV || "development";
|
@@ -79661,7 +79699,7 @@ function loadAndSetEnvFromDotEnvFiles({ workDir, cmd }) {
|
|
79661
79699
|
let mode2 = process.env.SANITY_ACTIVE_ENV;
|
79662
79700
|
!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
79701
|
`)), loadEnv.debug("Loading environment files using %s mode", mode2);
|
79664
|
-
const studioEnv = loadEnv.loadEnv(mode2, workDir, ["SANITY_STUDIO_"]);
|
79702
|
+
const studioEnv = loadEnv.loadEnv(mode2, workDir, [isApp ? "SANITY_APP_" : "SANITY_STUDIO_"]);
|
79665
79703
|
process.env = { ...process.env, ...studioEnv };
|
79666
79704
|
}
|
79667
79705
|
function maybeFixMissingWindowsEnvVar() {
|