@sanity/cli 3.85.2-media-library.14 → 3.86.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.
@@ -18,7 +18,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
18
18
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
19
19
  mod
20
20
  ));
21
- var fs$1 = require("node:fs"), os = require("node:os"), path$3 = require("node:path"), chalk = require("chalk"), loadEnv = require("./loadEnv.js"), require$$0$5 = require("path"), require$$1$2 = require("module"), require$$0$4 = require("fs"), telemetry = require("@sanity/telemetry"), childProcess = require("node:child_process"), fs = require("node:fs/promises"), util$4 = require("node:util"), require$$0$6 = require("os"), require$$5$1 = require("url"), require$$1$3 = require("get-it"), require$$2$1 = require("get-it/middleware"), require$$0$7 = require("constants"), require$$0$8 = require("stream"), require$$0$9 = require("util"), require$$0$a = require("assert"), require$$0$b = require("events"), require$$6$1 = require("http"), semver = require("semver"), pkgDir = require("pkg-dir"), client$1 = require("@sanity/client"), require$$3$1 = require("crypto"), require$$1$4 = require("child_process"), require$$0$c = require("fs/promises"), require$$0$d = require("buffer"), getCliConfig = require("./getCliConfig.js"), journeyConfig = require("./journeyConfig.js"), Stream = require("node:stream"), promises$1 = require("node:stream/promises"), templateValidator = require("@sanity/template-validator"), require$$2$2 = require("string_decoder"), require$$0$e = require("zlib"), require$$7$1 = require("process"), http = require("node:http"), traverse = require("@babel/traverse"), node_url = require("node:url"), node_events = require("node:events"), node_string_decoder = require("node:string_decoder"), process$2 = require("node:process"), require$$2$3 = require("readline"), require$$0$f = require("tty");
21
+ var fs$1 = require("node:fs"), os = require("node:os"), path$3 = require("node:path"), chalk = require("chalk"), loadEnv = require("./loadEnv.js"), require$$0$5 = require("path"), require$$1$2 = require("module"), require$$0$4 = require("fs"), telemetry = require("@sanity/telemetry"), process$2 = require("node:process"), childProcess = require("node:child_process"), fs = require("node:fs/promises"), util$4 = require("node:util"), require$$0$6 = require("os"), require$$5$1 = require("url"), require$$1$3 = require("get-it"), require$$2$1 = require("get-it/middleware"), require$$0$7 = require("constants"), require$$0$8 = require("stream"), require$$0$9 = require("util"), require$$0$a = require("assert"), require$$0$b = require("events"), require$$6$1 = require("http"), semver = require("semver"), pkgDir = require("pkg-dir"), client$1 = require("@sanity/client"), require$$3$1 = require("crypto"), require$$1$4 = require("child_process"), require$$0$c = require("fs/promises"), require$$0$d = require("buffer"), getCliConfig = require("./getCliConfig.js"), journeyConfig = require("./journeyConfig.js"), Stream = require("node:stream"), promises$1 = require("node:stream/promises"), templateValidator = require("@sanity/template-validator"), require$$2$2 = require("string_decoder"), require$$0$e = require("zlib"), require$$7$1 = require("process"), http = require("node:http"), traverse = require("@babel/traverse"), node_url = require("node:url"), node_events = require("node:events"), node_string_decoder = require("node:string_decoder"), require$$2$3 = require("readline"), require$$0$f = require("tty");
22
22
  function _interopDefaultCompat(e) {
23
23
  return e && typeof e == "object" && "default" in e ? e : { default: e };
24
24
  }
@@ -52,7 +52,7 @@ function _mergeNamespaces(n, m) {
52
52
  });
53
53
  }), Object.freeze(n);
54
54
  }
