jsrepo 1.6.0 → 1.7.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.
package/dist/index.js CHANGED
@@ -1077,23 +1077,54 @@ var buildBlocksDirectory = (blocksPath, { cwd, excludeDeps, includeBlocks, inclu
1077
1077
  // src/utils/context.ts
1078
1078
  var OUTPUT_FILE = "jsrepo-manifest.json";
1079
1079
 
1080
+ // src/utils/persisted.ts
1081
+ import Conf from "conf";
1082
+ var get = () => {
1083
+ return new Conf({ projectName: "jsrepo" });
1084
+ };
1085
+
1080
1086
  // src/utils/git-providers.ts
1081
1087
  var octokit = new Octokit({});
1082
1088
  var github = {
1083
1089
  name: () => "github",
1084
1090
  resolveRaw: async (repoPath, resourcePath) => {
1085
- let info;
1086
- if (typeof repoPath === "string") {
1087
- info = await github.info(repoPath);
1088
- } else {
1089
- info = repoPath;
1090
- }
1091
+ const info = await github.info(repoPath);
1091
1092
  return new URL(
1092
1093
  resourcePath,
1093
1094
  `https://raw.githubusercontent.com/${info.owner}/${info.repoName}/refs/${info.refs}/${info.ref}/`
1094
1095
  );
1095
1096
  },
1097
+ fetchRaw: async (repoPath, resourcePath) => {
1098
+ const url = await github.resolveRaw(repoPath, resourcePath);
1099
+ const errorMessage = (err) => {
1100
+ return Err(
1101
+ `There was an error fetching the \`${OUTPUT_FILE}\` from the repository \`${url.href}\` make sure the target repository has a \`${OUTPUT_FILE}\` in its root.
1102
+ Error: ${err}`
1103
+ );
1104
+ };
1105
+ try {
1106
+ const token = get().get(`${github.name()}-token`);
1107
+ const headers = new Headers();
1108
+ if (token !== void 0) {
1109
+ headers.append("Authorization", `token ${token}`);
1110
+ }
1111
+ const response = await fetch(url, { headers });
1112
+ if (!response.ok) {
1113
+ return errorMessage(`${response.status} ${response.text}`);
1114
+ }
1115
+ return Ok(await response.text());
1116
+ } catch (err) {
1117
+ return errorMessage(`${err}`);
1118
+ }
1119
+ },
1120
+ fetchManifest: async (repoPath) => {
1121
+ const manifest = await github.fetchRaw(repoPath, OUTPUT_FILE);
1122
+ if (manifest.isErr()) return Err(manifest.unwrapErr());
1123
+ const categories = v3.parse(v3.array(categorySchema), JSON.parse(manifest.unwrap()));
1124
+ return Ok(categories);
1125
+ },
1096
1126
  info: async (repoPath) => {
1127
+ if (typeof repoPath !== "string") return repoPath;
1097
1128
  const repo = repoPath.replaceAll(/(https:\/\/github.com\/)|(github\/)/g, "");
1098
1129
  const [owner, repoName, ...rest] = repo.split("/");
1099
1130
  let ref = "main";
@@ -1135,32 +1166,13 @@ var getProviderInfo = async (repo) => {
1135
1166
  }
1136
1167
  return Err("Only GitHub repositories are supported at this time!");
1137
1168
  };
1138
- var getManifest = async (url) => {
1139
- const errorMessage = (err) => {
1140
- return Err(
1141
- `There was an error fetching the \`${OUTPUT_FILE}\` from the repository \`${url.href}\` make sure the target repository has a \`${OUTPUT_FILE}\` in its root.
1142
- Error: ${err}`
1143
- );
1144
- };
1145
- try {
1146
- const response = await fetch(url);
1147
- if (!response.ok) {
1148
- return errorMessage(`${response.status} ${response.text}`);
1149
- }
1150
- const categories = v3.parse(v3.array(categorySchema), await response.json());
1151
- return Ok(categories);
1152
- } catch (err) {
1153
- return errorMessage(`${err}`);
1154
- }
1155
- };
1156
1169
  var fetchBlocks = async (...repos) => {
1157
1170
  const blocksMap = /* @__PURE__ */ new Map();
1158
1171
  for (const repo of repos) {
1159
1172
  const getProviderResult = await getProviderInfo(repo);
1160
1173
  if (getProviderResult.isErr()) return Err({ message: getProviderResult.unwrapErr(), repo });
1161
1174
  const providerInfo = getProviderResult.unwrap();
1162
- const manifestUrl = await providerInfo.provider.resolveRaw(providerInfo, OUTPUT_FILE);
1163
- const getManifestResult = await getManifest(manifestUrl);
1175
+ const getManifestResult = await providerInfo.provider.fetchManifest(providerInfo);
1164
1176
  if (getManifestResult.isErr()) return Err({ message: getManifestResult.unwrapErr(), repo });
1165
1177
  const categories = getManifestResult.unwrap();
1166
1178
  for (const category of categories) {
@@ -1528,15 +1540,14 @@ var _add = async (blockNames, options) => {
1528
1540
  fs6.mkdirSync(directory, { recursive: true });
1529
1541
  const files = [];
1530
1542
  const getSourceFile = async (filePath) => {
1531
- const rawUrl = await providerInfo.provider.resolveRaw(providerInfo, filePath);
1532
- const response = await fetch(rawUrl);
1533
- if (!response.ok) {
1534
- loading.stop(color7.red(`Error fetching ${color7.bold(rawUrl.href)}`));
1543
+ const content = await providerInfo.provider.fetchRaw(providerInfo, filePath);
1544
+ if (content.isErr()) {
1545
+ loading.stop(color7.red(`Error fetching ${color7.bold(filePath)}`));
1535
1546
  program2.error(
1536
1547
  color7.red(`There was an error trying to get ${fullSpecifier}`)
1537
1548
  );
1538
1549
  }
1539
- return await response.text();
1550
+ return content.unwrap();
1540
1551
  };
1541
1552
  for (const sourceFile of block.files) {
1542
1553
  if (!config.includeTests && isTestFile(sourceFile)) continue;
@@ -1664,24 +1675,95 @@ ${content}`;
1664
1675
  }
1665
1676
  };
1666
1677
 
1667
- // src/commands/build.ts
1668
- import fs7 from "node:fs";
1669
- import { outro as outro2, spinner as spinner3 } from "@clack/prompts";
1678
+ // src/commands/auth.ts
1679
+ import { cancel as cancel2, confirm as confirm2, isCancel as isCancel2, outro as outro2, password, select } from "@clack/prompts";
1670
1680
  import color8 from "chalk";
1671
- import { Command as Command2, program as program3 } from "commander";
1672
- import path7 from "pathe";
1681
+ import { Command as Command2, Option } from "commander";
1673
1682
  import * as v6 from "valibot";
1674
1683
  var schema3 = v6.object({
1675
- dirs: v6.array(v6.string()),
1676
- includeBlocks: v6.array(v6.string()),
1677
- includeCategories: v6.array(v6.string()),
1678
- excludeDeps: v6.array(v6.string()),
1679
- output: v6.boolean(),
1680
- errorOnWarn: v6.boolean(),
1681
- verbose: v6.boolean(),
1684
+ token: v6.optional(v6.string()),
1685
+ provider: v6.optional(v6.string()),
1686
+ logout: v6.boolean(),
1682
1687
  cwd: v6.string()
1683
1688
  });
1684
- var build = new Command2("build").description(`Builds the provided --dirs in the project root into a \`${OUTPUT_FILE}\` file.`).option("--dirs [dirs...]", "The directories containing the blocks.", ["./blocks"]).option("--include-blocks [blockNames...]", "Include only the blocks with these names.", []).option(
1689
+ var auth = new Command2("auth").description("Provide a token for access to private repositories.").option("--token <token>", "The token to use for authenticating to your provider.").addOption(
1690
+ new Option("--provider <name>", "The provider this token belongs to.").choices(
1691
+ providers.map((provider) => provider.name())
1692
+ )
1693
+ ).option("--logout", "Erase tokens from each provider from storage.", false).option("--cwd <path>", "The current working directory.", process.cwd()).action(async (opts) => {
1694
+ const options = v6.parse(schema3, opts);
1695
+ _intro(context.package.version);
1696
+ await _auth(options);
1697
+ outro2(color8.green("All done!"));
1698
+ });
1699
+ var _auth = async (options) => {
1700
+ const storage = get();
1701
+ if (options.logout) {
1702
+ for (const provider of providers) {
1703
+ const response = await confirm2({
1704
+ message: `Remove ${provider.name()} token?`,
1705
+ initialValue: true
1706
+ });
1707
+ if (isCancel2(response)) {
1708
+ cancel2("Canceled!");
1709
+ process.exit(0);
1710
+ }
1711
+ if (!response) continue;
1712
+ storage.delete(`${provider.name()}-token`);
1713
+ }
1714
+ return;
1715
+ }
1716
+ if (providers.length > 1) {
1717
+ const response = await select({
1718
+ message: "Which provider is this token for?",
1719
+ options: providers.map((provider) => ({
1720
+ label: provider.name(),
1721
+ value: provider.name()
1722
+ })),
1723
+ initialValue: providers[0].name()
1724
+ });
1725
+ if (isCancel2(response)) {
1726
+ cancel2("Canceled!");
1727
+ process.exit(0);
1728
+ }
1729
+ options.provider = response;
1730
+ } else {
1731
+ options.provider = providers[0].name();
1732
+ }
1733
+ if (options.token === void 0) {
1734
+ const response = await password({
1735
+ message: "Paste your token",
1736
+ validate(value) {
1737
+ if (value.trim() === "") return "Please provide a value";
1738
+ }
1739
+ });
1740
+ if (isCancel2(response) || !response) {
1741
+ cancel2("Canceled!");
1742
+ process.exit(0);
1743
+ }
1744
+ options.token = response;
1745
+ }
1746
+ storage.set(`${options.provider}-token`, options.token);
1747
+ };
1748
+
1749
+ // src/commands/build.ts
1750
+ import fs7 from "node:fs";
1751
+ import { outro as outro3, spinner as spinner3 } from "@clack/prompts";
1752
+ import color9 from "chalk";
1753
+ import { Command as Command3, program as program3 } from "commander";
1754
+ import path7 from "pathe";
1755
+ import * as v7 from "valibot";
1756
+ var schema4 = v7.object({
1757
+ dirs: v7.array(v7.string()),
1758
+ includeBlocks: v7.array(v7.string()),
1759
+ includeCategories: v7.array(v7.string()),
1760
+ excludeDeps: v7.array(v7.string()),
1761
+ output: v7.boolean(),
1762
+ errorOnWarn: v7.boolean(),
1763
+ verbose: v7.boolean(),
1764
+ cwd: v7.string()
1765
+ });
1766
+ var build = new Command3("build").description(`Builds the provided --dirs in the project root into a \`${OUTPUT_FILE}\` file.`).option("--dirs [dirs...]", "The directories containing the blocks.", ["./blocks"]).option("--include-blocks [blockNames...]", "Include only the blocks with these names.", []).option(
1685
1767
  "--include-categories [categoryNames...]",
1686
1768
  "Include only the categories with these names.",
1687
1769
  []
@@ -1690,10 +1772,10 @@ var build = new Command2("build").description(`Builds the provided --dirs in the
1690
1772
  "If there is a warning throw an error and do not allow build to complete.",
1691
1773
  false
1692
1774
  ).option("--verbose", "Include debug logs.", false).option("--cwd <path>", "The current working directory.", process.cwd()).action(async (opts) => {
1693
- const options = v6.parse(schema3, opts);
1775
+ const options = v7.parse(schema4, opts);
1694
1776
  _intro(context.package.version);
1695
1777
  await _build(options);
1696
- outro2(color8.green("All done!"));
1778
+ outro3(color9.green("All done!"));
1697
1779
  });
1698
1780
  var _build = async (options) => {
1699
1781
  const loading = spinner3();
@@ -1701,7 +1783,7 @@ var _build = async (options) => {
1701
1783
  const outFile = path7.join(options.cwd, OUTPUT_FILE);
1702
1784
  for (const dir of options.dirs) {
1703
1785
  const dirPath = path7.join(options.cwd, dir);
1704
- loading.start(`Building ${color8.cyan(dirPath)}`);
1786
+ loading.start(`Building ${color9.cyan(dirPath)}`);
1705
1787
  if (options.output && fs7.existsSync(outFile)) fs7.rmSync(outFile);
1706
1788
  const builtCategories = buildBlocksDirectory(dirPath, { ...options });
1707
1789
  for (const category of builtCategories) {
@@ -1709,20 +1791,20 @@ var _build = async (options) => {
1709
1791
  const error = "a category with the same name already exists!";
1710
1792
  if (options.errorOnWarn) {
1711
1793
  program3.error(
1712
- color8.red(
1713
- `\`${color8.bold(`${dir}/${category.name}`)}\` could not be added because ${error}`
1794
+ color9.red(
1795
+ `\`${color9.bold(`${dir}/${category.name}`)}\` could not be added because ${error}`
1714
1796
  )
1715
1797
  );
1716
1798
  } else {
1717
1799
  console.warn(
1718
- `${VERTICAL_LINE} ${WARN} Skipped adding \`${color8.cyan(`${dir}/${category.name}`)}\` because ${error}`
1800
+ `${VERTICAL_LINE} ${WARN} Skipped adding \`${color9.cyan(`${dir}/${category.name}`)}\` because ${error}`
1719
1801
  );
1720
1802
  }
1721
1803
  continue;
1722
1804
  }
1723
1805
  categories.push(category);
1724
1806
  }
1725
- loading.stop(`Built ${color8.cyan(dirPath)}`);
1807
+ loading.stop(`Built ${color9.cyan(dirPath)}`);
1726
1808
  }
1727
1809
  loading.start("Checking manifest");
1728
1810
  const warnings = [];
@@ -1734,14 +1816,14 @@ var _build = async (options) => {
1734
1816
  (cat) => cat.name.trim() === depCategoryName.trim()
1735
1817
  );
1736
1818
  const invalidDependencyError = () => {
1737
- const error = `depends on ${color8.bold(dep)} which doesn't exist!`;
1819
+ const error = `depends on ${color9.bold(dep)} which doesn't exist!`;
1738
1820
  if (options.errorOnWarn) {
1739
1821
  warnings.push(
1740
- color8.red(`${color8.bold(`${category.name}/${block.name}`)} ${error}`)
1822
+ color9.red(`${color9.bold(`${category.name}/${block.name}`)} ${error}`)
1741
1823
  );
1742
1824
  } else {
1743
1825
  warnings.push(
1744
- `${VERTICAL_LINE} ${WARN} ${color8.bold(`${category.name}/${block.name}`)} ${error}`
1826
+ `${VERTICAL_LINE} ${WARN} ${color9.bold(`${category.name}/${block.name}`)} ${error}`
1745
1827
  );
1746
1828
  }
1747
1829
  };
@@ -1755,9 +1837,9 @@ var _build = async (options) => {
1755
1837
  }
1756
1838
  for (const dep of [...block.dependencies, ...block.devDependencies]) {
1757
1839
  if (!dep.includes("@")) {
1758
- const error = `You haven't installed ${color8.bold(dep)} as a dependency so your users could get any version of it when they install your block!`;
1840
+ const error = `You haven't installed ${color9.bold(dep)} as a dependency so your users could get any version of it when they install your block!`;
1759
1841
  if (options.errorOnWarn) {
1760
- warnings.push(color8.red(error));
1842
+ warnings.push(color9.red(error));
1761
1843
  } else {
1762
1844
  warnings.push(`${VERTICAL_LINE} ${WARN} ${error}`);
1763
1845
  }
@@ -1775,23 +1857,23 @@ var _build = async (options) => {
1775
1857
  }
1776
1858
  }
1777
1859
  if (options.output) {
1778
- loading.start(`Writing output to \`${color8.cyan(outFile)}\``);
1860
+ loading.start(`Writing output to \`${color9.cyan(outFile)}\``);
1779
1861
  fs7.writeFileSync(outFile, JSON.stringify(categories, null, " "));
1780
- loading.stop(`Wrote output to \`${color8.cyan(outFile)}\``);
1862
+ loading.stop(`Wrote output to \`${color9.cyan(outFile)}\``);
1781
1863
  }
1782
1864
  };
1783
1865
 
1784
1866
  // src/commands/diff.ts
1785
1867
  import fs8 from "node:fs";
1786
- import { cancel as cancel2, confirm as confirm2, isCancel as isCancel2, outro as outro3, spinner as spinner4 } from "@clack/prompts";
1787
- import color10 from "chalk";
1788
- import { Command as Command3, program as program4 } from "commander";
1868
+ import { cancel as cancel3, confirm as confirm3, isCancel as isCancel3, outro as outro4, spinner as spinner4 } from "@clack/prompts";
1869
+ import color11 from "chalk";
1870
+ import { Command as Command4, program as program4 } from "commander";
1789
1871
  import { diffLines } from "diff";
1790
1872
  import path8 from "pathe";
1791
- import * as v7 from "valibot";
1873
+ import * as v8 from "valibot";
1792
1874
 
1793
1875
  // src/utils/diff.ts
1794
- import color9 from "chalk";
1876
+ import color10 from "chalk";
1795
1877
  import { diffChars } from "diff";
1796
1878
 
1797
1879
  // src/utils/blocks/utils/array-sum.ts
@@ -1806,7 +1888,7 @@ var arraySum = (arr, fn) => {
1806
1888
  // src/utils/blocks/utils/lines.ts
1807
1889
  import os from "node:os";
1808
1890
  var NEW_LINE_REGEX = /\n|\r\n/g;
1809
- var get = (str) => str.split(NEW_LINE_REGEX);
1891
+ var get2 = (str) => str.split(NEW_LINE_REGEX);
1810
1892
  var join = (lines, { lineNumbers = false, prefix } = {}) => {
1811
1893
  let transformed = lines;
1812
1894
  if (lineNumbers) {
@@ -1840,10 +1922,10 @@ var formatDiff = ({
1840
1922
  changes,
1841
1923
  expand = false,
1842
1924
  maxUnchanged = 5,
1843
- colorRemoved = color9.red,
1844
- colorAdded = color9.green,
1845
- colorCharsRemoved = color9.bgRed,
1846
- colorCharsAdded = color9.bgGreen,
1925
+ colorRemoved = color10.red,
1926
+ colorAdded = color10.green,
1927
+ colorCharsRemoved = color10.bgRed,
1928
+ colorCharsAdded = color10.bgGreen,
1847
1929
  prefix,
1848
1930
  onUnchanged,
1849
1931
  intro: intro2
@@ -1877,7 +1959,7 @@ var formatDiff = ({
1877
1959
  onUnchanged,
1878
1960
  intro: intro2
1879
1961
  });
1880
- const linePrefix = (line) => color9.gray(`${prefix?.() ?? ""}${leftPadMin(`${line + 1 + lineOffset} `, length)} `);
1962
+ const linePrefix = (line) => color10.gray(`${prefix?.() ?? ""}${leftPadMin(`${line + 1 + lineOffset} `, length)} `);
1881
1963
  for (let i = 0; i < changes.length; i++) {
1882
1964
  const change = changes[i];
1883
1965
  const hasPreviousChange = changes[i - 1]?.added || changes[i - 1]?.removed;
@@ -1885,7 +1967,7 @@ var formatDiff = ({
1885
1967
  if (!change.added && !change.removed) {
1886
1968
  if (!expand && change.count !== void 0 && change.count > maxUnchanged) {
1887
1969
  const prevLineOffset = lineOffset;
1888
- const ls = get(trimSingleNewLine(change.value));
1970
+ const ls = get2(trimSingleNewLine(change.value));
1889
1971
  let shownLines = 0;
1890
1972
  if (hasNextChange) shownLines += maxUnchanged;
1891
1973
  if (hasPreviousChange) shownLines += maxUnchanged;
@@ -1906,9 +1988,9 @@ var formatDiff = ({
1906
1988
  if (ls.length > shownLines) {
1907
1989
  const count = ls.length - shownLines;
1908
1990
  result += `${join(
1909
- get(
1910
- color9.gray(
1911
- `+ ${count} more unchanged (${color9.italic("-E to expand")})`
1991
+ get2(
1992
+ color10.gray(
1993
+ `+ ${count} more unchanged (${color10.italic("-E to expand")})`
1912
1994
  )
1913
1995
  ),
1914
1996
  {
@@ -1927,7 +2009,7 @@ var formatDiff = ({
1927
2009
  lineOffset = prevLineOffset + change.count;
1928
2010
  continue;
1929
2011
  }
1930
- result += `${join(get(trimSingleNewLine(change.value)), {
2012
+ result += `${join(get2(trimSingleNewLine(change.value)), {
1931
2013
  prefix: linePrefix
1932
2014
  })}
1933
2015
  `;
@@ -1960,7 +2042,7 @@ var formatDiff = ({
1960
2042
  i++;
1961
2043
  } else {
1962
2044
  if (isWhitespace(change.value)) {
1963
- result += `${join(get(colorCharChange(change)), {
2045
+ result += `${join(get2(colorCharChange(change)), {
1964
2046
  prefix: (line) => `${linePrefix(line)}${colorCharChange({ removed: true, value: " ", added: false })}`
1965
2047
  })}
1966
2048
  `;
@@ -1968,7 +2050,7 @@ var formatDiff = ({
1968
2050
  lineOffset += change.count ?? 0;
1969
2051
  }
1970
2052
  } else {
1971
- result += `${join(get(colorLineChange(change)), {
2053
+ result += `${join(get2(colorLineChange(change)), {
1972
2054
  prefix: linePrefix
1973
2055
  })}
1974
2056
  `;
@@ -1982,52 +2064,52 @@ var formatDiff = ({
1982
2064
  };
1983
2065
 
1984
2066
  // src/commands/diff.ts
1985
- var schema4 = v7.object({
1986
- expand: v7.boolean(),
1987
- maxUnchanged: v7.number(),
1988
- repo: v7.optional(v7.string()),
1989
- allow: v7.boolean(),
1990
- cwd: v7.string()
2067
+ var schema5 = v8.object({
2068
+ expand: v8.boolean(),
2069
+ maxUnchanged: v8.number(),
2070
+ repo: v8.optional(v8.string()),
2071
+ allow: v8.boolean(),
2072
+ cwd: v8.string()
1991
2073
  });
1992
- var diff = new Command3("diff").description("Compares local blocks to the blocks in the provided repository.").option("-E, --expand", "Expands the diff so you see everything.", false).option(
2074
+ var diff = new Command4("diff").description("Compares local blocks to the blocks in the provided repository.").option("-E, --expand", "Expands the diff so you see everything.", false).option(
1993
2075
  "--max-unchanged <number>",
1994
2076
  "Maximum unchanged lines that will show without being collapsed.",
1995
2077
  (val) => Number.parseInt(val),
1996
2078
  // this is such a dumb api thing
1997
2079
  3
1998
2080
  ).option("--repo <repo>", "Repository to download the blocks from.").option("-A, --allow", "Allow jsrepo to download code from the provided repo.", false).option("--cwd <path>", "The current working directory.", process.cwd()).action(async (opts) => {
1999
- const options = v7.parse(schema4, opts);
2081
+ const options = v8.parse(schema5, opts);
2000
2082
  _intro(context.package.version);
2001
2083
  await _diff(options);
2002
- outro3(color10.green("All done!"));
2084
+ outro4(color11.green("All done!"));
2003
2085
  });
2004
2086
  var _diff = async (options) => {
2005
2087
  const loading = spinner4();
2006
2088
  const config = getConfig(options.cwd).match(
2007
2089
  (val) => val,
2008
- (err) => program4.error(color10.red(err))
2090
+ (err) => program4.error(color11.red(err))
2009
2091
  );
2010
2092
  let repoPaths = config.repos;
2011
2093
  if (options.repo) repoPaths = [options.repo];
2012
2094
  if (!options.allow && options.repo) {
2013
- const result = await confirm2({
2014
- message: `Allow ${color10.cyan("jsrepo")} to download and run code from ${color10.cyan(options.repo)}?`,
2095
+ const result = await confirm3({
2096
+ message: `Allow ${color11.cyan("jsrepo")} to download and run code from ${color11.cyan(options.repo)}?`,
2015
2097
  initialValue: true
2016
2098
  });
2017
- if (isCancel2(result) || !result) {
2018
- cancel2("Canceled!");
2099
+ if (isCancel3(result) || !result) {
2100
+ cancel3("Canceled!");
2019
2101
  process.exit(0);
2020
2102
  }
2021
2103
  }
2022
- loading.start(`Fetching blocks from ${color10.cyan(repoPaths.join(", "))}`);
2104
+ loading.start(`Fetching blocks from ${color11.cyan(repoPaths.join(", "))}`);
2023
2105
  const blocksMap = (await fetchBlocks(...repoPaths)).match(
2024
2106
  (val) => val,
2025
2107
  ({ repo, message }) => {
2026
- loading.stop(`Failed fetching blocks from ${color10.cyan(repo)}`);
2027
- program4.error(color10.red(message));
2108
+ loading.stop(`Failed fetching blocks from ${color11.cyan(repo)}`);
2109
+ program4.error(color11.red(message));
2028
2110
  }
2029
2111
  );
2030
- loading.stop(`Retrieved blocks from ${color10.cyan(repoPaths.join(", "))}`);
2112
+ loading.stop(`Retrieved blocks from ${color11.cyan(repoPaths.join(", "))}`);
2031
2113
  const installedBlocks = getInstalled(blocksMap, config, options.cwd);
2032
2114
  for (const blockSpecifier of installedBlocks) {
2033
2115
  let found = false;
@@ -2047,12 +2129,11 @@ var _diff = async (options) => {
2047
2129
  process.stdout.write(`${VERTICAL_LINE}
2048
2130
  `);
2049
2131
  const sourcePath = path8.join(block.directory, file);
2050
- const rawUrl = await providerInfo.provider.resolveRaw(providerInfo, sourcePath);
2051
- const response = await fetch(rawUrl);
2052
- if (!response.ok) {
2053
- program4.error(color10.red(`There was an error trying to get ${fullSpecifier}`));
2132
+ const response = await providerInfo.provider.fetchRaw(providerInfo, sourcePath);
2133
+ if (response.isErr()) {
2134
+ program4.error(color11.red(`There was an error trying to get ${fullSpecifier}`));
2054
2135
  }
2055
- let remoteContent = await response.text();
2136
+ let remoteContent = response.unwrap();
2056
2137
  const directory = path8.join(options.cwd, config.path, block.category);
2057
2138
  let localPath = path8.join(directory, file);
2058
2139
  let prettyLocalPath = path8.join(config.path, block.category, file);
@@ -2084,16 +2165,16 @@ ${remoteContent}`;
2084
2165
  changes,
2085
2166
  expand: options.expand,
2086
2167
  maxUnchanged: options.maxUnchanged,
2087
- colorAdded: color10.greenBright,
2088
- colorRemoved: color10.redBright,
2089
- colorCharsAdded: color10.bgGreenBright,
2090
- colorCharsRemoved: color10.bgRedBright,
2168
+ colorAdded: color11.greenBright,
2169
+ colorRemoved: color11.redBright,
2170
+ colorCharsAdded: color11.bgGreenBright,
2171
+ colorCharsRemoved: color11.bgRedBright,
2091
2172
  prefix: () => `${VERTICAL_LINE} `,
2092
- onUnchanged: ({ from: from2, to, prefix }) => `${prefix?.() ?? ""}${color10.cyan(from2)} \u2192 ${color10.gray(to)} ${color10.gray("(unchanged)")}
2173
+ onUnchanged: ({ from: from2, to, prefix }) => `${prefix?.() ?? ""}${color11.cyan(from2)} \u2192 ${color11.gray(to)} ${color11.gray("(unchanged)")}
2093
2174
  `,
2094
2175
  intro: ({ from: from2, to, changes: changes2, prefix }) => {
2095
2176
  const totalChanges = changes2.filter((a) => a.added).length;
2096
- return `${prefix?.() ?? ""}${color10.cyan(from2)} \u2192 ${color10.gray(to)} (${totalChanges} change${totalChanges === 1 ? "" : "s"})
2177
+ return `${prefix?.() ?? ""}${color11.cyan(from2)} \u2192 ${color11.gray(to)} (${totalChanges} change${totalChanges === 1 ? "" : "s"})
2097
2178
  ${prefix?.() ?? ""}
2098
2179
  `;
2099
2180
  }
@@ -2104,7 +2185,7 @@ ${prefix?.() ?? ""}
2104
2185
  }
2105
2186
  if (!found) {
2106
2187
  program4.error(
2107
- color10.red(`Invalid block! ${color10.bold(blockSpecifier)} does not exist!`)
2188
+ color11.red(`Invalid block! ${color11.bold(blockSpecifier)} does not exist!`)
2108
2189
  );
2109
2190
  }
2110
2191
  }
@@ -2112,38 +2193,38 @@ ${prefix?.() ?? ""}
2112
2193
 
2113
2194
  // src/commands/init.ts
2114
2195
  import fs9 from "node:fs";
2115
- import { cancel as cancel3, confirm as confirm3, isCancel as isCancel3, outro as outro4, select, spinner as spinner5, text } from "@clack/prompts";
2116
- import color11 from "chalk";
2117
- import { Command as Command4, program as program5 } from "commander";
2196
+ import { cancel as cancel4, confirm as confirm4, isCancel as isCancel4, outro as outro5, password as password2, select as select2, spinner as spinner5, text } from "@clack/prompts";
2197
+ import color12 from "chalk";
2198
+ import { Command as Command5, program as program5 } from "commander";
2118
2199
  import { detect as detect2, resolveCommand as resolveCommand3 } from "package-manager-detector";
2119
2200
  import path9 from "pathe";
2120
- import * as v8 from "valibot";
2121
- var schema5 = v8.object({
2122
- path: v8.optional(v8.string()),
2123
- repos: v8.optional(v8.array(v8.string())),
2124
- watermark: v8.boolean(),
2125
- tests: v8.optional(v8.boolean()),
2126
- project: v8.optional(v8.boolean()),
2127
- registry: v8.optional(v8.boolean()),
2128
- script: v8.string(),
2129
- yes: v8.boolean(),
2130
- cwd: v8.string()
2201
+ import * as v9 from "valibot";
2202
+ var schema6 = v9.object({
2203
+ path: v9.optional(v9.string()),
2204
+ repos: v9.optional(v9.array(v9.string())),
2205
+ watermark: v9.boolean(),
2206
+ tests: v9.optional(v9.boolean()),
2207
+ project: v9.optional(v9.boolean()),
2208
+ registry: v9.optional(v9.boolean()),
2209
+ script: v9.string(),
2210
+ yes: v9.boolean(),
2211
+ cwd: v9.string()
2131
2212
  });
2132
- var init = new Command4("init").description("Initializes your project with a configuration file.").option("--path <path>", "Path to install the blocks / Path to build the blocks from.").option("--repos [repos...]", "Repository to install the blocks from.").option(
2213
+ var init = new Command5("init").description("Initializes your project with a configuration file.").option("--path <path>", "Path to install the blocks / Path to build the blocks from.").option("--repos [repos...]", "Repository to install the blocks from.").option(
2133
2214
  "--no-watermark",
2134
2215
  "Will not add a watermark to each file upon adding it to your project."
2135
2216
  ).option("--tests", "Will include tests with the blocks.").option("-P, --project", "Takes you through the steps to initialize a project.").option("-R, --registry", "Takes you through the steps to initialize a registry.").option("--script <name>", "The name of the build script. (For Registry setup)", "build").option("-y, --yes", "Skip confirmation prompt.", false).option("--cwd <path>", "The current working directory.", process.cwd()).action(async (opts) => {
2136
- const options = v8.parse(schema5, opts);
2217
+ const options = v9.parse(schema6, opts);
2137
2218
  _intro(context.package.version);
2138
2219
  if (options.registry !== void 0 && options.project !== void 0) {
2139
2220
  program5.error(
2140
- color11.red(
2141
- `You cannot provide both ${color11.bold("--project")} and ${color11.bold("--registry")} at the same time.`
2221
+ color12.red(
2222
+ `You cannot provide both ${color12.bold("--project")} and ${color12.bold("--registry")} at the same time.`
2142
2223
  )
2143
2224
  );
2144
2225
  }
2145
2226
  if (options.registry === void 0 && options.project === void 0) {
2146
- const response = await select({
2227
+ const response = await select2({
2147
2228
  message: "Initialize a project or registry?",
2148
2229
  options: [
2149
2230
  { value: "project", label: "project" },
@@ -2151,8 +2232,8 @@ var init = new Command4("init").description("Initializes your project with a con
2151
2232
  ],
2152
2233
  initialValue: "project"
2153
2234
  });
2154
- if (isCancel3(response)) {
2155
- cancel3("Canceled!");
2235
+ if (isCancel4(response)) {
2236
+ cancel4("Canceled!");
2156
2237
  process.exit(0);
2157
2238
  }
2158
2239
  options.registry = response === "registry";
@@ -2162,9 +2243,10 @@ var init = new Command4("init").description("Initializes your project with a con
2162
2243
  } else {
2163
2244
  await _initProject(options);
2164
2245
  }
2165
- outro4(color11.green("All done!"));
2246
+ outro5(color12.green("All done!"));
2166
2247
  });
2167
2248
  var _initProject = async (options) => {
2249
+ const storage = get();
2168
2250
  const initialConfig = getConfig(options.cwd);
2169
2251
  const loading = spinner5();
2170
2252
  if (!options.path) {
@@ -2175,8 +2257,8 @@ var _initProject = async (options) => {
2175
2257
  },
2176
2258
  initialValue: initialConfig.isOk() ? initialConfig.unwrap().path : "src/blocks"
2177
2259
  });
2178
- if (isCancel3(result)) {
2179
- cancel3("Canceled!");
2260
+ if (isCancel4(result)) {
2261
+ cancel4("Canceled!");
2180
2262
  process.exit(0);
2181
2263
  }
2182
2264
  options.path = result;
@@ -2184,13 +2266,13 @@ var _initProject = async (options) => {
2184
2266
  if (!options.repos) {
2185
2267
  options.repos = initialConfig.isOk() ? initialConfig.unwrap().repos : [];
2186
2268
  while (true) {
2187
- const confirmResult = await confirm3({
2269
+ const confirmResult = await confirm4({
2188
2270
  message: `Add ${options.repos.length > 0 ? "another" : "a"} repo?`,
2189
2271
  initialValue: options.repos.length === 0
2190
2272
  // default to yes for first repo
2191
2273
  });
2192
- if (isCancel3(confirmResult)) {
2193
- cancel3("Canceled!");
2274
+ if (isCancel4(confirmResult)) {
2275
+ cancel4("Canceled!");
2194
2276
  process.exit(0);
2195
2277
  }
2196
2278
  if (!confirmResult) break;
@@ -2198,15 +2280,45 @@ var _initProject = async (options) => {
2198
2280
  message: "Where should we download the blocks from?",
2199
2281
  placeholder: "github/ieedan/std",
2200
2282
  validate: (val) => {
2201
- if (!val.startsWith("https://github.com") && !val.startsWith("github/")) {
2202
- return `Must be a ${color11.bold("GitHub")} repository!`;
2283
+ if (val.trim().length === 0) return "Please provide a value";
2284
+ if (!providers.find((provider2) => provider2.matches(val))) {
2285
+ return `Invalid provider! Valid providers (${providers.map((provider2) => provider2.name()).join(", ")})`;
2203
2286
  }
2204
2287
  }
2205
2288
  });
2206
- if (isCancel3(result)) {
2207
- cancel3("Canceled!");
2289
+ if (isCancel4(result)) {
2290
+ cancel4("Canceled!");
2208
2291
  process.exit(0);
2209
2292
  }
2293
+ const provider = providers.find((p) => p.matches(result));
2294
+ if (!provider) {
2295
+ program5.error(color12.red("Invalid provider!"));
2296
+ }
2297
+ const tokenKey = `${provider.name()}-token`;
2298
+ const token = storage.get(tokenKey);
2299
+ if (!token) {
2300
+ const result2 = await confirm4({
2301
+ message: "Would you like to add an auth token?",
2302
+ initialValue: false
2303
+ });
2304
+ if (isCancel4(result2)) {
2305
+ cancel4("Canceled!");
2306
+ process.exit(0);
2307
+ }
2308
+ if (result2) {
2309
+ const response = await password2({
2310
+ message: "Paste your token",
2311
+ validate(value) {
2312
+ if (value.trim() === "") return "Please provide a value";
2313
+ }
2314
+ });
2315
+ if (isCancel4(response)) {
2316
+ cancel4("Canceled!");
2317
+ process.exit(0);
2318
+ }
2319
+ storage.set(tokenKey, response);
2320
+ }
2321
+ }
2210
2322
  options.repos.push(result);
2211
2323
  }
2212
2324
  }
@@ -2235,25 +2347,25 @@ var _initRegistry = async (options) => {
2235
2347
  initialValue: "./blocks",
2236
2348
  placeholder: "./blocks"
2237
2349
  });
2238
- if (isCancel3(response)) {
2239
- cancel3("Canceled!");
2350
+ if (isCancel4(response)) {
2351
+ cancel4("Canceled!");
2240
2352
  process.exit(0);
2241
2353
  }
2242
2354
  options.path = response;
2243
2355
  }
2244
2356
  const packagePath = path9.join(options.cwd, "package.json");
2245
2357
  if (!fs9.existsSync(packagePath)) {
2246
- program5.error(color11.red(`Couldn't find your ${color11.bold("package.json")}!`));
2358
+ program5.error(color12.red(`Couldn't find your ${color12.bold("package.json")}!`));
2247
2359
  }
2248
2360
  const pkg = JSON.parse(fs9.readFileSync(packagePath).toString());
2249
2361
  const scriptAlreadyExists = pkg.scripts !== void 0 && pkg.scripts[options.script] !== void 0;
2250
2362
  if (!options.yes && scriptAlreadyExists) {
2251
- const response = await confirm3({
2252
- message: `The \`${color11.cyan(options.script)}\` already exists overwrite?`,
2363
+ const response = await confirm4({
2364
+ message: `The \`${color12.cyan(options.script)}\` already exists overwrite?`,
2253
2365
  initialValue: false
2254
2366
  });
2255
- if (isCancel3(response)) {
2256
- cancel3("Canceled!");
2367
+ if (isCancel4(response)) {
2368
+ cancel4("Canceled!");
2257
2369
  process.exit(0);
2258
2370
  }
2259
2371
  if (!response) {
@@ -2266,8 +2378,8 @@ var _initRegistry = async (options) => {
2266
2378
  if (val.trim().length === 0) return "Please provide a value!";
2267
2379
  }
2268
2380
  });
2269
- if (isCancel3(response2)) {
2270
- cancel3("Canceled!");
2381
+ if (isCancel4(response2)) {
2382
+ cancel4("Canceled!");
2271
2383
  process.exit(0);
2272
2384
  }
2273
2385
  options.script = response2;
@@ -2276,12 +2388,12 @@ var _initRegistry = async (options) => {
2276
2388
  const alreadyInstalled = pkg.devDependencies && pkg.devDependencies.jsrepo !== void 0;
2277
2389
  let installAsDevDependency = options.yes || alreadyInstalled;
2278
2390
  if (!options.yes && !alreadyInstalled) {
2279
- const response = await confirm3({
2391
+ const response = await confirm4({
2280
2392
  message: `Add ${JSREPO} as a dev dependency?`,
2281
2393
  initialValue: true
2282
2394
  });
2283
- if (isCancel3(response)) {
2284
- cancel3("Canceled!");
2395
+ if (isCancel4(response)) {
2396
+ cancel4("Canceled!");
2285
2397
  process.exit(0);
2286
2398
  }
2287
2399
  installAsDevDependency = response;
@@ -2292,7 +2404,7 @@ var _initRegistry = async (options) => {
2292
2404
  buildScript += "jsrepo build ";
2293
2405
  } else {
2294
2406
  const command = resolveCommand3(pm, "execute", ["jsrepo", "build"]);
2295
- if (!command) program5.error(color11.red(`Error resolving execute command for ${pm}`));
2407
+ if (!command) program5.error(color12.red(`Error resolving execute command for ${pm}`));
2296
2408
  buildScript += `${command.command} ${command.args.join(" ")} `;
2297
2409
  }
2298
2410
  if (options.path !== "./build") {
@@ -2302,23 +2414,23 @@ var _initRegistry = async (options) => {
2302
2414
  pkg.scripts = {};
2303
2415
  }
2304
2416
  pkg.scripts[options.script] = buildScript;
2305
- loading.start(`Adding \`${color11.cyan(options.script)}\` to scripts in package.json`);
2417
+ loading.start(`Adding \`${color12.cyan(options.script)}\` to scripts in package.json`);
2306
2418
  try {
2307
2419
  fs9.writeFileSync(packagePath, JSON.stringify(pkg, null, " "));
2308
2420
  } catch (err) {
2309
- program5.error(color11.red(`Error writing to \`${color11.bold(packagePath)}\`. Error: ${err}`));
2421
+ program5.error(color12.red(`Error writing to \`${color12.bold(packagePath)}\`. Error: ${err}`));
2310
2422
  }
2311
- loading.stop(`Added \`${color11.cyan(options.script)}\` to scripts in package.json`);
2423
+ loading.stop(`Added \`${color12.cyan(options.script)}\` to scripts in package.json`);
2312
2424
  let installed = alreadyInstalled;
2313
2425
  if (installAsDevDependency && !alreadyInstalled) {
2314
2426
  let shouldInstall = options.yes;
2315
2427
  if (!options.yes) {
2316
- const response = await confirm3({
2428
+ const response = await confirm4({
2317
2429
  message: "Install dependencies?",
2318
2430
  initialValue: true
2319
2431
  });
2320
- if (isCancel3(response)) {
2321
- cancel3("Canceled!");
2432
+ if (isCancel4(response)) {
2433
+ cancel4("Canceled!");
2322
2434
  process.exit(0);
2323
2435
  }
2324
2436
  shouldInstall = response;
@@ -2345,13 +2457,13 @@ var _initRegistry = async (options) => {
2345
2457
  if (!installed && installAsDevDependency) {
2346
2458
  const cmd = resolveCommand3(pm, "install", ["jsrepo", "-D"]);
2347
2459
  steps.push(
2348
- `Install ${JSREPO} as a dev dependency \`${color11.cyan(`${cmd?.command} ${cmd?.args.join(" ")}`)}\``
2460
+ `Install ${JSREPO} as a dev dependency \`${color12.cyan(`${cmd?.command} ${cmd?.args.join(" ")}`)}\``
2349
2461
  );
2350
2462
  }
2351
- steps.push(`Add blocks to \`${color11.cyan(options.path)}\`.`);
2463
+ steps.push(`Add blocks to \`${color12.cyan(options.path)}\`.`);
2352
2464
  const runScript = resolveCommand3(pm, "run", [options.script]);
2353
2465
  steps.push(
2354
- `Run \`${color11.cyan(`${runScript?.command} ${runScript?.args.join(" ")}`)}\` to build the registry.`
2466
+ `Run \`${color12.cyan(`${runScript?.command} ${runScript?.args.join(" ")}`)}\` to build the registry.`
2355
2467
  );
2356
2468
  steps = steps.map((step, i) => `${i + 1}. ${step}`);
2357
2469
  const next = nextSteps(steps);
@@ -2360,27 +2472,27 @@ var _initRegistry = async (options) => {
2360
2472
 
2361
2473
  // src/commands/test.ts
2362
2474
  import fs10 from "node:fs";
2363
- import { cancel as cancel4, confirm as confirm4, isCancel as isCancel4, outro as outro5, spinner as spinner6 } from "@clack/prompts";
2364
- import color12 from "chalk";
2365
- import { Argument, Command as Command5, program as program6 } from "commander";
2475
+ import { cancel as cancel5, confirm as confirm5, isCancel as isCancel5, outro as outro6, spinner as spinner6 } from "@clack/prompts";
2476
+ import color13 from "chalk";
2477
+ import { Argument, Command as Command6, program as program6 } from "commander";
2366
2478
  import { execa as execa2 } from "execa";
2367
2479
  import { resolveCommand as resolveCommand4 } from "package-manager-detector/commands";
2368
2480
  import { detect as detect3 } from "package-manager-detector/detect";
2369
2481
  import path10 from "pathe";
2370
2482
  import { Project as Project2 } from "ts-morph";
2371
- import * as v9 from "valibot";
2372
- var schema6 = v9.object({
2373
- repo: v9.optional(v9.string()),
2374
- allow: v9.boolean(),
2375
- debug: v9.boolean(),
2376
- verbose: v9.boolean(),
2377
- cwd: v9.string()
2483
+ import * as v10 from "valibot";
2484
+ var schema7 = v10.object({
2485
+ repo: v10.optional(v10.string()),
2486
+ allow: v10.boolean(),
2487
+ debug: v10.boolean(),
2488
+ verbose: v10.boolean(),
2489
+ cwd: v10.string()
2378
2490
  });
2379
- var test = new Command5("test").description("Tests local blocks against most recent remote tests.").addArgument(new Argument("[blocks...]", "The blocks you want to test.").default([])).option("--repo <repo>", "Repository to download the blocks from.").option("-A, --allow", "Allow jsrepo to download code from the provided repo.", false).option("--debug", "Leaves the temp test file around for debugging upon failure.", false).option("--verbose", "Include debug logs.", false).option("--cwd <path>", "The current working directory.", process.cwd()).action(async (blockNames, opts) => {
2380
- const options = v9.parse(schema6, opts);
2491
+ var test = new Command6("test").description("Tests local blocks against most recent remote tests.").addArgument(new Argument("[blocks...]", "The blocks you want to test.").default([])).option("--repo <repo>", "Repository to download the blocks from.").option("-A, --allow", "Allow jsrepo to download code from the provided repo.", false).option("--debug", "Leaves the temp test file around for debugging upon failure.", false).option("--verbose", "Include debug logs.", false).option("--cwd <path>", "The current working directory.", process.cwd()).action(async (blockNames, opts) => {
2492
+ const options = v10.parse(schema7, opts);
2381
2493
  _intro(context.package.version);
2382
2494
  await _test(blockNames, options);
2383
- outro5(color12.green("All done!"));
2495
+ outro6(color13.green("All done!"));
2384
2496
  });
2385
2497
  var _test = async (blockNames, options) => {
2386
2498
  const verbose = (msg) => {
@@ -2391,43 +2503,42 @@ var _test = async (blockNames, options) => {
2391
2503
  verbose(`Attempting to test ${JSON.stringify(blockNames)}`);
2392
2504
  const config = getConfig(options.cwd).match(
2393
2505
  (val) => val,
2394
- (err) => program6.error(color12.red(err))
2506
+ (err) => program6.error(color13.red(err))
2395
2507
  );
2396
2508
  const loading = spinner6();
2397
2509
  const blocksMap = /* @__PURE__ */ new Map();
2398
2510
  let repoPaths = config.repos;
2399
2511
  if (options.repo) repoPaths = [options.repo];
2400
2512
  if (!options.allow && options.repo) {
2401
- const result = await confirm4({
2402
- message: `Allow ${color12.cyan("jsrepo")} to download and run code from ${color12.cyan(options.repo)}?`,
2513
+ const result = await confirm5({
2514
+ message: `Allow ${color13.cyan("jsrepo")} to download and run code from ${color13.cyan(options.repo)}?`,
2403
2515
  initialValue: true
2404
2516
  });
2405
- if (isCancel4(result) || !result) {
2406
- cancel4("Canceled!");
2517
+ if (isCancel5(result) || !result) {
2518
+ cancel5("Canceled!");
2407
2519
  process.exit(0);
2408
2520
  }
2409
2521
  }
2410
- verbose(`Fetching blocks from ${color12.cyan(repoPaths.join(", "))}`);
2411
- if (!options.verbose) loading.start(`Fetching blocks from ${color12.cyan(repoPaths.join(", "))}`);
2522
+ verbose(`Fetching blocks from ${color13.cyan(repoPaths.join(", "))}`);
2523
+ if (!options.verbose) loading.start(`Fetching blocks from ${color13.cyan(repoPaths.join(", "))}`);
2412
2524
  for (const repo of repoPaths) {
2413
2525
  const providerInfo = (await getProviderInfo(repo)).match(
2414
2526
  (info) => info,
2415
- (err) => program6.error(color12.red(err))
2527
+ (err) => program6.error(color13.red(err))
2416
2528
  );
2417
- const manifestUrl = await providerInfo.provider.resolveRaw(providerInfo, OUTPUT_FILE);
2418
- verbose(`Got info for provider ${color12.cyan(providerInfo.name)}`);
2419
- const response = await fetch(manifestUrl);
2420
- if (!response.ok) {
2421
- if (!options.verbose) loading.stop(`Error fetching ${color12.cyan(manifestUrl.href)}`);
2529
+ const manifest = await providerInfo.provider.fetchManifest(providerInfo);
2530
+ verbose(`Got info for provider ${color13.cyan(providerInfo.name)}`);
2531
+ if (manifest.isErr()) {
2532
+ if (!options.verbose) loading.stop(`Error fetching ${color13.cyan(repo)}`);
2422
2533
  program6.error(
2423
- color12.red(
2424
- `There was an error fetching the \`${OUTPUT_FILE}\` from the repository ${color12.cyan(
2534
+ color13.red(
2535
+ `There was an error fetching the \`${OUTPUT_FILE}\` from the repository ${color13.cyan(
2425
2536
  repo
2426
2537
  )} make sure the target repository has a \`${OUTPUT_FILE}\` in its root?`
2427
2538
  )
2428
2539
  );
2429
2540
  }
2430
- const categories = v9.parse(v9.array(categorySchema), await response.json());
2541
+ const categories = manifest.unwrap();
2431
2542
  for (const category of categories) {
2432
2543
  for (const block of category.blocks) {
2433
2544
  blocksMap.set(
@@ -2440,12 +2551,12 @@ var _test = async (blockNames, options) => {
2440
2551
  }
2441
2552
  }
2442
2553
  }
2443
- verbose(`Retrieved blocks from ${color12.cyan(repoPaths.join(", "))}`);
2444
- if (!options.verbose) loading.stop(`Retrieved blocks from ${color12.cyan(repoPaths.join(", "))}`);
2554
+ verbose(`Retrieved blocks from ${color13.cyan(repoPaths.join(", "))}`);
2555
+ if (!options.verbose) loading.stop(`Retrieved blocks from ${color13.cyan(repoPaths.join(", "))}`);
2445
2556
  const tempTestDirectory = path10.resolve(
2446
2557
  path10.join(options.cwd, `blocks-tests-temp-${Date.now()}`)
2447
2558
  );
2448
- verbose(`Trying to create the temp directory ${color12.bold(tempTestDirectory)}.`);
2559
+ verbose(`Trying to create the temp directory ${color13.bold(tempTestDirectory)}.`);
2449
2560
  fs10.mkdirSync(tempTestDirectory, { recursive: true });
2450
2561
  const cleanUp = () => {
2451
2562
  fs10.rmSync(tempTestDirectory, { recursive: true, force: true });
@@ -2459,7 +2570,7 @@ var _test = async (blockNames, options) => {
2459
2570
  }
2460
2571
  if (testingBlocks.length === 0) {
2461
2572
  cleanUp();
2462
- program6.error(color12.red("There were no blocks found in your project!"));
2573
+ program6.error(color13.red("There were no blocks found in your project!"));
2463
2574
  }
2464
2575
  const testingBlocksMapped = [];
2465
2576
  for (const blockSpecifier of testingBlocks) {
@@ -2485,15 +2596,11 @@ var _test = async (blockNames, options) => {
2485
2596
  }
2486
2597
  const providerInfo = (await getProviderInfo(repo)).match(
2487
2598
  (val) => val,
2488
- (err) => program6.error(color12.red(err))
2489
- );
2490
- const manifestUrl = await providerInfo.provider.resolveRaw(
2491
- providerInfo,
2492
- OUTPUT_FILE
2599
+ (err) => program6.error(color13.red(err))
2493
2600
  );
2494
- const categories = (await getManifest(manifestUrl)).match(
2601
+ const categories = (await providerInfo.provider.fetchManifest(providerInfo)).match(
2495
2602
  (val) => val,
2496
- (err) => program6.error(color12.red(err))
2603
+ (err) => program6.error(color13.red(err))
2497
2604
  );
2498
2605
  for (const category of categories) {
2499
2606
  for (const block2 of category.blocks) {
@@ -2511,30 +2618,30 @@ var _test = async (blockNames, options) => {
2511
2618
  }
2512
2619
  if (!block) {
2513
2620
  program6.error(
2514
- color12.red(`Invalid block! ${color12.bold(blockSpecifier)} does not exist!`)
2621
+ color13.red(`Invalid block! ${color13.bold(blockSpecifier)} does not exist!`)
2515
2622
  );
2516
2623
  }
2517
2624
  testingBlocksMapped.push({ name: blockSpecifier, block });
2518
2625
  }
2519
- for (const { name: specifier, block } of testingBlocksMapped) {
2626
+ for (const { block } of testingBlocksMapped) {
2520
2627
  const providerInfo = block.sourceRepo;
2628
+ const fullSpecifier = `${block.sourceRepo.url}/${block.category}/${block.name}`;
2521
2629
  if (!options.verbose) {
2522
- loading.start(`Setting up test file for ${color12.cyan(specifier)}`);
2630
+ loading.start(`Setting up test file for ${color13.cyan(fullSpecifier)}`);
2523
2631
  }
2524
2632
  if (!block.tests) {
2525
- loading.stop(`No tests found for ${color12.cyan(specifier)}`);
2633
+ loading.stop(`No tests found for ${color13.cyan(fullSpecifier)}`);
2526
2634
  continue;
2527
2635
  }
2528
2636
  const getSourceFile = async (filePath) => {
2529
- const rawUrl = await providerInfo.provider.resolveRaw(providerInfo, filePath);
2530
- const response = await fetch(rawUrl);
2531
- if (!response.ok) {
2532
- loading.stop(color12.red(`Error fetching ${color12.bold(rawUrl.href)}`));
2533
- program6.error(color12.red(`There was an error trying to get ${specifier}`));
2637
+ const content = await providerInfo.provider.fetchRaw(providerInfo, filePath);
2638
+ if (content.isErr()) {
2639
+ loading.stop(color13.red(`Error fetching ${color13.bold(filePath)}`));
2640
+ program6.error(color13.red(`There was an error trying to get ${fullSpecifier}`));
2534
2641
  }
2535
- return await response.text();
2642
+ return content.unwrap();
2536
2643
  };
2537
- verbose(`Downloading and copying test files for ${specifier}`);
2644
+ verbose(`Downloading and copying test files for ${fullSpecifier}`);
2538
2645
  const testFiles = [];
2539
2646
  for (const testFile of block.files.filter((file) => isTestFile(file))) {
2540
2647
  const content = await getSourceFile(path10.join(block.directory, testFile));
@@ -2573,19 +2680,19 @@ var _test = async (blockNames, options) => {
2573
2680
  }
2574
2681
  }
2575
2682
  project.saveSync();
2576
- verbose(`Completed ${color12.cyan.bold(specifier)} test file`);
2683
+ verbose(`Completed ${color13.cyan.bold(fullSpecifier)} test file`);
2577
2684
  if (!options.verbose) {
2578
- loading.stop(`Completed setup for ${color12.bold(specifier)}`);
2685
+ loading.stop(`Completed setup for ${color13.bold(fullSpecifier)}`);
2579
2686
  }
2580
2687
  }
2581
2688
  verbose("Beginning testing");
2582
2689
  const pm = await detect3({ cwd: options.cwd });
2583
2690
  if (pm == null) {
2584
- program6.error(color12.red("Could not detect package manager"));
2691
+ program6.error(color13.red("Could not detect package manager"));
2585
2692
  }
2586
2693
  const resolved = resolveCommand4(pm.agent, "execute", ["vitest", "run", tempTestDirectory]);
2587
2694
  if (resolved == null) {
2588
- program6.error(color12.red(`Could not resolve add command for '${pm.agent}'.`));
2695
+ program6.error(color13.red(`Could not resolve add command for '${pm.agent}'.`));
2589
2696
  }
2590
2697
  const { command, args } = resolved;
2591
2698
  const testCommand = `${command} ${args.join(" ")}`;
@@ -2602,7 +2709,7 @@ var _test = async (blockNames, options) => {
2602
2709
  } catch (err) {
2603
2710
  if (options.debug) {
2604
2711
  console.info(
2605
- `${color12.bold("--debug")} flag provided. Skipping cleanup. Run '${color12.bold(
2712
+ `${color13.bold("--debug")} flag provided. Skipping cleanup. Run '${color13.bold(
2606
2713
  testCommand
2607
2714
  )}' to retry tests.
2608
2715
  `
@@ -2610,41 +2717,41 @@ var _test = async (blockNames, options) => {
2610
2717
  } else {
2611
2718
  cleanUp();
2612
2719
  }
2613
- program6.error(color12.red(`Tests failed! Error ${err}`));
2720
+ program6.error(color13.red(`Tests failed! Error ${err}`));
2614
2721
  }
2615
2722
  };
2616
2723
 
2617
2724
  // src/commands/update.ts
2618
2725
  import fs11 from "node:fs";
2619
- import { cancel as cancel5, confirm as confirm5, isCancel as isCancel5, multiselect as multiselect2, outro as outro6, spinner as spinner7 } from "@clack/prompts";
2620
- import color13 from "chalk";
2621
- import { Command as Command6, program as program7 } from "commander";
2726
+ import { cancel as cancel6, confirm as confirm6, isCancel as isCancel6, multiselect as multiselect2, outro as outro7, spinner as spinner7 } from "@clack/prompts";
2727
+ import color14 from "chalk";
2728
+ import { Command as Command7, program as program7 } from "commander";
2622
2729
  import { diffLines as diffLines2 } from "diff";
2623
2730
  import { resolveCommand as resolveCommand5 } from "package-manager-detector/commands";
2624
2731
  import { detect as detect4 } from "package-manager-detector/detect";
2625
2732
  import path11 from "pathe";
2626
- import * as v10 from "valibot";
2627
- var schema7 = v10.object({
2628
- all: v10.boolean(),
2629
- expand: v10.boolean(),
2630
- maxUnchanged: v10.number(),
2631
- repo: v10.optional(v10.string()),
2632
- allow: v10.boolean(),
2633
- yes: v10.boolean(),
2634
- verbose: v10.boolean(),
2635
- cwd: v10.string()
2733
+ import * as v11 from "valibot";
2734
+ var schema8 = v11.object({
2735
+ all: v11.boolean(),
2736
+ expand: v11.boolean(),
2737
+ maxUnchanged: v11.number(),
2738
+ repo: v11.optional(v11.string()),
2739
+ allow: v11.boolean(),
2740
+ yes: v11.boolean(),
2741
+ verbose: v11.boolean(),
2742
+ cwd: v11.string()
2636
2743
  });
2637
- var update = new Command6("update").argument("[blocks...]", "Names of the blocks you want to update. ex: (utils/math)").option("--all", "Update all installed components.", false).option("-E, --expand", "Expands the diff so you see everything.", false).option(
2744
+ var update = new Command7("update").argument("[blocks...]", "Names of the blocks you want to update. ex: (utils/math)").option("--all", "Update all installed components.", false).option("-E, --expand", "Expands the diff so you see everything.", false).option(
2638
2745
  "--max-unchanged <number>",
2639
2746
  "Maximum unchanged lines that will show without being collapsed.",
2640
2747
  (val) => Number.parseInt(val),
2641
2748
  // this is such a dumb api thing
2642
2749
  3
2643
2750
  ).option("--repo <repo>", "Repository to download the blocks from.").option("-A, --allow", "Allow jsrepo to download code from the provided repo.", false).option("-y, --yes", "Skip confirmation prompt.", false).option("--verbose", "Include debug logs.", false).option("--cwd <path>", "The current working directory.", process.cwd()).action(async (blockNames, opts) => {
2644
- const options = v10.parse(schema7, opts);
2751
+ const options = v11.parse(schema8, opts);
2645
2752
  _intro(context.package.version);
2646
2753
  await _update(blockNames, options);
2647
- outro6(color13.green("All done!"));
2754
+ outro7(color14.green("All done!"));
2648
2755
  });
2649
2756
  var _update = async (blockNames, options) => {
2650
2757
  const verbose = (msg) => {
@@ -2656,40 +2763,40 @@ var _update = async (blockNames, options) => {
2656
2763
  const loading = spinner7();
2657
2764
  const config = getConfig(options.cwd).match(
2658
2765
  (val) => val,
2659
- (err) => program7.error(color13.red(err))
2766
+ (err) => program7.error(color14.red(err))
2660
2767
  );
2661
2768
  let repoPaths = config.repos;
2662
2769
  if (options.repo) repoPaths = [options.repo];
2663
2770
  for (const blockSpecifier of blockNames) {
2664
2771
  if (blockSpecifier.startsWith("github")) {
2665
2772
  program7.error(
2666
- color13.red(
2667
- `Invalid value provided for block names \`${color13.bold(blockSpecifier)}\`. Block names are expected to be provided in the format of \`${color13.bold("<category>/<name>")}\``
2773
+ color14.red(
2774
+ `Invalid value provided for block names \`${color14.bold(blockSpecifier)}\`. Block names are expected to be provided in the format of \`${color14.bold("<category>/<name>")}\``
2668
2775
  )
2669
2776
  );
2670
2777
  }
2671
2778
  }
2672
2779
  if (!options.allow && options.repo) {
2673
- const result = await confirm5({
2674
- message: `Allow ${color13.cyan("jsrepo")} to download and run code from ${color13.cyan(options.repo)}?`,
2780
+ const result = await confirm6({
2781
+ message: `Allow ${color14.cyan("jsrepo")} to download and run code from ${color14.cyan(options.repo)}?`,
2675
2782
  initialValue: true
2676
2783
  });
2677
- if (isCancel5(result) || !result) {
2678
- cancel5("Canceled!");
2784
+ if (isCancel6(result) || !result) {
2785
+ cancel6("Canceled!");
2679
2786
  process.exit(0);
2680
2787
  }
2681
2788
  }
2682
- verbose(`Fetching blocks from ${color13.cyan(repoPaths.join(", "))}`);
2683
- if (!options.verbose) loading.start(`Fetching blocks from ${color13.cyan(repoPaths.join(", "))}`);
2789
+ verbose(`Fetching blocks from ${color14.cyan(repoPaths.join(", "))}`);
2790
+ if (!options.verbose) loading.start(`Fetching blocks from ${color14.cyan(repoPaths.join(", "))}`);
2684
2791
  const blocksMap = (await fetchBlocks(...repoPaths)).match(
2685
2792
  (val) => val,
2686
2793
  ({ repo, message }) => {
2687
- loading.stop(`Failed fetching blocks from ${color13.cyan(repo)}`);
2688
- program7.error(color13.red(message));
2794
+ loading.stop(`Failed fetching blocks from ${color14.cyan(repo)}`);
2795
+ program7.error(color14.red(message));
2689
2796
  }
2690
2797
  );
2691
- if (!options.verbose) loading.stop(`Retrieved blocks from ${color13.cyan(repoPaths.join(", "))}`);
2692
- verbose(`Retrieved blocks from ${color13.cyan(repoPaths.join(", "))}`);
2798
+ if (!options.verbose) loading.stop(`Retrieved blocks from ${color14.cyan(repoPaths.join(", "))}`);
2799
+ verbose(`Retrieved blocks from ${color14.cyan(repoPaths.join(", "))}`);
2693
2800
  const installedBlocks = getInstalled(blocksMap, config, options.cwd);
2694
2801
  let updatingBlockNames = blockNames;
2695
2802
  if (options.all) {
@@ -2700,19 +2807,19 @@ var _update = async (blockNames, options) => {
2700
2807
  message: "Which blocks would you like to update?",
2701
2808
  options: installedBlocks.map((block) => {
2702
2809
  return {
2703
- label: `${color13.cyan(block.block.category)}/${block.block.name}`,
2810
+ label: `${color14.cyan(block.block.category)}/${block.block.name}`,
2704
2811
  value: block.specifier
2705
2812
  };
2706
2813
  }),
2707
2814
  required: true
2708
2815
  });
2709
- if (isCancel5(promptResult)) {
2710
- cancel5("Canceled!");
2816
+ if (isCancel6(promptResult)) {
2817
+ cancel6("Canceled!");
2711
2818
  process.exit(0);
2712
2819
  }
2713
2820
  updatingBlockNames = promptResult;
2714
2821
  }
2715
- verbose(`Preparing to update ${color13.cyan(updatingBlockNames.join(", "))}`);
2822
+ verbose(`Preparing to update ${color14.cyan(updatingBlockNames.join(", "))}`);
2716
2823
  const updatingBlocks = (await resolveTree(updatingBlockNames, blocksMap, repoPaths)).match(
2717
2824
  (val) => val,
2718
2825
  program7.error
@@ -2729,13 +2836,12 @@ var _update = async (blockNames, options) => {
2729
2836
  const directory = path11.join(options.cwd, config.path, block.category);
2730
2837
  const files = [];
2731
2838
  const getSourceFile = async (filePath) => {
2732
- const rawUrl = await providerInfo.provider.resolveRaw(providerInfo, filePath);
2733
- const response = await fetch(rawUrl);
2734
- if (!response.ok) {
2735
- loading.stop(color13.red(`Error fetching ${color13.bold(rawUrl.href)}`));
2736
- program7.error(color13.red(`There was an error trying to get ${fullSpecifier}`));
2839
+ const content = await providerInfo.provider.fetchRaw(providerInfo, filePath);
2840
+ if (content.isErr()) {
2841
+ loading.stop(color14.red(`Error fetching ${color14.bold(filePath)}`));
2842
+ program7.error(color14.red(`There was an error trying to get ${fullSpecifier}`));
2737
2843
  }
2738
- return await response.text();
2844
+ return content.unwrap();
2739
2845
  };
2740
2846
  for (const sourceFile of block.files) {
2741
2847
  if (!config.includeTests && isTestFile(sourceFile)) continue;
@@ -2787,28 +2893,28 @@ ${remoteContent}`;
2787
2893
  changes,
2788
2894
  expand: options.expand,
2789
2895
  maxUnchanged: options.maxUnchanged,
2790
- colorAdded: color13.greenBright,
2791
- colorRemoved: color13.redBright,
2792
- colorCharsAdded: color13.bgGreenBright,
2793
- colorCharsRemoved: color13.bgRedBright,
2896
+ colorAdded: color14.greenBright,
2897
+ colorRemoved: color14.redBright,
2898
+ colorCharsAdded: color14.bgGreenBright,
2899
+ colorCharsRemoved: color14.bgRedBright,
2794
2900
  prefix: () => `${VERTICAL_LINE} `,
2795
- onUnchanged: ({ from: from2, to: to2, prefix }) => `${prefix?.() ?? ""}${color13.cyan(from2)} \u2192 ${color13.gray(to2)} ${color13.gray("(unchanged)")}
2901
+ onUnchanged: ({ from: from2, to: to2, prefix }) => `${prefix?.() ?? ""}${color14.cyan(from2)} \u2192 ${color14.gray(to2)} ${color14.gray("(unchanged)")}
2796
2902
  `,
2797
2903
  intro: ({ from: from2, to: to2, changes: changes2, prefix }) => {
2798
2904
  const totalChanges = changes2.filter((a) => a.added).length;
2799
- return `${prefix?.() ?? ""}${color13.cyan(from2)} \u2192 ${color13.gray(to2)} (${totalChanges} change${totalChanges === 1 ? "" : "s"})
2905
+ return `${prefix?.() ?? ""}${color14.cyan(from2)} \u2192 ${color14.gray(to2)} (${totalChanges} change${totalChanges === 1 ? "" : "s"})
2800
2906
  ${prefix?.() ?? ""}
2801
2907
  `;
2802
2908
  }
2803
2909
  });
2804
2910
  process.stdout.write(formattedDiff);
2805
2911
  if (changes.length > 1) {
2806
- const confirmResult = await confirm5({
2912
+ const confirmResult = await confirm6({
2807
2913
  message: "Accept changes?",
2808
2914
  initialValue: true
2809
2915
  });
2810
- if (isCancel5(confirmResult)) {
2811
- cancel5("Canceled!");
2916
+ if (isCancel6(confirmResult)) {
2917
+ cancel6("Canceled!");
2812
2918
  process.exit(0);
2813
2919
  }
2814
2920
  acceptedChanges = confirmResult;
@@ -2818,8 +2924,8 @@ ${prefix?.() ?? ""}
2818
2924
  await runTasks(
2819
2925
  [
2820
2926
  {
2821
- loadingMessage: `Writing changes to ${color13.cyan(file.destPath)}`,
2822
- completedMessage: `Wrote changes to ${color13.cyan(file.destPath)}.`,
2927
+ loadingMessage: `Writing changes to ${color14.cyan(file.destPath)}`,
2928
+ completedMessage: `Wrote changes to ${color14.cyan(file.destPath)}.`,
2823
2929
  run: async () => fs11.writeFileSync(file.destPath, remoteContent)
2824
2930
  }
2825
2931
  ],
@@ -2850,12 +2956,12 @@ ${prefix?.() ?? ""}
2850
2956
  if (hasDependencies) {
2851
2957
  let install = options.yes;
2852
2958
  if (!options.yes) {
2853
- const result = await confirm5({
2959
+ const result = await confirm6({
2854
2960
  message: "Would you like to install dependencies?",
2855
2961
  initialValue: true
2856
2962
  });
2857
- if (isCancel5(result)) {
2858
- cancel5("Canceled!");
2963
+ if (isCancel6(result)) {
2964
+ cancel6("Canceled!");
2859
2965
  process.exit(0);
2860
2966
  }
2861
2967
  install = result;
@@ -2863,7 +2969,7 @@ ${prefix?.() ?? ""}
2863
2969
  if (install) {
2864
2970
  if (deps.size > 0) {
2865
2971
  if (!options.verbose)
2866
- loading.start(`Installing dependencies with ${color13.cyan(pm)}`);
2972
+ loading.start(`Installing dependencies with ${color14.cyan(pm)}`);
2867
2973
  (await installDependencies({
2868
2974
  pm,
2869
2975
  deps: Array.from(deps),
@@ -2872,7 +2978,7 @@ ${prefix?.() ?? ""}
2872
2978
  })).match(
2873
2979
  (installed) => {
2874
2980
  if (!options.verbose)
2875
- loading.stop(`Installed ${color13.cyan(installed.join(", "))}`);
2981
+ loading.stop(`Installed ${color14.cyan(installed.join(", "))}`);
2876
2982
  },
2877
2983
  (err) => {
2878
2984
  if (!options.verbose) loading.stop("Failed to install dependencies");
@@ -2882,7 +2988,7 @@ ${prefix?.() ?? ""}
2882
2988
  }
2883
2989
  if (devDeps.size > 0) {
2884
2990
  if (!options.verbose)
2885
- loading.start(`Installing dependencies with ${color13.cyan(pm)}`);
2991
+ loading.start(`Installing dependencies with ${color14.cyan(pm)}`);
2886
2992
  (await installDependencies({
2887
2993
  pm,
2888
2994
  deps: Array.from(devDeps),
@@ -2891,7 +2997,7 @@ ${prefix?.() ?? ""}
2891
2997
  })).match(
2892
2998
  (installed) => {
2893
2999
  if (!options.verbose)
2894
- loading.stop(`Installed ${color13.cyan(installed.join(", "))}`);
3000
+ loading.stop(`Installed ${color14.cyan(installed.join(", "))}`);
2895
3001
  },
2896
3002
  (err) => {
2897
3003
  if (!options.verbose) loading.stop("Failed to install dev dependencies");
@@ -2905,13 +3011,13 @@ ${prefix?.() ?? ""}
2905
3011
  if (deps.size > 0) {
2906
3012
  const cmd = resolveCommand5(pm, "install", [...deps]);
2907
3013
  steps.push(
2908
- `Install dependencies \`${color13.cyan(`${cmd?.command} ${cmd?.args.join(" ")}`)}\``
3014
+ `Install dependencies \`${color14.cyan(`${cmd?.command} ${cmd?.args.join(" ")}`)}\``
2909
3015
  );
2910
3016
  }
2911
3017
  if (devDeps.size > 0) {
2912
3018
  const cmd = resolveCommand5(pm, "install", [...devDeps, "-D"]);
2913
3019
  steps.push(
2914
- `Install dev dependencies \`${color13.cyan(`${cmd?.command} ${cmd?.args.join(" ")}`)}\``
3020
+ `Install dev dependencies \`${color14.cyan(`${cmd?.command} ${cmd?.args.join(" ")}`)}\``
2915
3021
  );
2916
3022
  }
2917
3023
  }
@@ -2919,7 +3025,7 @@ ${prefix?.() ?? ""}
2919
3025
  if (!install) {
2920
3026
  steps.push("");
2921
3027
  }
2922
- steps.push(`Import the blocks from \`${color13.cyan(config.path)}\``);
3028
+ steps.push(`Import the blocks from \`${color14.cyan(config.path)}\``);
2923
3029
  const next = nextSteps(steps);
2924
3030
  process.stdout.write(next);
2925
3031
  }
@@ -2942,7 +3048,7 @@ var context = {
2942
3048
  },
2943
3049
  resolveRelativeToRoot
2944
3050
  };
2945
- program8.name(name).description(description).version(version).addCommand(add).addCommand(init).addCommand(test).addCommand(build).addCommand(update).addCommand(diff);
3051
+ program8.name(name).description(description).version(version).addCommand(add).addCommand(auth).addCommand(init).addCommand(test).addCommand(build).addCommand(update).addCommand(diff);
2946
3052
  program8.parse();
2947
3053
  export {
2948
3054
  context