@sanity/cli 5.5.0-next.9 → 5.5.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 os = require("node:os"), chalk = require("chalk"), loadEnv = require("./loadEnv.js"), require$$0$5 = require("path"), require$$1$2 = require("module"), require$$0$4 = require("fs"), semver = require("semver"), telemetry = require("@sanity/telemetry"), childProcess = require("node:child_process"), fs$1 = require("node:fs"), path$3 = require("node:path"), fs = require("node:fs/promises"), util$3 = require("node:util"), require$$0$6 = require("os"), getLatestVersion = require("get-latest-version"), pkgDir = require("pkg-dir"), client$1 = require("@sanity/client"), 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$$3$1 = require("crypto"), require$$1$3 = require("child_process"), getCliConfig = require("./getCliConfig.js"), require$$0$c = require("fs/promises"), require$$0$d = require("buffer"), journeyConfig = require("./journeyConfig.js"), Stream = require("node:stream"), promises$1 = require("node:stream/promises"), templateValidator = require("@sanity/template-validator"), require$$2$1 = require("string_decoder"), require$$0$e = require("zlib"), require$$7$1 = require("process"), http = require("node:http"), jsoncParser = require("jsonc-parser"), 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$2 = require("readline"), require$$0$f = require("tty");
21
+ var os = require("node:os"), chalk = require("chalk"), loadEnv = require("./loadEnv.js"), require$$0$5 = require("path"), require$$1$2 = require("module"), require$$0$4 = require("fs"), semver = require("semver"), telemetry = require("@sanity/telemetry"), runtimeCli = require("@sanity/runtime-cli"), utils$3 = require("@sanity/runtime-cli/utils"), childProcess = require("node:child_process"), fs$1 = require("node:fs"), path$3 = require("node:path"), fs = require("node:fs/promises"), util$3 = require("node:util"), require$$0$6 = require("os"), getLatestVersion = require("get-latest-version"), pkgDir = require("pkg-dir"), client$1 = require("@sanity/client"), 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$$3$1 = require("crypto"), require$$1$3 = require("child_process"), getCliConfig = require("./getCliConfig.js"), require$$0$c = require("fs/promises"), require$$0$d = require("buffer"), journeyConfig = require("./journeyConfig.js"), Stream = require("node:stream"), promises$1 = require("node:stream/promises"), templateValidator = require("@sanity/template-validator"), require$$2$1 = require("string_decoder"), require$$0$e = require("zlib"), require$$7$1 = require("process"), http = require("node:http"), jsoncParser = require("jsonc-parser"), 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$2 = 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
  }
@@ -1575,55 +1575,64 @@ var sortBy = baseRest(function(collection, iteratees) {
1575
1575
  var length = iteratees.length;
1576
1576
  return length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1]) ? iteratees = [] : length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2]) && (iteratees = [iteratees[0]]), baseOrderBy(collection, baseFlatten(iteratees), []);
1577
1577
  });