55
- var fs__namespace = /* @__PURE__ */ _interopNamespaceCompat(fs$1), os__default = /* @__PURE__ */ _interopDefaultCompat(os), path__default = /* @__PURE__ */ _interopDefaultCompat(path$3), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk), require$$0__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$0$5), require$$1__default = /* @__PURE__ */ _interopDefaultCompat(require$$1$2), require$$0__default = /* @__PURE__ */ _interopDefaultCompat(require$$0$4), childProcess__default = /* @__PURE__ */ _interopDefaultCompat(childProcess), fs__default = /* @__PURE__ */ _interopDefaultCompat(fs), util__default = /* @__PURE__ */ _interopDefaultCompat(util$4), require$$0__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$0$6), require$$5__default = /* @__PURE__ */ _interopDefaultCompat(require$$5$1), require$$1__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$1$3), require$$2__default = /* @__PURE__ */ _interopDefaultCompat(require$$2$1), require$$0__default$3 = /* @__PURE__ */ _interopDefaultCompat(require$$0$7), require$$0__default$4 = /* @__PURE__ */ _interopDefaultCompat(require$$0$8), require$$0__default$5 = /* @__PURE__ */ _interopDefaultCompat(require$$0$9), require$$0__default$6 = /* @__PURE__ */ _interopDefaultCompat(require$$0$a), require$$0__default$7 = /* @__PURE__ */ _interopDefaultCompat(require$$0$b), require$$6__default = /* @__PURE__ */ _interopDefaultCompat(require$$6$1), semver__default = /* @__PURE__ */ _interopDefaultCompat(semver), pkgDir__default = /* @__PURE__ */ _interopDefaultCompat(pkgDir), require$$3__default = /* @__PURE__ */ _interopDefaultCompat(require$$3$1), require$$1__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$1$4), require$$0__default$8 = /* @__PURE__ */ _interopDefaultCompat(require$$0$c), require$$0__default$9 = /* @__PURE__ */ _interopDefaultCompat(require$$0$d), Stream__default = /* @__PURE__ */ _interopDefaultCompat(Stream), require$$2__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$2$2), require$$0__default$a = /* @__PURE__ */ _interopDefaultCompat(require$$0$e), require$$7__default = /* @__PURE__ */ _interopDefaultCompat(require$$7$1), http__default = /* @__PURE__ */ _interopDefaultCompat(http), traverse__default = /* @__PURE__ */ _interopDefaultCompat(traverse), process__default = /* @__PURE__ */ _interopDefaultCompat(process$2), require$$2__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$2$3), require$$0__default$b = /* @__PURE__ */ _interopDefaultCompat(require$$0$f), resolveFrom$1 = { exports: {} }, hasRequiredResolveFrom;
55
+ var fs__namespace = /* @__PURE__ */ _interopNamespaceCompat(fs$1), os__default = /* @__PURE__ */ _interopDefaultCompat(os), path__default = /* @__PURE__ */ _interopDefaultCompat(path$3), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk), require$$0__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$0$5), require$$1__default = /* @__PURE__ */ _interopDefaultCompat(require$$1$2), require$$0__default = /* @__PURE__ */ _interopDefaultCompat(require$$0$4), process__default = /* @__PURE__ */ _interopDefaultCompat(process$2), childProcess__default = /* @__PURE__ */ _interopDefaultCompat(childProcess), fs__default = /* @__PURE__ */ _interopDefaultCompat(fs), util__default = /* @__PURE__ */ _interopDefaultCompat(util$4), require$$0__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$0$6), require$$5__default = /* @__PURE__ */ _interopDefaultCompat(require$$5$1), require$$1__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$1$3), require$$2__default = /* @__PURE__ */ _interopDefaultCompat(require$$2$1), require$$0__default$3 = /* @__PURE__ */ _interopDefaultCompat(require$$0$7), require$$0__default$4 = /* @__PURE__ */ _interopDefaultCompat(require$$0$8), require$$0__default$5 = /* @__PURE__ */ _interopDefaultCompat(require$$0$9), require$$0__default$6 = /* @__PURE__ */ _interopDefaultCompat(require$$0$a), require$$0__default$7 = /* @__PURE__ */ _interopDefaultCompat(require$$0$b), require$$6__default = /* @__PURE__ */ _interopDefaultCompat(require$$6$1), semver__default = /* @__PURE__ */ _interopDefaultCompat(semver), pkgDir__default = /* @__PURE__ */ _interopDefaultCompat(pkgDir), require$$3__default = /* @__PURE__ */ _interopDefaultCompat(require$$3$1), require$$1__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$1$4), require$$0__default$8 = /* @__PURE__ */ _interopDefaultCompat(require$$0$c), require$$0__default$9 = /* @__PURE__ */ _interopDefaultCompat(require$$0$d), Stream__default = /* @__PURE__ */ _interopDefaultCompat(Stream), require$$2__default$1 = /* @__PURE__ */ _interopDefaultCompat(require$$2$2), require$$0__default$a = /* @__PURE__ */ _interopDefaultCompat(require$$0$e), require$$7__default = /* @__PURE__ */ _interopDefaultCompat(require$$7$1), http__default = /* @__PURE__ */ _interopDefaultCompat(http), traverse__default = /* @__PURE__ */ _interopDefaultCompat(traverse), require$$2__default$2 = /* @__PURE__ */ _interopDefaultCompat(require$$2$3), require$$0__default$b = /* @__PURE__ */ _interopDefaultCompat(require$$0$f), resolveFrom$1 = { exports: {} }, hasRequiredResolveFrom;
56
56
  function requireResolveFrom() {
57
57
  if (hasRequiredResolveFrom) return resolveFrom$1.exports;
58
58
  hasRequiredResolveFrom = 1;
@@ -3767,7 +3767,500 @@ function print() { __p += __j.call(arguments, '') }
3767
3767
  }(lodash$1, lodash$1.exports)), lodash$1.exports;
3768
3768
  }
3769
3769
  var lodashExports = requireLodash();
3770
- const purpose$2 = "Transform `sanity/desk` imports to `sanity/structure`", description$3 = `
3770
+ const helpText$l = `
3771
+ Arguments
3772
+ [type] Type of Resource to add (currently only 'function' is supported)
3773
+
3774
+ Examples
3775
+ # Add a Function Resource
3776
+ sanity blueprints add function
3777
+ `, addBlueprintsCommand = {
3778
+ name: "add",
3779
+ group: "blueprints",
3780
+ helpText: helpText$l,
3781
+ signature: "<type>",
3782
+ description: "Add a Resource to a Blueprint",
3783
+ hideFromHelp: !0,
3784
+ async action(args, context) {
3785
+ const { output, prompt: prompt2 } = context, { print } = output, [resourceType] = args.argsWithoutOptions;
3786
+ if (!resourceType) {
3787
+ print("Resource type is required. Available types: function");
3788
+ return;
3789
+ }
3790
+ const { blueprint: blueprintAction, resources: resourcesAction } = await import("@sanity/runtime-cli/actions/blueprints");
3791
+ if (!blueprintAction.findBlueprintFile()) {
3792
+ print("No blueprint file found. Run `sanity blueprints init` first.");
3793
+ return;
3794
+ }
3795
+ if (resourceType === "function") {
3796
+ const functionName = await prompt2.single({
3797
+ type: "input",
3798
+ message: "Enter function name:",
3799
+ validate: (input2) => input2.length > 0 || "Function name is required"
3800
+ }), functionType = await prompt2.single({
3801
+ type: "list",
3802
+ message: "Choose function type:",
3803
+ choices: [
3804
+ { value: "document-publish", name: "Document Publish" },
3805
+ { value: "document-create", name: "Document Create (Available soon)", disabled: !0 },
3806
+ { value: "document-delete", name: "Document Delete (Available soon)", disabled: !0 }
3807
+ ]
3808
+ }), { filePath, resourceAdded, resource } = resourcesAction.createFunctionResource({
3809
+ name: functionName,
3810
+ type: functionType,
3811
+ displayName: functionName
3812
+ });
3813
+ print(`
3814
+ Created function: ${filePath}`), resourceAdded ? print("Function Resource added to Blueprint") : (print(`
3815
+ Add this Function Resource to your Blueprint:`), print(JSON.stringify(resource, null, 2)));
3816
+ return;
3817
+ }
3818
+ print(`Unsupported resource type: ${resourceType}. Available types: function`);
3819
+ }
3820
+ }, blueprintsGroup = {
3821
+ name: "blueprints",
3822
+ signature: "[COMMAND]",
3823
+ isGroupRoot: !0,
3824
+ description: "Deploy and manage Sanity Blueprints and Stacks (IaC)",
3825
+ hideFromHelp: !0
3826
+ }, helpText$k = `
3827
+ Options
3828
+ --edit Edit the configuration
3829
+
3830
+ Examples
3831
+ # View current configuration
3832
+ sanity blueprints config
3833
+
3834
+ # Edit configuration
3835
+ sanity blueprints config --edit
3836
+ `, defaultFlags$6 = {
3837
+ edit: !1
3838
+ }, configBlueprintsCommand = {
3839
+ name: "config",
3840
+ group: "blueprints",
3841
+ helpText: helpText$k,
3842
+ signature: "[--edit]",
3843
+ description: "View or edit local Blueprints configuration",
3844
+ hideFromHelp: !0,
3845
+ async action(args, context) {
3846
+ const { apiClient, output, prompt: prompt2 } = context, { print } = output, flags = { ...defaultFlags$6, ...args.extOptions }, client2 = apiClient({
3847
+ requireUser: !0,
3848
+ requireProject: !1
3849
+ }), { token: token2 } = client2.config(), {
3850
+ blueprint: blueprintAction,
3851
+ projects: projectsAction,
3852
+ stacks: stacksAction
3853
+ } = await import("@sanity/runtime-cli/actions/blueprints"), config2 = blueprintAction.readConfigFile();
3854
+ if (!config2) {
3855
+ print("No configuration found. Run `sanity blueprints init` first.");
3856
+ return;
3857
+ }
3858
+ if (print(`
3859
+ Current configuration:`), print(JSON.stringify(config2, null, 2)), !flags.edit)
3860
+ return;
3861
+ if (!token2) {
3862
+ print("No API token found. Please run `sanity login` first.");
3863
+ return;
3864
+ }
3865
+ const { ok, projects, error: error2 } = await projectsAction.listProjects({ token: token2 });
3866
+ if (!ok) {
3867
+ print(error2);
3868
+ return;
3869
+ }
3870
+ if (!projects || projects.length === 0) {
3871
+ print("No Projects found. Please create a Project in Sanity.io first.");
3872
+ return;
3873
+ }
3874
+ const projectChoices = projects.map(({ displayName, id }) => ({
3875
+ value: id,
3876
+ name: `${displayName} <${id}>`
3877
+ })), projectId = await prompt2.single({
3878
+ type: "list",
3879
+ message: "Select your Sanity Project:",
3880
+ choices: projectChoices,
3881
+ default: config2.projectId
3882
+ }), auth = { token: token2, projectId }, { ok: stacksOk, stacks, error: stacksError } = await stacksAction.listStacks(auth);
3883
+ if (!stacksOk) {
3884
+ print(stacksError);
3885
+ return;
3886
+ }
3887
+ let stackId;
3888
+ if (stacks && stacks.length > 0) {
3889
+ const stackChoices = stacks.map(({ name, id }) => ({
3890
+ value: id,
3891
+ name: `${name} <${id}>`
3892
+ }));
3893
+ stackId = await prompt2.single({
3894
+ type: "list",
3895
+ message: "Select a Stack:",
3896
+ choices: stackChoices,
3897
+ default: config2.stackId
3898
+ });
3899
+ }
3900
+ blueprintAction.writeConfigFile({ projectId, stackId }), print(`
3901
+ Configuration updated successfully.`);
3902
+ }
3903
+ }, helpText$j = `
3904
+ Examples
3905
+ # Deploy the current blueprint
3906
+ sanity blueprints deploy
3907
+ `, deployBlueprintsCommand = {
3908
+ name: "deploy",
3909
+ group: "blueprints",
3910
+ helpText: helpText$j,
3911
+ signature: "",
3912
+ description: "Deploy a Blueprint to create or update a Stack",
3913
+ hideFromHelp: !0,
3914
+ /* eslint-disable-next-line complexity, max-statements */
3915
+ async action(args, context) {
3916
+ const { apiClient, output, prompt: prompt2 } = context, { print } = output, client2 = apiClient({
3917
+ requireUser: !0,
3918
+ requireProject: !1
3919
+ }), { token: token2 } = client2.config(), {
3920
+ blueprint: blueprintAction,
3921
+ stacks: stacksAction,
3922
+ assets: assetsAction
3923
+ } = await import("@sanity/runtime-cli/actions/blueprints"), { display } = await import("@sanity/runtime-cli/utils");
3924
+ if (!token2) {
3925
+ print("No API token found. Please run `sanity login` first.");
3926
+ return;
3927
+ }
3928
+ let blueprint = null;
3929
+ try {
3930
+ blueprint = await blueprintAction.readBlueprintOnDisk({ getStack: !0, token: token2 });
3931
+ } catch {
3932
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
3933
+ return;
3934
+ }
3935
+ if (!blueprint) {
3936
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
3937
+ return;
3938
+ }
3939
+ const {
3940
+ errors,
3941
+ projectId: configuredProjectId,
3942
+ stackId,
3943
+ parsedBlueprint,
3944
+ deployedStack
3945
+ } = blueprint;
3946
+ if (errors && errors.length > 0) {
3947
+ print(errors);
3948
+ return;
3949
+ }
3950
+ if (stackId && !deployedStack) {
3951
+ print("Stack specified in config, but deployed Stack not found.");
3952
+ return;
3953
+ }
3954
+ const resources = parsedBlueprint.resources || [];
3955
+ let projectId = configuredProjectId;
3956
+ if (projectId || (print("No Sanity Project context found in Blueprint configuration."), projectId = await prompt2.single({
3957
+ type: "input",
3958
+ message: "Enter Sanity Project ID:"
3959
+ })), !projectId) {
3960
+ print("Sanity Project context is required"), print("To configure this Blueprint, run `sanity blueprints config`");
3961
+ return;
3962
+ }
3963
+ const auth = { token: token2, projectId };
3964
+ let name = deployedStack?.name;
3965
+ if (name || (name = await prompt2.single({
3966
+ type: "input",
3967
+ message: "Enter stack name:",
3968
+ validate: (input2) => input2.length > 0 || "Stack name is required"
3969
+ })), !name) {
3970
+ print("Stack name is required");
3971
+ return;
3972
+ }
3973
+ const validResources = resources?.filter((r) => r.type), functionResources = validResources?.filter((r) => r.type.startsWith("sanity.function."));
3974
+ if (functionResources?.length)
3975
+ for (const resource of functionResources) {
3976
+ print(`Processing ${resource.name}...`);
3977
+ const result = await assetsAction.stashAsset({ resource, auth });
3978
+ if (result.success && result.assetId) {
3979
+ const src2 = resource.src;
3980
+ resource.src = result.assetId;
3981
+ const { yellow } = display.colors;
3982
+ print(`${resource.name} <${yellow(result.assetId)}>`), print(` Source: ${src2}`);
3983
+ } else
3984
+ throw print(` Error: ${result.error}`), new Error(`Failed to process ${resource.name}`);
3985
+ }
3986
+ const stackPayload = {
3987
+ name,
3988
+ projectId,
3989
+ document: { resources: validResources }
3990
+ };
3991
+ print("Deploying stack...");
3992
+ const {
3993
+ ok: deployOk,
3994
+ stack: stack2,
3995
+ error: deployError
3996
+ } = deployedStack ? await stacksAction.updateStack({ stackId: deployedStack.id, stackPayload, auth }) : await stacksAction.createStack({ stackPayload, auth });
3997
+ if (deployOk) {
3998
+ const { green, bold: bold2, yellow } = display.colors;
3999
+ print(
4000
+ `${green("Success!")} Stack "${bold2(stack2.name)}" ${deployedStack ? "updated" : "created"} <${yellow(stack2.id)}>`
4001
+ ), blueprintAction.writeConfigFile({
4002
+ projectId,
4003
+ stackId: stack2.id
4004
+ }), print("\nUse `sanity blueprints info` to check deployment status");
4005
+ } else {
4006
+ const { red } = display.colors;
4007
+ print(`${red("Failed")} to ${deployedStack ? "update" : "create"} stack`), print(`Error: ${deployError || JSON.stringify(stack2, null, 2) || "Unknown error"}`);
4008
+ }
4009
+ }
4010
+ }, helpText$i = `
4011
+ Options
4012
+ --id, -i Stack ID
4013
+
4014
+ Examples
4015
+ # Retrieve information about the current Stack
4016
+ sanity blueprints info
4017
+
4018
+ # Retrieve information about a specific Stack
4019
+ sanity blueprints info --id <stack-id>
4020
+ `, defaultFlags$5 = { id: void 0 }, infoBlueprintsCommand = {
4021
+ name: "info",
4022
+ group: "blueprints",
4023
+ helpText: helpText$i,
4024
+ signature: "",
4025
+ description: "Retrieve information about a Blueprint Stack",
4026
+ hideFromHelp: !0,
4027
+ async action(args, context) {
4028
+ const { apiClient, output } = context, { print } = output, flags = { ...defaultFlags$5, ...args.extOptions }, client2 = apiClient({
4029
+ requireUser: !0,
4030
+ requireProject: !1
4031
+ }), { token: token2 } = client2.config(), { blueprint: blueprintAction, stacks: stacksAction } = await import("@sanity/runtime-cli/actions/blueprints"), { display } = await import("@sanity/runtime-cli/utils");
4032
+ let blueprint = null;
4033
+ try {
4034
+ blueprint = await blueprintAction.readBlueprintOnDisk({ token: token2 });
4035
+ } catch {
4036
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4037
+ return;
4038
+ }
4039
+ if (!blueprint) {
4040
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4041
+ return;
4042
+ }
4043
+ const { errors, deployedStack, projectId } = blueprint;
4044
+ if (errors && errors.length > 0) {
4045
+ print(errors);
4046
+ return;
4047
+ }
4048
+ if (token2 && projectId) {
4049
+ const auth = { token: token2, projectId };
4050
+ let result;
4051
+ if (flags.id) {
4052
+ const { stack: stack2, error: error2, ok } = await stacksAction.getStack({ stackId: flags.id, auth });
4053
+ ok ? result = stack2 : print(error2);
4054
+ } else
4055
+ result = deployedStack;
4056
+ print(result ? display.blueprintsFormatting.formatStackInfo(result) : "No Stack found");
4057
+ } else
4058
+ print("Cannot retrieve information for Blueprint: missing API token or Project ID");
4059
+ }
4060
+ }, helpText$h = `
4061
+ Examples
4062
+ # Create a new Blueprint manifest file
4063
+ sanity blueprints init
4064
+ `, initBlueprintsCommand = {
4065
+ name: "init",
4066
+ group: "blueprints",
4067
+ helpText: helpText$h,
4068
+ signature: "",
4069
+ description: "Initialize a new Blueprint manifest file",
4070
+ hideFromHelp: !0,
4071
+ async action(args, context) {
4072
+ const { apiClient, output, prompt: prompt2 } = context, { print } = output, client2 = apiClient({
4073
+ requireUser: !0,
4074
+ requireProject: !1
4075
+ }), { token: token2 } = client2.config();
4076
+ if (!token2) {
4077
+ print("No API token found. Please run `sanity login` first.");
4078
+ return;
4079
+ }
4080
+ const { blueprint: blueprintAction, projects: projectsAction } = await import("@sanity/runtime-cli/actions/blueprints"), existingBlueprint = blueprintAction.findBlueprintFile();
4081
+ if (existingBlueprint) {
4082
+ print(`A blueprint file already exists: ${existingBlueprint.fileName}`);
4083
+ return;
4084
+ }
4085
+ const blueprintExtension = await prompt2.single({
4086
+ type: "list",
4087
+ message: "Choose a Blueprint manifest file type:",
4088
+ choices: [
4089
+ { value: "json", name: "JSON (Recommended)" },
4090
+ { value: "js", name: "JavaScript (Available soon)", disabled: !0 },
4091
+ { value: "ts", name: "TypeScript (Available soon)", disabled: !0 }
4092
+ ]
4093
+ }), { ok, projects, error: error2 } = await projectsAction.listProjects({ token: token2 });
4094
+ if (!ok) {
4095
+ print(error2);
4096
+ return;
4097
+ }
4098
+ if (!projects || projects.length === 0) {
4099
+ print("No Projects found. Please create a Project in Sanity.io first.");
4100
+ return;
4101
+ }
4102
+ const projectChoices = projects.map(({ displayName, id }) => ({
4103
+ value: id,
4104
+ name: `${displayName} <${id}>`
4105
+ })), projectId = await prompt2.single({
4106
+ type: "list",
4107
+ message: "Select your Sanity Project:",
4108
+ choices: projectChoices
4109
+ }), fileName = `blueprint.${blueprintExtension}`, filePath = path$3.join(process$2.cwd(), fileName);
4110
+ blueprintAction.writeBlueprintToDisk({
4111
+ path: filePath,
4112
+ fileType: blueprintExtension
4113
+ }), blueprintAction.writeConfigFile({ projectId }), print(`Created new blueprint: ./${fileName}`), blueprintExtension === "ts" && print(`
4114
+ Note: TypeScript support requires "tsx" to be installed. Run: npm install -D tsx`);
4115
+ }
4116
+ }, helpText$g = `
4117
+
4118
+ Examples
4119
+ # Show logs for the current Stack
4120
+ sanity blueprints logs
4121
+
4122
+ `, logsBlueprintsCommand = {
4123
+ name: "logs",
4124
+ group: "blueprints",
4125
+ helpText: helpText$g,
4126
+ signature: "[--watch]",
4127
+ description: "Display logs for the current Blueprint Stack",
4128
+ hideFromHelp: !0,
4129
+ async action(args, context) {
4130
+ const { apiClient, output } = context, { print } = output, client2 = apiClient({ requireUser: !0, requireProject: !1 }), { token: token2 } = client2.config();
4131
+ if (!token2) {
4132
+ print("No API token found. Please run `sanity login` first.");
4133
+ return;
4134
+ }
4135
+ const { blueprint: blueprintAction, logs: logsAction } = await import("@sanity/runtime-cli/actions/blueprints"), { display } = await import("@sanity/runtime-cli/utils");
4136
+ let blueprint = null;
4137
+ try {
4138
+ blueprint = await blueprintAction.readBlueprintOnDisk({ token: token2 });
4139
+ } catch {
4140
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4141
+ return;
4142
+ }
4143
+ if (!blueprint) {
4144
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4145
+ return;
4146
+ }
4147
+ const { errors, deployedStack } = blueprint;
4148
+ if (errors && errors.length > 0) {
4149
+ print(errors);
4150
+ return;
4151
+ }
4152
+ if (!deployedStack) {
4153
+ print("Stack not found");
4154
+ return;
4155
+ }
4156
+ const { id: stackId, projectId, name } = deployedStack, auth = { token: token2, projectId };
4157
+ print(`Fetching logs for stack ${display.colors.yellow(`<${stackId}>`)}`);
4158
+ try {
4159
+ const { ok, logs, error: error2 } = await logsAction.getLogs(stackId, auth);
4160
+ if (!ok) {
4161
+ print(`${display.colors.red("Failed")} to retrieve logs`), print(`Error: ${error2 || "Unknown error"}`);
4162
+ return;
4163
+ }
4164
+ if (logs.length === 0) {
4165
+ print(`No logs found for Stack ${stackId}`);
4166
+ return;
4167
+ }
4168
+ print(`${display.blueprintsFormatting.formatTitle("Blueprint", name)} Logs`), print(
4169
+ `Found ${display.colors.bold(logs.length.toString())} log entries for stack ${display.colors.yellow(stackId)}
4170
+ `
4171
+ );
4172
+ const logsByDay = display.logsFormatting.organizeLogsByDay(logs);
4173
+ print(display.logsFormatting.formatLogsByDay(logsByDay));
4174
+ } catch (err) {
4175
+ print("Failed to retrieve logs"), err instanceof Error && print(`Error: ${err.message}`);
4176
+ }
4177
+ }
4178
+ }, helpText$f = `
4179
+ Safe to run at any time. Will not modify any Resources.
4180
+
4181
+ Examples
4182
+ # Show deployment plan
4183
+ sanity blueprints plan
4184
+ `, planBlueprintsCommand = {
4185
+ name: "plan",
4186
+ group: "blueprints",
4187
+ helpText: helpText$f,
4188
+ signature: "",
4189
+ description: "Enumerate Resources to be deployed",
4190
+ hideFromHelp: !0,
4191
+ async action(args, context) {
4192
+ const { apiClient, output } = context, { print } = output, client2 = apiClient({ requireUser: !0, requireProject: !1 }), { token: token2 } = client2.config(), { blueprint: blueprintAction } = await import("@sanity/runtime-cli/actions/blueprints"), { display } = await import("@sanity/runtime-cli/utils");
4193
+ let blueprint = null;
4194
+ try {
4195
+ blueprint = await blueprintAction.readBlueprintOnDisk({ token: token2 });
4196
+ } catch {
4197
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4198
+ return;
4199
+ }
4200
+ if (!blueprint) {
4201
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4202
+ return;
4203
+ }
4204
+ const { errors, projectId, stackId, parsedBlueprint, fileInfo } = blueprint;
4205
+ errors && errors.length > 0 && print(errors);
4206
+ const resources = parsedBlueprint.resources || [];
4207
+ projectId || (print("Unable to determine Project ID."), print("To configure this Blueprint, run `sanity blueprints config`"));
4208
+ const name = stackId || "Unknown";
4209
+ print(`${display.blueprintsFormatting.formatTitle("Blueprint", name)} Plan
4210
+ `), print(`Blueprint document: (${fileInfo.fileName})`), print(""), print(display.blueprintsFormatting.formatResourceTree(resources)), print("\nRun `sanity blueprints deploy` to deploy these changes");
4211
+ }
4212
+ }, helpText$e = `
4213
+ Examples
4214
+ # List all Stacks for the current Project
4215
+ sanity blueprints stacks
4216
+ `, stacksBlueprintsCommand = {
4217
+ name: "stacks",
4218
+ group: "blueprints",
4219
+ helpText: helpText$e,
4220
+ signature: "",
4221
+ description: "List all Blueprint Stacks for the current Project",
4222
+ hideFromHelp: !0,
4223
+ async action(args, context) {
4224
+ const { apiClient, output } = context, { print } = output, client2 = apiClient({ requireUser: !0, requireProject: !1 }), { token: token2 } = client2.config();
4225
+ if (!token2) {
4226
+ print("No API token found. Please run `sanity login` first.");
4227
+ return;
4228
+ }
4229
+ const { blueprint: blueprintAction, stacks: stacksAction } = await import("@sanity/runtime-cli/actions/blueprints"), { display } = await import("@sanity/runtime-cli/utils");
4230
+ let blueprint = null;
4231
+ try {
4232
+ blueprint = await blueprintAction.readBlueprintOnDisk({ token: token2 });
4233
+ } catch {
4234
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4235
+ return;
4236
+ }
4237
+ if (!blueprint) {
4238
+ print("Unable to read Blueprint manifest file. Run `sanity blueprints init`");
4239
+ return;
4240
+ }
4241
+ const { errors, projectId, stackId } = blueprint;
4242
+ if (errors && errors.length > 0) {
4243
+ print(errors);
4244
+ return;
4245
+ }
4246
+ if (!projectId) {
4247
+ print("Blueprint is not configured for a Project. Run `sanity blueprints config`");
4248
+ return;
4249
+ }
4250
+ const auth = { token: token2, projectId }, { ok, stacks, error: error2 } = await stacksAction.listStacks(auth);
4251
+ if (!ok) {
4252
+ print(error2 || "Failed to list Stacks");
4253
+ return;
4254
+ }
4255
+ if (!stacks || stacks.length === 0) {
4256
+ print("No Stacks found");
4257
+ return;
4258
+ }
4259
+ const { bold: bold2, yellow } = display.colors;
4260
+ print(`${bold2("Project")} <${yellow(projectId)}> ${bold2("Stacks")}:
4261
+ `), print(display.blueprintsFormatting.formatStacksListing(stacks, stackId));
4262
+ }
4263
+ }, purpose$2 = "Transform `sanity/desk` imports to `sanity/structure`", description$3 = `
3771
4264
  Modifies all code paths that are found to import from 'sanity/desk' to instead import from