1578
+ const ANSI_REGEX = /\x1b\[[0-9;]*m/g, OCLIF_HEADERS = [
1579
+ "ARGUMENTS",
1580
+ "FLAGS",
1581
+ "GLOBAL FLAGS",
1582
+ "FLAG DESCRIPTIONS",
1583
+ "DESCRIPTION",
1584
+ "EXAMPLES",
1585
+ "ALIASES",
1586
+ "COMMANDS",
1587
+ "TOPICS",
1588
+ "CONFIGURATION VARIABLES"
1589
+ ];
1590
+ function stripAnsi$4(str2) {
1591
+ return str2.replace(ANSI_REGEX, "");
1592
+ }
1593
+ function transformHelpLine(line3) {
1594
+ const cleanLine = stripAnsi$4(line3);
1595
+ return OCLIF_HEADERS.includes(cleanLine) ? `${cleanLine.toLowerCase()}:` : cleanLine;
1596
+ }
1597
+ function transformHelpText(command2, bin, commandId) {
1598
+ const lines2 = command2.getHelpText(bin, commandId).split(`
1599
+ `), usagePrefix = ` $ ${bin} ${commandId} `;
1600
+ let usageStartIndex = -1, usageEndIndex = -1;
1601
+ const signatureParts = [];
1602
+ for (let i = 0; i < lines2.length; i++) {
1603
+ const cleanLine = stripAnsi$4(lines2[i]);
1604
+ if (cleanLine === "USAGE") {
1605
+ usageStartIndex = i;
1606
+ continue;
1607
+ }
1608
+ usageStartIndex !== -1 && usageEndIndex === -1 && (cleanLine.startsWith(usagePrefix) ? signatureParts.push(cleanLine.slice(usagePrefix.length).trim()) : signatureParts.length > 0 && cleanLine.startsWith(" ") ? signatureParts.push(cleanLine.trim()) : (cleanLine === "" || /^[A-Z]+$/.test(cleanLine)) && (usageEndIndex = i));
1609
+ }
1610
+ const signature = signatureParts.join(" "), helpTextLines = [];
1611
+ for (let i = 0; i < lines2.length; i++)
1612
+ usageStartIndex !== -1 && i >= usageStartIndex && i < usageEndIndex || i === usageEndIndex && stripAnsi$4(lines2[i]) === "" || helpTextLines.push(transformHelpLine(lines2[i]));
1613
+ return {
1614
+ helpText: helpTextLines.join(`
1615
+ `),
1616
+ signature,
1617
+ description: command2.summary
1618
+ };
1619
+ }
1620
+ function createErrorLogger(output) {
1621
+ return (message, options2 = {}) => {
1622
+ output.error(message), options2.exit && process.exit(options2.code ?? 1);
1623
+ };
1624
+ }
1578
1625
  const BlueprintsAddExampleUsed = telemetry.defineEvent({
1579
1626
  version: 1,
1580
1627
  name: "Blueprints Add Example Used",
1581
1628
  description: "User used --example flag with blueprints add command"
1582
- }), helpText$t = `
1583
- Arguments
1584
- <type> Type of Resource to add (currently only 'function' is supported)
1585
-
1586
- Options
1587
- --name, -n <name> Name of the Resource
1588
- --fn-type <type> Type of Function to add. Available options: "document-create", "document-delete", "document-update", "document-publish". Default: "document-publish"
1589
- --fn-language, --lang <ts|js> Language of the Function. Default: "ts"
1590
- --js, --javascript Shortcut for --fn-language=js
1591
- --fn-helpers, --helpers Add helpers to the Function
1592
- --no-fn-helpers Do not add helpers to the Function
1593
- --fn-installer, Package manager to use for Function helpers
1594
- --installer <npm|pnpm|yarn> sets --fn-helpers to true
1595
- --install, -i Shortcut for --fn-installer=npm
1596
-
1597
- Examples:
1598
- # Add a Function (TypeScript by default)
1599
- sanity blueprints add function
1600
-
1601
- # Add a Function with a specific name and install helpers with npm
1602
- sanity blueprints add function --name my-function -i --helpers
1603
-
1604
- # Add a Function with a specific type
1605
- sanity blueprints add function --fn-type document-create
1606
-
1607
- # Add a Function using an example
1608
- sanity blueprints add function --example example-name
1609
-
1610
- # Add a JavaScript Function
1611
- sanity blueprints add function --js
1612
-
1613
- # Add a Function without helpers
1614
- sanity blueprints add function --no-fn-helpers
1615
-
1616
- # Add a document-publish .js Function with helpers and install with npm
1617
- sanity blueprints add function -n roboto --fn-type document-publish --js -i
1618
- `, defaultFlags$e = {
1629
+ }), defaultFlags$e = {
1619
1630
  "fn-language": "ts"
1620
1631
  // 'fn-helpers': true, // ask, for now
1621
1632
  }, addBlueprintsCommand = {
1622
1633
  name: "add",
1623
1634
  group: "blueprints",
1624
- helpText: helpText$t,
1625
- signature: "<type> [--name <name>] [--fn-type <document-create|document-delete|document-update|document-publish>] [--fn-lang <ts|js>] [--javascript]",
1626
- description: "Add a Resource to a Blueprint",
1635
+ ...transformHelpText(runtimeCli.BlueprintsAddCommand, "sanity", "blueprints add"),
1627
1636
  async action(args, context) {
1628
1637
  const { output, apiClient, telemetry: telemetry2 } = context, { extOptions } = args, [resourceType] = args.argsWithoutOptions;
1629
1638
  if (extOptions.example) {
@@ -1632,6 +1641,7 @@ Examples:
1632
1641
  "n",
1633
1642
  "fn-type",
1634
1643
  "fn-language",
1644
+ "language",
1635
1645
  "lang",
1636
1646
  "javascript",
1637
1647
  "js",
@@ -1658,7 +1668,7 @@ Examples:
1658
1668
  }
1659
1669
  const { initBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { functionAddCore } = await import("@sanity/runtime-cli/cores/functions"), cmdConfig = await initBlueprintConfig({
1660
1670
  bin: "sanity",
1661
- log: (message) => output.print(message),
1671
+ log: utils$3.logger.Logger(output.print),
1662
1672
  token: token2
1663
1673
  });
1664
1674
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
@@ -1670,7 +1680,7 @@ Examples:
1670
1680
  example: flags.example,
1671
1681
  name: flags.n ?? flags.name,
1672
1682
  type: flags["fn-type"],
1673
- language: flags.lang ?? flags["fn-language"],
1683
+ language: flags.lang ?? flags.language ?? flags["fn-language"],
1674
1684
  javascript: flags.js || flags.javascript,
1675
1685
  helpers: userWantsFnHelpers,
1676
1686
  installer: flags.installer ?? flags["fn-installer"],
@@ -1684,27 +1694,12 @@ Examples:
1684
1694
  signature: "[COMMAND]",
1685
1695
  isGroupRoot: !0,
1686
1696
  description: "Deploy and manage Sanity Blueprints and Stacks (IaC)"
1687
- }, helpText$s = `
1688
- Options
1689
- --edit, -e Modify the configuration interactively, or directly when combined with ID flags.
1690
- --project-id <id> Directly set the Project ID in the configuration. Requires --edit flag
1691
- --stack-id <id> Directly set the Stack ID in the configuration. Requires --edit flag
1692
- --verbose Output verbose logs
1693
-
1694
- Examples:
1695
- # View current configuration
1696
- sanity blueprints config
1697
-
1698
- # Edit configuration
1699
- sanity blueprints config --edit
1700
- `, defaultFlags$d = {
1697
+ }, defaultFlags$d = {
1701
1698
  //
1702
1699
  }, configBlueprintsCommand = {
1703
1700
  name: "config",
1704
1701
  group: "blueprints",
1705
- helpText: helpText$s,
1706
- signature: "[--edit] [--project-id <id>] [--stack-id <id>] [--verbose]",
1707
- description: "View or edit local Blueprints configuration",
1702
+ ...transformHelpText(runtimeCli.BlueprintsConfigCommand, "sanity", "blueprints config"),
1708
1703
  async action(args, context) {
1709
1704
  const { apiClient, output } = context, flags = { ...defaultFlags$d, ...args.extOptions }, client2 = apiClient({
1710
1705
  requireUser: !0,
@@ -1713,7 +1708,7 @@ Examples:
1713
1708
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
1714
1709
  const { initBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { blueprintConfigCore } = await import("@sanity/runtime-cli/cores/blueprints"), cmdConfig = await initBlueprintConfig({
1715
1710
  bin: "sanity",
1716
- log: (message) => output.print(message),
1711
+ log: utils$3.logger.Logger(output.print, { verbose: flags.verbose }),
1717
1712
  token: token2
1718
1713
  });
1719
1714
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
@@ -1729,24 +1724,12 @@ Examples:
1729
1724
  });
1730
1725
  if (!success) throw new Error(error2);
1731
1726
  }
1732
- }, helpText$r = `
1733
- Options
1734
- --no-wait Do not wait for Stack deployment to complete
1735
-
1736
- Examples:
1737
- # Deploy the current blueprint
1738
- sanity blueprints deploy
1739
-
1740
- # Deploy the current blueprint without waiting for completion
1741
- sanity blueprints deploy --no-wait
1742
- `, defaultFlags$c = {
1727
+ }, defaultFlags$c = {
1743
1728
  //
1744
1729
  }, deployBlueprintsCommand = {
1745
1730
  name: "deploy",
1746
1731
  group: "blueprints",
1747
- helpText: helpText$r,
1748
- signature: "[--no-wait]",
1749
- description: "Deploy a Blueprint",
1732
+ ...transformHelpText(runtimeCli.BlueprintsDeployCommand, "sanity", "blueprints deploy"),
1750
1733
  async action(args, context) {
1751
1734
  const { apiClient, output } = context, flags = { ...defaultFlags$c, ...args.extOptions }, client2 = apiClient({
1752
1735
  requireUser: !0,
@@ -1755,7 +1738,7 @@ Examples:
1755
1738
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
1756
1739
  const { initDeployedBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { blueprintDeployCore } = await import("@sanity/runtime-cli/cores/blueprints"), cmdConfig = await initDeployedBlueprintConfig({
1757
1740
  bin: "sanity",
1758
- log: (message) => output.print(message),
1741
+ log: utils$3.logger.Logger(output.print),
1759
1742
  token: token2
1760
1743
  });
1761
1744
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
@@ -1767,30 +1750,12 @@ Examples:
1767
1750
  });
1768
1751
  if (!success) throw new Error(error2);
1769
1752
  }
1770
- }, helpText$q = `
1771
- Options
1772
- --project-id Project associated with the Stack
1773
- --stack-id Stack ID to destroy (defaults to current Stack)
1774
- --force, -f Force destroy without confirmation
1775
- --no-wait Do not wait for destroy to complete
1776
-
1777
- Examples:
1778
- # Destroy the current deployment
1779
- sanity blueprints destroy
1780
-
1781
- # Force destroy without confirmation
1782
- sanity blueprints destroy --force
1783
-
1784
- # Destroy without waiting for completion
1785
- sanity blueprints destroy --no-wait
1786
- `, defaultFlags$b = {
1753
+ }, defaultFlags$b = {
1787
1754
  //
1788
1755
  }, destroyBlueprintsCommand = {
1789
1756
  name: "destroy",
1790
1757
  group: "blueprints",
1791
- helpText: helpText$q,
1792
- signature: "[--project-id <value> --stack-id <value> --force] [--no-wait]",
1793
- description: "Destroy a Blueprint Stack deployment and its resources (will not delete local files)",
1758
+ ...transformHelpText(runtimeCli.BlueprintsDestroyCommand, "sanity", "blueprints destroy"),
1794
1759
  async action(args, context) {
1795
1760
  const { apiClient, output } = context, flags = { ...defaultFlags$b, ...args.extOptions }, client2 = apiClient({
1796
1761
  requireUser: !0,
@@ -1799,7 +1764,7 @@ Examples:
1799
1764
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
1800
1765
  const { initBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { blueprintDestroyCore } = await import("@sanity/runtime-cli/cores/blueprints"), cmdConfig = await initBlueprintConfig({
1801
1766
  bin: "sanity",
1802
- log: (message) => output.print(message),
1767
+ log: utils$3.logger.Logger(output.print),
1803
1768
  token: token2
1804
1769
  });
1805
1770
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
@@ -1814,27 +1779,14 @@ Examples:
1814
1779
  });
1815
1780
  if (!success) throw new Error(error2);
1816
1781
  }
1817
- }, helpText$p = `
1818
- Options
1819
- --verbose Provide detailed information about issues
1820
- --fix Interactively update the Blueprint configuration to fix issues
1821
-
1822
- Examples:
1823
- # Check the health of the current Blueprint project
1824
- sanity blueprints doctor --verbose
1825
-
1826
- # Fix issues in the current Blueprint project
1827
- sanity blueprints doctor --fix
1828
- `, defaultFlags$a = {
1829
- // path: undefined,
1782
+ }, defaultFlags$a = {
1830
1783
  fix: !1,
1784
+ json: !1,
1831
1785
  verbose: !1
1832
1786
  }, doctorBlueprintsCommand = {
1833
1787
  name: "doctor",
1834
1788
  group: "blueprints",
1835
- helpText: helpText$p,
1836
- signature: "[--verbose] [--fix]",
1837
- description: "Diagnose potential issues with Blueprint configuration",
1789
+ ...transformHelpText(runtimeCli.BlueprintsDoctorCommand, "sanity", "blueprints doctor"),
1838
1790
  async action(args, context) {
1839
1791
  const { apiClient, output } = context, flags = { ...defaultFlags$a, ...args.extOptions }, client2 = apiClient({
1840
1792
  requireUser: !0,
@@ -1843,24 +1795,18 @@ Examples:
1843
1795
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
1844
1796
  const { blueprintDoctorCore } = await import("@sanity/runtime-cli/cores/blueprints"), { success, error: error2 } = await blueprintDoctorCore({
1845
1797
  bin: "sanity",
1846
- log: (message) => output.print(message),
1798
+ log: utils$3.logger.Logger(output.print, { verbose: flags.verbose }),
1847
1799
  token: token2,
1848
1800
  flags
1849
1801
  });
1850
1802
  if (!success) throw new Error(error2);
1851
1803
  }
1852
- }, helpText$o = `
1853
- Examples:
1854
- # Retrieve information about the current Stack
1855
- sanity blueprints info
1856
- `, defaultFlags$9 = {
1804
+ }, defaultFlags$9 = {
1857
1805
  //
1858
1806
  }, infoBlueprintsCommand = {
1859
1807
  name: "info",
1860
1808
  group: "blueprints",
1861
- helpText: helpText$o,
1862
- signature: "",
1863
- description: "Show information about a Blueprint Stack deployment",
1809
+ ...transformHelpText(runtimeCli.BlueprintsInfoCommand, "sanity", "blueprints info"),
1864
1810
  async action(args, context) {
1865
1811
  const { apiClient, output } = context, flags = { ...defaultFlags$9, ...args.extOptions }, client2 = apiClient({
1866
1812
  requireUser: !0,
@@ -1869,7 +1815,7 @@ Examples:
1869
1815
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
1870
1816
  const { initDeployedBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { blueprintInfoCore } = await import("@sanity/runtime-cli/cores/blueprints"), cmdConfig = await initDeployedBlueprintConfig({
1871
1817
  bin: "sanity",
1872
- log: (message) => output.print(message),
1818
+ log: utils$3.logger.Logger(output.print),
1873
1819
  token: token2
1874
1820
  });
1875
1821
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
@@ -1879,34 +1825,12 @@ Examples:
1879
1825
  });
1880
1826
  if (!success) throw new Error(error2);
1881
1827
  }
1882
- }, helpText$n = `
1883
- Arguments
1884
- [dir] Path to initialize the Blueprint in
1885
-
1886
- Options
1887
- --blueprint-type, --type <json> Blueprint manifest type to use for the Blueprint (json|js|ts)
1888
- --project-id <id> Sanity Project ID to use for the Blueprint
1889
- --stack-id <id> Existing Stack ID to use for the Blueprint
1890
- --stack-name <id> Name to use for a NEW Stack
1891
- --verbose Verbose output
1892
-
1893
- Examples:
1894
- # Create a new Blueprint project in the current directory
1895
- sanity blueprints init
1896
-
1897
- # Create a new Blueprint project in a specific directory
1898
- sanity blueprints init my-sanity-project --type json
1899
-
1900
- # Create a new Blueprint project in a specific directory with an example
1901
- sanity blueprints init --example example-name
1902
- `, defaultFlags$8 = {
1828
+ }, defaultFlags$8 = {
1903
1829
  //
1904
1830
  }, initBlueprintsCommand = {
1905
1831
  name: "init",
1906
1832
  group: "blueprints",
1907
- helpText: helpText$n,
1908
- signature: "[dir] [--blueprint-type <type>] [--project-id <id>]",
1909
- description: "Initialize a new Blueprint",
1833
+ ...transformHelpText(runtimeCli.BlueprintsInitCommand, "sanity", "blueprints init"),
1910
1834
  async action(args, context) {
1911
1835
  const { apiClient, output } = context, flags = { ...defaultFlags$8, ...args.extOptions }, [dir] = args.argsWithoutOptions, client2 = apiClient({
1912
1836
  requireUser: !0,
@@ -1929,7 +1853,7 @@ Examples:
1929
1853
  }
1930
1854
  const { success, error: error2 } = await blueprintInitCore({
1931
1855
  bin: "sanity",
1932
- log: (message) => output.print(message),
1856
+ log: utils$3.logger.Logger(output.print, { verbose: flags.verbose }),
1933
1857
  token: token2,
1934
1858
  args: {
1935
1859
  dir: dir ?? flags.dir
@@ -1945,24 +1869,12 @@ Examples:
1945
1869
  });
1946
1870
  if (!success) throw new Error(error2);
1947
1871
  }
1948
- }, helpText$m = `
1949
- Options
1950
- --watch, -w Watch for new Stack logs (streaming mode)
1951
-
1952
- Examples:
1953
- # Show logs for the current Stack
1954
- sanity blueprints logs
1955
-
1956
- # Watch for new logs (streaming mode)
1957
- sanity blueprints logs --watch
1958
- `, defaultFlags$7 = {
1872
+ }, defaultFlags$7 = {
1959
1873
  //
1960
1874
  }, logsBlueprintsCommand = {
1961
1875
  name: "logs",
1962
1876
  group: "blueprints",
1963
- helpText: helpText$m,
1964
- signature: "[--watch] [-w]",
1965
- description: "Display logs for a Blueprint Stack deployment",
1877
+ ...transformHelpText(runtimeCli.BlueprintsLogsCommand, "sanity", "blueprints logs"),
1966
1878
  async action(args, context) {
1967
1879
  const { apiClient, output } = context, flags = { ...defaultFlags$7, ...args.extOptions }, client2 = apiClient({
1968
1880
  requireUser: !0,
@@ -1971,7 +1883,7 @@ Examples:
1971
1883
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
1972
1884
  const { initDeployedBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { blueprintLogsCore } = await import("@sanity/runtime-cli/cores/blueprints"), cmdConfig = await initDeployedBlueprintConfig({
1973
1885
  bin: "sanity",
1974
- log: (message) => output.print(message),
1886
+ log: utils$3.logger.Logger(output.print),
1975
1887
  token: token2
1976
1888
  });
1977
1889
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
@@ -1983,23 +1895,12 @@ Examples:
1983
1895
  });
1984
1896
  if (streaming && await streaming, !success) throw new Error(error2);
1985
1897
  }
1986
- }, helpText$l = `
1987
- Safe to run at any time. Will not modify any Resources.
1988
-
1989
- Options
1990
- --version Verbose output
1991
-
1992
- Examples:
1993
- # Show deployment plan for the current Blueprint
1994
- sanity blueprints plan
1995
- `, defaultFlags$6 = {
1898
+ }, defaultFlags$6 = {
1996
1899
  //
1997
1900
  }, planBlueprintsCommand = {
1998
1901
  name: "plan",
1999
1902
  group: "blueprints",
2000
- helpText: helpText$l,
2001
- signature: "",
2002
- description: "Enumerate resources to be deployed - will not modify any resources",
1903
+ ...transformHelpText(runtimeCli.BlueprintsPlanCommand, "sanity", "blueprints plan"),
2003
1904
  async action(args, context) {
2004
1905
  const { apiClient, output } = context, flags = { ...defaultFlags$6, ...args.extOptions }, client2 = apiClient({
2005
1906
  requireUser: !0,
@@ -2008,7 +1909,7 @@ Examples:
2008
1909
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
2009
1910
  const { initBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { blueprintPlanCore } = await import("@sanity/runtime-cli/cores/blueprints"), cmdConfig = await initBlueprintConfig({
2010
1911
  bin: "sanity",
2011
- log: (message) => output.print(message),
1912
+ log: utils$3.logger.Logger(output.print, { verbose: flags.verbose }),
2012
1913
  token: token2
2013
1914
  });
2014
1915
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
@@ -2020,24 +1921,12 @@ Examples:
2020
1921
  });
2021
1922
  if (!success) throw new Error(error2);
2022
1923
  }
2023
- }, helpText$k = `
2024
- Options
2025
- --project-id <id> Project ID to use
2026
-
2027
- Examples:
2028
- # List all Stacks for the current Project
2029
- sanity blueprints stacks
2030
-
2031
- # List Stacks for a specific project
2032
- sanity blueprints stacks --project-id abc123
2033
- `, defaultFlags$5 = {
1924
+ }, defaultFlags$5 = {
2034
1925
  //
2035
1926
  }, stacksBlueprintsCommand = {
2036
1927
  name: "stacks",
2037
1928
  group: "blueprints",
2038
- helpText: helpText$k,
2039
- signature: "[--project-id <value>]",
2040
- description: "List all Blueprint Stacks",
1929
+ ...transformHelpText(runtimeCli.BlueprintsStacksCommand, "sanity", "blueprints stacks"),
2041
1930
  hideFromHelp: !1,
2042
1931
  async action(args, context) {
2043
1932
  const { apiClient, output } = context, flags = { ...defaultFlags$5, ...args.extOptions }, client2 = apiClient({
@@ -2047,7 +1936,7 @@ Examples:
2047
1936
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
2048
1937
  const { initBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { blueprintStacksCore } = await import("@sanity/runtime-cli/cores/blueprints"), cmdConfig = await initBlueprintConfig({
2049
1938
  bin: "sanity",
2050
- log: (message) => output.print(message),
1939
+ log: utils$3.logger.Logger(output.print, { verbose: flags.verbose }),
2051
1940
  token: token2
2052
1941
  });
2053
1942
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
@@ -2204,7 +2093,7 @@ function ensureNpx() {
2204
2093
  );
2205
2094
  }
2206
2095
  }
2207
- const helpText$j = `
2096
+ const helpText$g = `
2208
2097
  Runs a given code modification script on the current studio folder.
2209
2098
  Running the command without a specified codemod name will list available transformations.
2210
2099
 
@@ -2226,7 +2115,7 @@ Examples
2226
2115
  name: "codemod",
2227
2116
  signature: "[CODEMOD_NAME]",
2228
2117
  description: "Updates Sanity Studio codebase with a code modification script",
2229
- helpText: helpText$j,
2118
+ helpText: helpText$g,
2230
2119
  action: codemodAction
2231
2120
  };
2232
2121
  var lodash_isplainobject, hasRequiredLodash_isplainobject;
@@ -3919,7 +3808,7 @@ function normalizePath(input2) {
3919
3808
  const sanityDocsPrefix = "https://www.sanity.io";
3920
3809
  return input2.startsWith(sanityDocsPrefix) ? input2.replace(sanityDocsPrefix, "") : input2;
3921
3810
  }
3922
- const helpText$i = `
3811
+ const helpText$f = `
3923
3812
  Arguments
3924
3813
  <path> Path or URL to article, found in search results and docs content as links
3925
3814
 
@@ -3937,13 +3826,13 @@ Examples
3937
3826
  `, readCommand = {
3938
3827
  name: "read",
3939
3828
  group: "docs",
3940
- helpText: helpText$i,
3829
+ helpText: helpText$f,
3941
3830
  signature: "<path|url> [-w, --web]",
3942
3831
  description: "Read an article in terminal",
3943
3832
  async action(args, context) {
3944
3833
  const { output } = context, flags = args.extOptions, input2 = args.argsWithoutOptions[0];
3945
3834
  if (!input2 || typeof input2 != "string") {
3946
- output.error("Please provide an article path or URL"), output.print(""), output.print(helpText$i), process.exit(1);
3835
+ output.error("Please provide an article path or URL"), output.print(""), output.print(helpText$f), process.exit(1);
3947
3836
  return;
3948
3837
  }
3949
3838
  const path2 = normalizePath(input2);
@@ -3973,7 +3862,7 @@ async function searchDocs(options2, context) {
3973
3862
  const results = await response.json();
3974
3863
  return Array.isArray(results) ? results.slice(0, limit) : [];
3975
3864
  }
3976
- const isInteractive$1 = process.stdout.isTTY && process.env.TERM !== "dumb" && !("CI" in process.env), helpText$h = `
3865
+ const isInteractive$1 = process.stdout.isTTY && process.env.TERM !== "dumb" && !("CI" in process.env), helpText$e = `
3977
3866
  Arguments
3978
3867
  <query> Search query for documentation
3979
3868
 
@@ -3994,7 +3883,7 @@ Examples
3994
3883
  }, searchCommand = {
3995
3884
  name: "search",
3996
3885
  group: "docs",
3997
- helpText: helpText$h,
3886
+ helpText: helpText$e,
3998
3887
  signature: "<query> [--limit <limit>]",
3999
3888
  description: "Search Sanity docs",
4000
3889
  async action(args, context) {
@@ -4048,53 +3937,35 @@ Found ${results.length} result(s):
4048
3937
  }
4049
3938
  }
4050
3939
  }
4051
- }, helpText$g = `
4052
- Options
4053
- --port <port> Port to start emulator on
4054
- --open Open dev server in a new browser tab
4055
-
4056
- Examples
4057
- # Start dev server on default port
4058
- sanity functions dev
4059
-
4060
- # Start dev server on specific host
4061
- sanity functions dev --host 0.0.0.0
4062
-
4063
- # Start dev server on specific port
4064
- sanity functions dev --port 3333
4065
-
4066
- # Start dev server and open a new browser tab
4067
- sanity functions dev --open
4068
- `, defaultFlags$3 = {
3940
+ }, defaultFlags$3 = {
4069
3941
  open: !1,
4070
3942
  host: "localhost",
4071
3943
  port: 8080
4072
3944
  }, devFunctionsCommand = {
4073
3945
  name: "dev",
4074
3946
  group: "functions",
4075
- helpText: helpText$g,
4076
- signature: "[--host <host> --port <port> --open]",
4077
- description: "Start the Sanity Function emulator",
3947
+ ...transformHelpText(runtimeCli.FunctionsDevCommand, "sanity", "functions dev"),
4078
3948
  async action(args, context) {
4079
3949
  const { apiClient, output } = context, flags = { ...defaultFlags$3, ...args.extOptions }, { open: shouldOpen } = flags, client2 = apiClient({ requireUser: !0, requireProject: !1 }), { token: token2 } = client2.config();
4080
3950
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
4081
3951
  const { initBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { functionDevCore } = await import("@sanity/runtime-cli/cores/functions"), cmdConfig = await initBlueprintConfig({
4082
3952
  bin: "sanity",
4083
- log: (message) => output.print(message),
3953
+ log: utils$3.logger.Logger(output.print),
4084
3954
  token: token2
4085
3955
  });
4086
3956
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
4087
- const { success, error: error2 } = await functionDevCore({
3957
+ const resolvedHost = flags.h ?? flags.host, resolvedPort = flags.p ?? flags.port, { success, error: error2 } = await functionDevCore({
4088
3958
  ...cmdConfig.value,
4089
3959
  flags: {
4090
- host: flags.host,
4091
- port: flags.port
3960
+ host: resolvedHost,
3961
+ port: resolvedPort,
3962
+ timeout: flags.t ?? flags.timeout
4092
3963
  }
4093
3964
  });
4094
3965
  if (!success) throw new Error(error2);
4095
- shouldOpen && await open(`http://${flags.host}:${flags.port}`);
3966
+ shouldOpen && await open(`http://${resolvedHost}:${resolvedPort}`);
4096
3967
  }
4097
- }, helpText$f = `
3968
+ }, helpText$d = `
4098
3969
  Commands
4099
3970
  add Add or update an environment variable
4100
3971
  list List the environment variables
@@ -4117,7 +3988,7 @@ Examples
4117
3988
  `, envFunctionsCommand = {
4118
3989
  name: "env",
4119
3990
  group: "functions",
4120
- helpText: helpText$f,
3991
+ helpText: helpText$d,
4121
3992
  signature: "<add|list|remove> <name> [key] [value]",
4122
3993
  description: "Add or remove an environment variable or list environment variables for a Sanity function",
4123
3994
  async action(args, context) {
@@ -4138,7 +4009,7 @@ Examples
4138
4009
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
4139
4010
  const { initDeployedBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { functionEnvAddCore, functionEnvListCore, functionEnvRemoveCore } = await import("@sanity/runtime-cli/cores/functions"), cmdConfig = await initDeployedBlueprintConfig({
4140
4011
  bin: "sanity",
4141
- log: (message) => output.print(message),
4012
+ log: utils$3.logger.Logger(output.print),
4142
4013
  token: token2
4143
4014
  });
4144
4015
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
@@ -4173,46 +4044,17 @@ Examples
4173
4044
  signature: "[COMMAND]",
4174
4045
  isGroupRoot: !0,
4175
4046
  description: "Manage, test, and observe Sanity Functions"
4176
- }, helpText$e = `
4177
- Arguments
4178
- <name> The name of the Function to retrieve logs for
4179
-
4180
- Options
4181
- --limit <limit> The number of log entries to retrieve [default 50]
4182
- --json If set return json
4183
- --utc Use UTC dates in logs
4184
- --delete Delete all logs for the Function
4185
- --force Force delete all logs for the Function
4186
- --watch Watch for new logs (streaming mode)
4187
-
4188
- Examples
4189
- # Retrieve logs for Sanity Function
4190
- sanity functions logs echo
4191
-
4192
- # Retrieve the last two log entries for Sanity Function
4193
- sanity functions logs echo --limit 2
4194
-
4195
- # Retrieve logs for Sanity Function in json format
4196
- sanity functions logs echo --json
4197
-
4198
- # Delete all logs for Sanity Function
4199
- sanity functions logs echo --delete
4200
-
4201
- # Watch for new logs (streaming mode)
4202
- sanity functions logs echo --watch
4203
- `, defaultFlags$2 = {
4047
+ }, defaultFlags$2 = {
4204
4048
  limit: 50,
4205
4049
  json: !1,
4206
4050
  utc: !1,
4207
4051
  delete: !1,
4208
4052
  force: !1,
4209
4053
  watch: !1
4210
- }, logsFunctionsCommand = {
4054
+ }, transformedHelp$1 = transformHelpText(runtimeCli.FunctionsLogsCommand, "sanity", "functions logs"), logsFunctionsCommand = {
4211
4055
  name: "logs",
4212
4056
  group: "functions",
4213
- helpText: helpText$e,
4214
- signature: "<name> [--limit <number>] [--json] [--utc] [--delete [--force]] [--watch]",
4215
- description: "Retrieve or delete logs for a Sanity Function",
4057
+ ...transformedHelp$1,
4216
4058
  async action(args, context) {
4217
4059
  const { apiClient, output } = context, [name] = args.argsWithoutOptions, flags = { ...defaultFlags$2, ...args.extOptions }, client2 = apiClient({
4218
4060
  requireUser: !0,
@@ -4224,113 +4066,89 @@ Examples
4224
4066
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
4225
4067
  const { initDeployedBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { functionLogsCore } = await import("@sanity/runtime-cli/cores/functions"), cmdConfig = await initDeployedBlueprintConfig({
4226
4068
  bin: "sanity",
4227
- log: (message) => output.print(message),
4069
+ log: utils$3.logger.Logger(output.print),
4228
4070
  token: token2
4229
4071
  });
4230
4072
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
4231
4073
  const { success, error: error2 } = await functionLogsCore({
4232
4074
  ...cmdConfig.value,
4075
+ helpText: transformedHelp$1.helpText,
4076
+ error: createErrorLogger(output),
4233
4077
  args: { name },
4234
- flags
4078
+ flags: {
4079
+ limit: flags.l ?? flags.limit,
4080
+ json: flags.j ?? flags.json,
4081
+ utc: flags.u ?? flags.utc,
4082
+ delete: flags.d ?? flags.delete,
4083
+ force: flags.f ?? flags.force,
4084
+ watch: flags.w ?? flags.watch
4085
+ }
4235
4086
  });
4236
4087
  if (!success) throw new Error(error2);
4237
4088
  }
4238
- }, helpText$d = `
4239
- Arguments
4240
- <name> The name of the Sanity Function
4241
-
4242
- Options
4243
- --event <create|update|delete> The type of event to simulate (default: 'create')
4244
- --data <data> Data to send to the function
4245
- --data-before <data> Data to send to the function when event is update
4246
- --data-after <data> Data to send to the function when event is update
4247
- --file <file> Read data from file and send to the function
4248
- --file-before <file> Read data from file and send to the function when event is update
4249
- --file-after <file> Read data from file and send to the function when event is update
4250
- --document-id <id> Document to fetch and send to function
4251
- --document-id-before <id> Document to fetch and send to function when event is update
4252
- --document-id-after <id> Document to fetch and send to function when event is update
4253
- --timeout <timeout> Execution timeout value in seconds
4254
- --api <version> Sanity API Version to use
4255
- --dataset <dataset> The Sanity dataset to use
4256
- --project-id <id> Sanity Project ID to use
4257
- --with-user-token Prime access token from CLI config into context.clientOptions
4258
- --media-library-id <id> Sanity Media Library ID to use
4259
-
4260
-
4261
- Examples
4262
- # Test function passing event data on command line
4263
- sanity functions test echo --data '{ "id": 1 }'
4264
-
4265
- # Test function passing event data via a file
4266
- sanity functions test echo --file 'payload.json'
4267
-
4268
- # Test function passing event data on command line and cap execution time to 60 seconds
4269
- sanity functions test echo --data '{ "id": 1 }' --timeout 60
4270
-
4271
- # Test function simulating an update event
4272
- sanity functions test echo --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
4273
- `, defaultFlags$1 = {
4089
+ }, defaultFlags$1 = {
4274
4090
  timeout: 10,
4275
4091
  // seconds
4276
4092
  "with-user-token": !1
4277
- }, testFunctionsCommand = {
4093
+ }, transformedHelp = transformHelpText(runtimeCli.FunctionsTestCommand, "sanity", "functions test");
4094
+ function validateUpdateEventFlags(flags) {
4095
+ if (flags.event !== "update" && flags.e !== "update") return;
4096
+ const hasDataPair = flags["data-before"] && flags["data-after"], hasFilePair = flags["file-before"] && flags["file-after"], hasDocPair = flags["document-id-before"] && flags["document-id-after"];
4097
+ if (!(hasDataPair || hasFilePair || hasDocPair))
4098
+ throw new Error(
4099
+ `When using --event=update, you must provide one of the following flag pairs:
4100
+ --data-before and --data-after
4101
+ --file-before and --file-after
4102
+ --document-id-before and --document-id-after`
4103
+ );
4104
+ }
4105
+ const testFunctionsCommand = {
4278
4106
  name: "test",
4279
4107
  group: "functions",
4280
- helpText: helpText$d,
4281
- signature: "<name> [--event create|update|delete] [--data <json>] [--data-before <json>] [--data-after <json>] [--file <filename>] [--file-before <filename>] [--file-after <filename>] [--document-id <id>] [--document-id-before <id>] [--document-id-before <id>] [--timeout <seconds>] [--api <version>] [--dataset <name>] [--project-id <id>] [--media-library-id <id>] [--with-user-token]",
4282
- description: "Invoke a local Sanity Function",
4108
+ ...transformedHelp,
4283
4109
  async action(args, context) {
4284
4110
  const { apiClient, output, chalk: chalk2 } = context, [name] = args.argsWithoutOptions, flags = { ...defaultFlags$1, ...args.extOptions }, client2 = apiClient({
4285
4111
  requireUser: !0,
4286
4112
  requireProject: !1
4287
4113
  }), { dataset, projectId, token: token2 } = client2.config(), actualDataset = dataset === "~dummy-placeholder-dataset-" ? void 0 : dataset;
4288
4114
  if (!token2) throw new Error("No API token found. Please run `sanity login`.");
4289
- if (!name)
4290
- throw new Error("You must provide a function name as the first argument");
4291
- const { initBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { functionTestCore } = await import("@sanity/runtime-cli/cores/functions"), { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { projectId: bpProjectId } = await blueprint.readLocalBlueprint();
4292
- if (projectId && projectId !== bpProjectId && (output.print(
4115
+ if (!name) throw new Error("You must provide a function name as the first argument");
4116
+ const { initBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { functionTestCore } = await import("@sanity/runtime-cli/cores/functions"), { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), log = utils$3.logger.Logger(output.print), { projectId: bpProjectId } = await blueprint.readLocalBlueprint(log);
4117
+ projectId && projectId !== bpProjectId && (output.print(
4293
4118
  chalk2.yellow("WARNING"),
4294
4119
  `Project ID ${chalk2.cyan(projectId)} in ${chalk2.green("sanity.cli.ts")} does not match Project ID ${chalk2.cyan(bpProjectId)} in ${chalk2.green("./sanity/blueprint.config.json")}.`
4295
4120
  ), output.print(
4296
4121
  `Defaulting to Project ID ${chalk2.cyan(bpProjectId)}. To override use the ${chalk2.green("--project-id")} flag.
4297
4122
  `
4298
- )), flags.event === "update") {
4299
- const hasDataPair = flags["data-before"] && flags["data-after"], hasFilePair = flags["file-before"] && flags["file-after"], hasDocPair = flags["document-id-before"] && flags["document-id-after"];
4300
- if (!(hasDataPair || hasFilePair || hasDocPair))
4301
- throw new Error(
4302
- `When using --event=update, you must provide one of the following flag pairs:
4303
- --data-before and --data-after
4304
- --file-before and --file-after
4305
- --document-id-before and --document-id-after`
4306
- );
4307
- }
4123
+ )), validateUpdateEventFlags(flags);
4308
4124
  const cmdConfig = await initBlueprintConfig({
4309
4125
  bin: "sanity",
4310
- log: (message) => output.print(message),
4126
+ log,
4311
4127
  token: token2
4312
4128
  });
4313
4129
  if (!cmdConfig.ok) throw new Error(cmdConfig.error);
4314
4130
  const { success, error: error2 } = await functionTestCore({
4315
4131
  ...cmdConfig.value,
4316
4132
  args: { name },
4133
+ helpText: transformedHelp.helpText,
4134
+ error: createErrorLogger(output),
4317
4135
  flags: {
4318
- data: flags.data,
4319
- "data-before": flags["data-before"],
4136
+ api: flags.a ?? flags.api,
4320
4137
  "data-after": flags["data-after"],
4321
- file: flags.file,
4322
- "file-before": flags["file-before"],
4323
- "file-after": flags["file-after"],
4324
- "document-id": flags["document-id"],
4325
- "document-id-before": flags["document-id-before"],
4326
- "document-id-after": flags["document-id-after"],
4327
- event: flags.event,
4328
- timeout: flags.timeout,
4329
- api: flags.api,
4138
+ "data-before": flags["data-before"],
4139
+ data: flags.d ?? flags.data,
4330
4140
  dataset: flags.dataset || actualDataset,
4141
+ "document-id-after": flags["document-id-after"],
4142
+ "document-id-before": flags["document-id-before"],
4143
+ "document-id": flags["document-id"],
4144
+ event: flags.e ?? flags.event,
4145
+ "file-after": flags["file-after"],
4146
+ "file-before": flags["file-before"],
4147
+ file: flags.f ?? flags.file,
4148
+ "media-library-id": flags["media-library-id"],
4331
4149
  "project-id": flags["project-id"] || bpProjectId,
4332
- "with-user-token": flags["with-user-token"],
4333
- "media-library-id": flags["media-library-id"]
4150
+ timeout: flags.t ?? flags.timeout,
4151
+ "with-user-token": flags["with-user-token"]
4334
4152
  }
4335
4153
  });
4336
4154
  if (!success) throw new Error(error2);