3772
4265
  'sanity/structure', and renames any renamed members.
3773
4266
 
@@ -7491,8 +7984,8 @@ Examples
7491
7984
  description: "Start the Sanity Function emulator",
7492
7985
  hideFromHelp: !0,
7493
7986
  async action(args, context) {
7494
- const { output } = context, { print } = output, flags = { ...defaultFlags$4, ...args.extOptions }, { functionsActions } = await import("@sanity/runtime-cli");
7495
- functionsActions.dev.dev(flags.port), print(`Server is running on port ${flags.port}
7987
+ const { output } = context, { print } = output, flags = { ...defaultFlags$4, ...args.extOptions }, { dev: devAction } = await import("@sanity/runtime-cli/actions/functions");
7988
+ devAction.dev(flags.port), print(`Server is running on port ${flags.port}
7496
7989
  `), open(`http://localhost:${flags.port}`);
7497
7990
  }
7498
7991
  }, helpText$b = `
@@ -7531,7 +8024,7 @@ Examples
7531
8024
  print("You must provide a function name");
7532
8025
  return;
7533
8026
  }
7534
- const token2 = client2.config().token, { blueprintsActions, functionsActions, utils: utils2 } = await import("@sanity/runtime-cli"), { deployedStack } = await blueprintsActions.blueprint.readBlueprintOnDisk({
8027
+ const token2 = client2.config().token, { env } = await import("@sanity/runtime-cli/actions/functions"), { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { findFunction } = await import("@sanity/runtime-cli/utils"), { deployedStack } = await blueprint.readBlueprintOnDisk({
7535
8028
  getStack: !0,
7536
8029
  token: token2
7537
8030
  });
@@ -7539,26 +8032,21 @@ Examples
7539
8032
  print("Stack not found");
7540
8033
  return;
7541
8034
  }
7542
- const projectId = blueprintsActions.blueprint.readConfigFile()?.projectId, { externalId } = utils2.findFunctions.findFunctionByName(
8035
+ const projectId = blueprint.readConfigFile()?.projectId, { externalId } = findFunction.findFunctionByName(
7543
8036
  deployedStack,
7544
8037
  flags.name
7545
8038
  );
7546
8039
  if (token2 && projectId) {
7547
8040
  if (flags.add) {
7548
8041
  print(`Updating "${flags.key}" environment variable in "${flags.name}"`);
7549
- const result = await functionsActions.env.update.update(
7550
- externalId,
7551
- flags.key,
7552
- flags.value,
7553
- {
7554
- token: token2,
7555
- projectId
7556
- }
7557
- );
8042
+ const result = await env.update.update(externalId, flags.key, flags.value, {
8043
+ token: token2,
8044
+ projectId
8045
+ });
7558
8046
  result.ok ? print(`Update of ${flags.key} succeeded`) : (print(`Failed to update ${flags.key}`), print(`Error: ${result.error || "Unknown error"}`));
7559
8047
  } else if (flags.remove) {
7560
8048
  print(`Removing "${flags.key}" environment variable in "${flags.name}"`);
7561
- const result = await functionsActions.env.remove.remove(externalId, flags.key, {
8049
+ const result = await env.remove.remove(externalId, flags.key, {
7562
8050
  token: token2,
7563
8051
  projectId
7564
8052
  });
@@ -7608,7 +8096,7 @@ Examples
7608
8096
  print("You must provide a function name");
7609
8097
  return;
7610
8098
  }
7611
- const token2 = client2.config().token, { blueprintsActions, utils: utils2 } = await import("@sanity/runtime-cli"), { deployedStack } = await blueprintsActions.blueprint.readBlueprintOnDisk({
8099
+ const token2 = client2.config().token, { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { findFunction } = await import("@sanity/runtime-cli/utils"), { deployedStack } = await blueprint.readBlueprintOnDisk({
7612
8100
  getStack: !0,
7613
8101
  token: token2
7614
8102
  });
@@ -7616,12 +8104,12 @@ Examples
7616
8104
  print("Stack not found");
7617
8105
  return;
7618
8106
  }
7619
- const projectId = blueprintsActions.blueprint.readConfigFile()?.projectId, { externalId } = utils2.findFunctions.findFunctionByName(
8107
+ const projectId = blueprint.readConfigFile()?.projectId, { externalId } = findFunction.findFunctionByName(
7620
8108
  deployedStack,
7621
8109
  flags.name
7622
8110
  );
7623
8111
  if (token2 && projectId) {
7624
- const { functionsActions } = await import("@sanity/runtime-cli"), { ok, error: error2, logs, total } = await functionsActions.logs.logs(
8112
+ const { logs: logsAction } = await import("@sanity/runtime-cli/actions/functions"), { ok, error: error2, logs, total } = await logsAction.logs(
7625
8113
  externalId,
7626
8114
  { limit: flags.limit },
7627
8115
  { token: token2, projectId }
@@ -7685,15 +8173,20 @@ Examples
7685
8173
  print("You must provide a function name");
7686
8174
  return;
7687
8175
  }
7688
- const { blueprintsActions, functionsActions, utils: utils2 } = await import("@sanity/runtime-cli"), { parsedBlueprint } = await blueprintsActions.blueprint.readBlueprintOnDisk({
8176
+ const { test } = await import("@sanity/runtime-cli/actions/functions"), { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { findFunction } = await import("@sanity/runtime-cli/utils"), { parsedBlueprint } = await blueprint.readBlueprintOnDisk({
7689
8177
  getStack: !1
7690
- }), src2 = utils2.findFunctions.getFunctionSource(parsedBlueprint, flags.name);
8178
+ }), src2 = findFunction.getFunctionSource(parsedBlueprint, flags.name);
7691
8179
  src2 || print(`Error: Function ${flags.name} has no source code`);
7692
- const { json: json2, logs, error: error2 } = await functionsActions.test.testAction(src2, {
7693
- data: flags.data,
7694
- file: flags.file,
7695
- timeout: flags.timeout
7696
- });
8180
+ const { json: json2, logs, error: error2 } = await test.testAction(
8181
+ src2,
8182
+ {
8183
+ data: flags.data,
8184
+ file: flags.file,
8185
+ timeout: flags.timeout
8186
+ },
8187
+ {}
8188
+ // @TODO: Add context
8189
+ );
7697
8190
  error2 ? print(error2.toString()) : (print("Logs:"), print(logs), print("Response:"), print(JSON.stringify(json2, null, 2)));
7698
8191
  }
7699
8192
  };
@@ -54123,7 +54616,16 @@ const baseCommands = [
54123
54616
  devFunctionsCommand,
54124
54617
  logsFunctionsCommand,
54125
54618
  testFunctionsCommand,
54126
- envFunctionsCommand
54619
+ envFunctionsCommand,
54620
+ blueprintsGroup,
54621
+ infoBlueprintsCommand,
54622
+ stacksBlueprintsCommand,
54623
+ initBlueprintsCommand,
54624
+ deployBlueprintsCommand,
54625
+ logsBlueprintsCommand,
54626
+ addBlueprintsCommand,
54627
+ configBlueprintsCommand,
54628
+ planBlueprintsCommand
54127
54629
  ], copyProperty = (to, from2, property, ignoreNonConfigurable) => {
54128
54630
  if (property === "length" || property === "prototype" || property === "arguments" || property === "caller")
54129
54631
  return;