jsrepo 1.5.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 +511 -301
- package/package.json +2 -1
- package/src/commands/add.ts +4 -6
- package/src/commands/auth.ts +100 -0
- package/src/commands/build.ts +99 -15
- package/src/commands/diff.ts +3 -5
- package/src/commands/index.ts +2 -1
- package/src/commands/init.ts +47 -3
- package/src/commands/test.ts +18 -25
- package/src/commands/update.ts +5 -7
- package/src/index.ts +1 -0
- package/src/utils/build.ts +78 -16
- package/src/utils/git-providers.ts +59 -32
- package/src/utils/persisted.ts +7 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import fs12 from "node:fs";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { program as
|
|
4
|
+
import { program as program8 } from "commander";
|
|
5
5
|
import path12 from "pathe";
|
|
6
6
|
|
|
7
7
|
// src/commands/add.ts
|
|
@@ -913,7 +913,7 @@ var categorySchema = v2.object({
|
|
|
913
913
|
});
|
|
914
914
|
var TEST_SUFFIXES = [".test.ts", "_test.ts", ".test.js", "_test.js"];
|
|
915
915
|
var isTestFile = (file) => TEST_SUFFIXES.find((suffix) => file.endsWith(suffix)) !== void 0;
|
|
916
|
-
var buildBlocksDirectory = (blocksPath, { cwd, excludeDeps }) => {
|
|
916
|
+
var buildBlocksDirectory = (blocksPath, { cwd, excludeDeps, includeBlocks, includeCategories, errorOnWarn }) => {
|
|
917
917
|
let paths;
|
|
918
918
|
try {
|
|
919
919
|
paths = fs3.readdirSync(blocksPath);
|
|
@@ -925,6 +925,8 @@ var buildBlocksDirectory = (blocksPath, { cwd, excludeDeps }) => {
|
|
|
925
925
|
const categoryDir = path3.join(blocksPath, categoryPath);
|
|
926
926
|
if (fs3.statSync(categoryDir).isFile()) continue;
|
|
927
927
|
const categoryName = path3.basename(categoryPath);
|
|
928
|
+
if (includeCategories.length > 0 && includeCategories.find((val) => val.trim() === categoryName.trim()) === void 0)
|
|
929
|
+
continue;
|
|
928
930
|
const category = {
|
|
929
931
|
name: categoryName,
|
|
930
932
|
blocks: []
|
|
@@ -934,16 +936,29 @@ var buildBlocksDirectory = (blocksPath, { cwd, excludeDeps }) => {
|
|
|
934
936
|
const blockDir = path3.join(categoryDir, file);
|
|
935
937
|
if (fs3.statSync(blockDir).isFile()) {
|
|
936
938
|
if (isTestFile(file)) continue;
|
|
939
|
+
const name2 = path3.parse(path3.basename(file)).name;
|
|
940
|
+
if (includeBlocks.length > 0 && includeBlocks.find((val) => val.trim() === name2.trim()) === void 0)
|
|
941
|
+
continue;
|
|
937
942
|
const lang = languages.find((resolver) => resolver.matches(file));
|
|
938
943
|
if (!lang) {
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
+
const error = "files are not currently supported!";
|
|
945
|
+
if (errorOnWarn) {
|
|
946
|
+
program.error(
|
|
947
|
+
color3.red(
|
|
948
|
+
`Couldn't add \`${color3.bold(blockDir)}\` \`*${color3.bold(
|
|
949
|
+
path3.parse(file).ext
|
|
950
|
+
)}\` ${error}`
|
|
951
|
+
)
|
|
952
|
+
);
|
|
953
|
+
} else {
|
|
954
|
+
console.warn(
|
|
955
|
+
`${VERTICAL_LINE} ${WARN} Skipped \`${color3.bold(blockDir)}\` \`*${color3.bold(
|
|
956
|
+
path3.parse(file).ext
|
|
957
|
+
)}\` ${error}`
|
|
958
|
+
);
|
|
959
|
+
}
|
|
944
960
|
continue;
|
|
945
961
|
}
|
|
946
|
-
const name2 = path3.parse(path3.basename(file)).name;
|
|
947
962
|
const testsPath = files.find(
|
|
948
963
|
(f) => TEST_SUFFIXES.find((suffix) => f === `${name2}${suffix}`)
|
|
949
964
|
);
|
|
@@ -975,6 +990,8 @@ var buildBlocksDirectory = (blocksPath, { cwd, excludeDeps }) => {
|
|
|
975
990
|
category.blocks.push(block);
|
|
976
991
|
} else {
|
|
977
992
|
const blockName = file;
|
|
993
|
+
if (includeBlocks.length > 0 && includeBlocks.find((val) => val.trim() === blockName.trim()) === void 0)
|
|
994
|
+
continue;
|
|
978
995
|
const blockFiles = fs3.readdirSync(blockDir);
|
|
979
996
|
const hasTests = blockFiles.findIndex((f) => isTestFile(f)) !== -1;
|
|
980
997
|
const localDepsSet = /* @__PURE__ */ new Set();
|
|
@@ -983,18 +1000,38 @@ var buildBlocksDirectory = (blocksPath, { cwd, excludeDeps }) => {
|
|
|
983
1000
|
for (const f of blockFiles) {
|
|
984
1001
|
if (isTestFile(f)) continue;
|
|
985
1002
|
if (fs3.statSync(path3.join(blockDir, f)).isDirectory()) {
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1003
|
+
const error = "subdirectories are not currently supported!";
|
|
1004
|
+
if (errorOnWarn) {
|
|
1005
|
+
program.error(
|
|
1006
|
+
color3.red(
|
|
1007
|
+
`Couldn't add \`${color3.bold(path3.join(blockDir, f))}\` ${error}`
|
|
1008
|
+
)
|
|
1009
|
+
);
|
|
1010
|
+
} else {
|
|
1011
|
+
console.warn(
|
|
1012
|
+
`${VERTICAL_LINE} ${WARN} Skipped \`${color3.bold(path3.join(blockDir, f))}\` ${error}`
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
989
1015
|
continue;
|
|
990
1016
|
}
|
|
991
1017
|
const lang = languages.find((resolver) => resolver.matches(f));
|
|
992
1018
|
if (!lang) {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1019
|
+
const error = "files are not currently supported!";
|
|
1020
|
+
if (errorOnWarn) {
|
|
1021
|
+
program.error(
|
|
1022
|
+
color3.red(
|
|
1023
|
+
`Couldn't add \`${color3.bold(path3.join(blockDir, f))}\` \`*${color3.bold(
|
|
1024
|
+
path3.parse(f).ext
|
|
1025
|
+
)}\` ${error}`
|
|
1026
|
+
)
|
|
1027
|
+
);
|
|
1028
|
+
} else {
|
|
1029
|
+
console.warn(
|
|
1030
|
+
`${VERTICAL_LINE} ${WARN} Skipped \`${path3.join(blockDir, f)}\` \`*${color3.bold(
|
|
1031
|
+
path3.parse(f).ext
|
|
1032
|
+
)}\` ${error}`
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
998
1035
|
continue;
|
|
999
1036
|
}
|
|
1000
1037
|
const { local, dependencies, devDependencies } = lang.resolveDependencies({
|
|
@@ -1040,23 +1077,54 @@ var buildBlocksDirectory = (blocksPath, { cwd, excludeDeps }) => {
|
|
|
1040
1077
|
// src/utils/context.ts
|
|
1041
1078
|
var OUTPUT_FILE = "jsrepo-manifest.json";
|
|
1042
1079
|
|
|
1080
|
+
// src/utils/persisted.ts
|
|
1081
|
+
import Conf from "conf";
|
|
1082
|
+
var get = () => {
|
|
1083
|
+
return new Conf({ projectName: "jsrepo" });
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1043
1086
|
// src/utils/git-providers.ts
|
|
1044
1087
|
var octokit = new Octokit({});
|
|
1045
1088
|
var github = {
|
|
1046
1089
|
name: () => "github",
|
|
1047
1090
|
resolveRaw: async (repoPath, resourcePath) => {
|
|
1048
|
-
|
|
1049
|
-
if (typeof repoPath === "string") {
|
|
1050
|
-
info = await github.info(repoPath);
|
|
1051
|
-
} else {
|
|
1052
|
-
info = repoPath;
|
|
1053
|
-
}
|
|
1091
|
+
const info = await github.info(repoPath);
|
|
1054
1092
|
return new URL(
|
|
1055
1093
|
resourcePath,
|
|
1056
1094
|
`https://raw.githubusercontent.com/${info.owner}/${info.repoName}/refs/${info.refs}/${info.ref}/`
|
|
1057
1095
|
);
|
|
1058
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
|
+
},
|
|
1059
1126
|
info: async (repoPath) => {
|
|
1127
|
+
if (typeof repoPath !== "string") return repoPath;
|
|
1060
1128
|
const repo = repoPath.replaceAll(/(https:\/\/github.com\/)|(github\/)/g, "");
|
|
1061
1129
|
const [owner, repoName, ...rest] = repo.split("/");
|
|
1062
1130
|
let ref = "main";
|
|
@@ -1098,32 +1166,13 @@ var getProviderInfo = async (repo) => {
|
|
|
1098
1166
|
}
|
|
1099
1167
|
return Err("Only GitHub repositories are supported at this time!");
|
|
1100
1168
|
};
|
|
1101
|
-
var getManifest = async (url) => {
|
|
1102
|
-
const errorMessage = (err) => {
|
|
1103
|
-
return Err(
|
|
1104
|
-
`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.
|
|
1105
|
-
Error: ${err}`
|
|
1106
|
-
);
|
|
1107
|
-
};
|
|
1108
|
-
try {
|
|
1109
|
-
const response = await fetch(url);
|
|
1110
|
-
if (!response.ok) {
|
|
1111
|
-
return errorMessage(`${response.status} ${response.text}`);
|
|
1112
|
-
}
|
|
1113
|
-
const categories = v3.parse(v3.array(categorySchema), await response.json());
|
|
1114
|
-
return Ok(categories);
|
|
1115
|
-
} catch (err) {
|
|
1116
|
-
return errorMessage(`${err}`);
|
|
1117
|
-
}
|
|
1118
|
-
};
|
|
1119
1169
|
var fetchBlocks = async (...repos) => {
|
|
1120
1170
|
const blocksMap = /* @__PURE__ */ new Map();
|
|
1121
1171
|
for (const repo of repos) {
|
|
1122
1172
|
const getProviderResult = await getProviderInfo(repo);
|
|
1123
1173
|
if (getProviderResult.isErr()) return Err({ message: getProviderResult.unwrapErr(), repo });
|
|
1124
1174
|
const providerInfo = getProviderResult.unwrap();
|
|
1125
|
-
const
|
|
1126
|
-
const getManifestResult = await getManifest(manifestUrl);
|
|
1175
|
+
const getManifestResult = await providerInfo.provider.fetchManifest(providerInfo);
|
|
1127
1176
|
if (getManifestResult.isErr()) return Err({ message: getManifestResult.unwrapErr(), repo });
|
|
1128
1177
|
const categories = getManifestResult.unwrap();
|
|
1129
1178
|
for (const category of categories) {
|
|
@@ -1491,15 +1540,14 @@ var _add = async (blockNames, options) => {
|
|
|
1491
1540
|
fs6.mkdirSync(directory, { recursive: true });
|
|
1492
1541
|
const files = [];
|
|
1493
1542
|
const getSourceFile = async (filePath) => {
|
|
1494
|
-
const
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
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)}`));
|
|
1498
1546
|
program2.error(
|
|
1499
1547
|
color7.red(`There was an error trying to get ${fullSpecifier}`)
|
|
1500
1548
|
);
|
|
1501
1549
|
}
|
|
1502
|
-
return
|
|
1550
|
+
return content.unwrap();
|
|
1503
1551
|
};
|
|
1504
1552
|
for (const sourceFile of block.files) {
|
|
1505
1553
|
if (!config.includeTests && isTestFile(sourceFile)) continue;
|
|
@@ -1627,67 +1675,205 @@ ${content}`;
|
|
|
1627
1675
|
}
|
|
1628
1676
|
};
|
|
1629
1677
|
|
|
1630
|
-
// src/commands/
|
|
1631
|
-
import
|
|
1632
|
-
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";
|
|
1633
1680
|
import color8 from "chalk";
|
|
1634
|
-
import { Command as Command2 } from "commander";
|
|
1635
|
-
import path7 from "pathe";
|
|
1681
|
+
import { Command as Command2, Option } from "commander";
|
|
1636
1682
|
import * as v6 from "valibot";
|
|
1637
1683
|
var schema3 = v6.object({
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
verbose: v6.boolean(),
|
|
1684
|
+
token: v6.optional(v6.string()),
|
|
1685
|
+
provider: v6.optional(v6.string()),
|
|
1686
|
+
logout: v6.boolean(),
|
|
1642
1687
|
cwd: v6.string()
|
|
1643
1688
|
});
|
|
1644
|
-
var
|
|
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) => {
|
|
1645
1694
|
const options = v6.parse(schema3, opts);
|
|
1646
1695
|
_intro(context.package.version);
|
|
1647
|
-
await
|
|
1696
|
+
await _auth(options);
|
|
1648
1697
|
outro2(color8.green("All done!"));
|
|
1649
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(
|
|
1767
|
+
"--include-categories [categoryNames...]",
|
|
1768
|
+
"Include only the categories with these names.",
|
|
1769
|
+
[]
|
|
1770
|
+
).option("--exclude-deps [deps...]", "Dependencies that should not be added.", []).option("--no-output", `Do not output a \`${OUTPUT_FILE}\` file.`).option(
|
|
1771
|
+
"--error-on-warn",
|
|
1772
|
+
"If there is a warning throw an error and do not allow build to complete.",
|
|
1773
|
+
false
|
|
1774
|
+
).option("--verbose", "Include debug logs.", false).option("--cwd <path>", "The current working directory.", process.cwd()).action(async (opts) => {
|
|
1775
|
+
const options = v7.parse(schema4, opts);
|
|
1776
|
+
_intro(context.package.version);
|
|
1777
|
+
await _build(options);
|
|
1778
|
+
outro3(color9.green("All done!"));
|
|
1779
|
+
});
|
|
1650
1780
|
var _build = async (options) => {
|
|
1651
1781
|
const loading = spinner3();
|
|
1652
1782
|
const categories = [];
|
|
1653
1783
|
const outFile = path7.join(options.cwd, OUTPUT_FILE);
|
|
1654
1784
|
for (const dir of options.dirs) {
|
|
1655
1785
|
const dirPath = path7.join(options.cwd, dir);
|
|
1656
|
-
loading.start(`Building ${
|
|
1786
|
+
loading.start(`Building ${color9.cyan(dirPath)}`);
|
|
1657
1787
|
if (options.output && fs7.existsSync(outFile)) fs7.rmSync(outFile);
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1788
|
+
const builtCategories = buildBlocksDirectory(dirPath, { ...options });
|
|
1789
|
+
for (const category of builtCategories) {
|
|
1790
|
+
if (categories.find((cat) => cat.name === category.name) !== void 0) {
|
|
1791
|
+
const error = "a category with the same name already exists!";
|
|
1792
|
+
if (options.errorOnWarn) {
|
|
1793
|
+
program3.error(
|
|
1794
|
+
color9.red(
|
|
1795
|
+
`\`${color9.bold(`${dir}/${category.name}`)}\` could not be added because ${error}`
|
|
1796
|
+
)
|
|
1797
|
+
);
|
|
1798
|
+
} else {
|
|
1799
|
+
console.warn(
|
|
1800
|
+
`${VERTICAL_LINE} ${WARN} Skipped adding \`${color9.cyan(`${dir}/${category.name}`)}\` because ${error}`
|
|
1801
|
+
);
|
|
1802
|
+
}
|
|
1803
|
+
continue;
|
|
1804
|
+
}
|
|
1805
|
+
categories.push(category);
|
|
1806
|
+
}
|
|
1807
|
+
loading.stop(`Built ${color9.cyan(dirPath)}`);
|
|
1662
1808
|
}
|
|
1663
|
-
|
|
1809
|
+
loading.start("Checking manifest");
|
|
1810
|
+
const warnings = [];
|
|
1664
1811
|
for (const category of categories) {
|
|
1665
|
-
const
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1812
|
+
for (const block of category.blocks) {
|
|
1813
|
+
for (const dep of block.localDependencies) {
|
|
1814
|
+
const [depCategoryName, depBlockName] = dep.split("/");
|
|
1815
|
+
const depCategory = categories.find(
|
|
1816
|
+
(cat) => cat.name.trim() === depCategoryName.trim()
|
|
1817
|
+
);
|
|
1818
|
+
const invalidDependencyError = () => {
|
|
1819
|
+
const error = `depends on ${color9.bold(dep)} which doesn't exist!`;
|
|
1820
|
+
if (options.errorOnWarn) {
|
|
1821
|
+
warnings.push(
|
|
1822
|
+
color9.red(`${color9.bold(`${category.name}/${block.name}`)} ${error}`)
|
|
1823
|
+
);
|
|
1824
|
+
} else {
|
|
1825
|
+
warnings.push(
|
|
1826
|
+
`${VERTICAL_LINE} ${WARN} ${color9.bold(`${category.name}/${block.name}`)} ${error}`
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
if (!depCategory) {
|
|
1831
|
+
invalidDependencyError();
|
|
1832
|
+
continue;
|
|
1833
|
+
}
|
|
1834
|
+
if (depCategory.blocks.find((b) => b.name === depBlockName) === void 0) {
|
|
1835
|
+
invalidDependencyError();
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
for (const dep of [...block.dependencies, ...block.devDependencies]) {
|
|
1839
|
+
if (!dep.includes("@")) {
|
|
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!`;
|
|
1841
|
+
if (options.errorOnWarn) {
|
|
1842
|
+
warnings.push(color9.red(error));
|
|
1843
|
+
} else {
|
|
1844
|
+
warnings.push(`${VERTICAL_LINE} ${WARN} ${error}`);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
loading.stop("Completed checking manifest.");
|
|
1851
|
+
if (warnings.length > 0) {
|
|
1852
|
+
for (const warning of warnings) {
|
|
1853
|
+
console.log(warning);
|
|
1854
|
+
}
|
|
1855
|
+
if (options.errorOnWarn) {
|
|
1856
|
+
program3.error("Had warnings while checking manifest.");
|
|
1669
1857
|
}
|
|
1670
|
-
cat.blocks = [...cat.blocks, ...category.blocks];
|
|
1671
|
-
categoriesMap.set(cat.name, cat);
|
|
1672
1858
|
}
|
|
1673
1859
|
if (options.output) {
|
|
1860
|
+
loading.start(`Writing output to \`${color9.cyan(outFile)}\``);
|
|
1674
1861
|
fs7.writeFileSync(outFile, JSON.stringify(categories, null, " "));
|
|
1675
|
-
|
|
1676
|
-
loading.stop("Built successfully!");
|
|
1862
|
+
loading.stop(`Wrote output to \`${color9.cyan(outFile)}\``);
|
|
1677
1863
|
}
|
|
1678
1864
|
};
|
|
1679
1865
|
|
|
1680
1866
|
// src/commands/diff.ts
|
|
1681
1867
|
import fs8 from "node:fs";
|
|
1682
|
-
import { cancel as
|
|
1683
|
-
import
|
|
1684
|
-
import { Command as
|
|
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";
|
|
1685
1871
|
import { diffLines } from "diff";
|
|
1686
1872
|
import path8 from "pathe";
|
|
1687
|
-
import * as
|
|
1873
|
+
import * as v8 from "valibot";
|
|
1688
1874
|
|
|
1689
1875
|
// src/utils/diff.ts
|
|
1690
|
-
import
|
|
1876
|
+
import color10 from "chalk";
|
|
1691
1877
|
import { diffChars } from "diff";
|
|
1692
1878
|
|
|
1693
1879
|
// src/utils/blocks/utils/array-sum.ts
|
|
@@ -1702,7 +1888,7 @@ var arraySum = (arr, fn) => {
|
|
|
1702
1888
|
// src/utils/blocks/utils/lines.ts
|
|
1703
1889
|
import os from "node:os";
|
|
1704
1890
|
var NEW_LINE_REGEX = /\n|\r\n/g;
|
|
1705
|
-
var
|
|
1891
|
+
var get2 = (str) => str.split(NEW_LINE_REGEX);
|
|
1706
1892
|
var join = (lines, { lineNumbers = false, prefix } = {}) => {
|
|
1707
1893
|
let transformed = lines;
|
|
1708
1894
|
if (lineNumbers) {
|
|
@@ -1736,10 +1922,10 @@ var formatDiff = ({
|
|
|
1736
1922
|
changes,
|
|
1737
1923
|
expand = false,
|
|
1738
1924
|
maxUnchanged = 5,
|
|
1739
|
-
colorRemoved =
|
|
1740
|
-
colorAdded =
|
|
1741
|
-
colorCharsRemoved =
|
|
1742
|
-
colorCharsAdded =
|
|
1925
|
+
colorRemoved = color10.red,
|
|
1926
|
+
colorAdded = color10.green,
|
|
1927
|
+
colorCharsRemoved = color10.bgRed,
|
|
1928
|
+
colorCharsAdded = color10.bgGreen,
|
|
1743
1929
|
prefix,
|
|
1744
1930
|
onUnchanged,
|
|
1745
1931
|
intro: intro2
|
|
@@ -1773,7 +1959,7 @@ var formatDiff = ({
|
|
|
1773
1959
|
onUnchanged,
|
|
1774
1960
|
intro: intro2
|
|
1775
1961
|
});
|
|
1776
|
-
const linePrefix = (line) =>
|
|
1962
|
+
const linePrefix = (line) => color10.gray(`${prefix?.() ?? ""}${leftPadMin(`${line + 1 + lineOffset} `, length)} `);
|
|
1777
1963
|
for (let i = 0; i < changes.length; i++) {
|
|
1778
1964
|
const change = changes[i];
|
|
1779
1965
|
const hasPreviousChange = changes[i - 1]?.added || changes[i - 1]?.removed;
|
|
@@ -1781,7 +1967,7 @@ var formatDiff = ({
|
|
|
1781
1967
|
if (!change.added && !change.removed) {
|
|
1782
1968
|
if (!expand && change.count !== void 0 && change.count > maxUnchanged) {
|
|
1783
1969
|
const prevLineOffset = lineOffset;
|
|
1784
|
-
const ls =
|
|
1970
|
+
const ls = get2(trimSingleNewLine(change.value));
|
|
1785
1971
|
let shownLines = 0;
|
|
1786
1972
|
if (hasNextChange) shownLines += maxUnchanged;
|
|
1787
1973
|
if (hasPreviousChange) shownLines += maxUnchanged;
|
|
@@ -1802,9 +1988,9 @@ var formatDiff = ({
|
|
|
1802
1988
|
if (ls.length > shownLines) {
|
|
1803
1989
|
const count = ls.length - shownLines;
|
|
1804
1990
|
result += `${join(
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
`+ ${count} more unchanged (${
|
|
1991
|
+
get2(
|
|
1992
|
+
color10.gray(
|
|
1993
|
+
`+ ${count} more unchanged (${color10.italic("-E to expand")})`
|
|
1808
1994
|
)
|
|
1809
1995
|
),
|
|
1810
1996
|
{
|
|
@@ -1823,7 +2009,7 @@ var formatDiff = ({
|
|
|
1823
2009
|
lineOffset = prevLineOffset + change.count;
|
|
1824
2010
|
continue;
|
|
1825
2011
|
}
|
|
1826
|
-
result += `${join(
|
|
2012
|
+
result += `${join(get2(trimSingleNewLine(change.value)), {
|
|
1827
2013
|
prefix: linePrefix
|
|
1828
2014
|
})}
|
|
1829
2015
|
`;
|
|
@@ -1856,7 +2042,7 @@ var formatDiff = ({
|
|
|
1856
2042
|
i++;
|
|
1857
2043
|
} else {
|
|
1858
2044
|
if (isWhitespace(change.value)) {
|
|
1859
|
-
result += `${join(
|
|
2045
|
+
result += `${join(get2(colorCharChange(change)), {
|
|
1860
2046
|
prefix: (line) => `${linePrefix(line)}${colorCharChange({ removed: true, value: " ", added: false })}`
|
|
1861
2047
|
})}
|
|
1862
2048
|
`;
|
|
@@ -1864,7 +2050,7 @@ var formatDiff = ({
|
|
|
1864
2050
|
lineOffset += change.count ?? 0;
|
|
1865
2051
|
}
|
|
1866
2052
|
} else {
|
|
1867
|
-
result += `${join(
|
|
2053
|
+
result += `${join(get2(colorLineChange(change)), {
|
|
1868
2054
|
prefix: linePrefix
|
|
1869
2055
|
})}
|
|
1870
2056
|
`;
|
|
@@ -1878,52 +2064,52 @@ var formatDiff = ({
|
|
|
1878
2064
|
};
|
|
1879
2065
|
|
|
1880
2066
|
// src/commands/diff.ts
|
|
1881
|
-
var
|
|
1882
|
-
expand:
|
|
1883
|
-
maxUnchanged:
|
|
1884
|
-
repo:
|
|
1885
|
-
allow:
|
|
1886
|
-
cwd:
|
|
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()
|
|
1887
2073
|
});
|
|
1888
|
-
var diff = new
|
|
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(
|
|
1889
2075
|
"--max-unchanged <number>",
|
|
1890
2076
|
"Maximum unchanged lines that will show without being collapsed.",
|
|
1891
2077
|
(val) => Number.parseInt(val),
|
|
1892
2078
|
// this is such a dumb api thing
|
|
1893
2079
|
3
|
|
1894
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) => {
|
|
1895
|
-
const options =
|
|
2081
|
+
const options = v8.parse(schema5, opts);
|
|
1896
2082
|
_intro(context.package.version);
|
|
1897
2083
|
await _diff(options);
|
|
1898
|
-
|
|
2084
|
+
outro4(color11.green("All done!"));
|
|
1899
2085
|
});
|
|
1900
2086
|
var _diff = async (options) => {
|
|
1901
2087
|
const loading = spinner4();
|
|
1902
2088
|
const config = getConfig(options.cwd).match(
|
|
1903
2089
|
(val) => val,
|
|
1904
|
-
(err) =>
|
|
2090
|
+
(err) => program4.error(color11.red(err))
|
|
1905
2091
|
);
|
|
1906
2092
|
let repoPaths = config.repos;
|
|
1907
2093
|
if (options.repo) repoPaths = [options.repo];
|
|
1908
2094
|
if (!options.allow && options.repo) {
|
|
1909
|
-
const result = await
|
|
1910
|
-
message: `Allow ${
|
|
2095
|
+
const result = await confirm3({
|
|
2096
|
+
message: `Allow ${color11.cyan("jsrepo")} to download and run code from ${color11.cyan(options.repo)}?`,
|
|
1911
2097
|
initialValue: true
|
|
1912
2098
|
});
|
|
1913
|
-
if (
|
|
1914
|
-
|
|
2099
|
+
if (isCancel3(result) || !result) {
|
|
2100
|
+
cancel3("Canceled!");
|
|
1915
2101
|
process.exit(0);
|
|
1916
2102
|
}
|
|
1917
2103
|
}
|
|
1918
|
-
loading.start(`Fetching blocks from ${
|
|
2104
|
+
loading.start(`Fetching blocks from ${color11.cyan(repoPaths.join(", "))}`);
|
|
1919
2105
|
const blocksMap = (await fetchBlocks(...repoPaths)).match(
|
|
1920
2106
|
(val) => val,
|
|
1921
2107
|
({ repo, message }) => {
|
|
1922
|
-
loading.stop(`Failed fetching blocks from ${
|
|
1923
|
-
|
|
2108
|
+
loading.stop(`Failed fetching blocks from ${color11.cyan(repo)}`);
|
|
2109
|
+
program4.error(color11.red(message));
|
|
1924
2110
|
}
|
|
1925
2111
|
);
|
|
1926
|
-
loading.stop(`Retrieved blocks from ${
|
|
2112
|
+
loading.stop(`Retrieved blocks from ${color11.cyan(repoPaths.join(", "))}`);
|
|
1927
2113
|
const installedBlocks = getInstalled(blocksMap, config, options.cwd);
|
|
1928
2114
|
for (const blockSpecifier of installedBlocks) {
|
|
1929
2115
|
let found = false;
|
|
@@ -1943,12 +2129,11 @@ var _diff = async (options) => {
|
|
|
1943
2129
|
process.stdout.write(`${VERTICAL_LINE}
|
|
1944
2130
|
`);
|
|
1945
2131
|
const sourcePath = path8.join(block.directory, file);
|
|
1946
|
-
const
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
program3.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}`));
|
|
1950
2135
|
}
|
|
1951
|
-
let remoteContent =
|
|
2136
|
+
let remoteContent = response.unwrap();
|
|
1952
2137
|
const directory = path8.join(options.cwd, config.path, block.category);
|
|
1953
2138
|
let localPath = path8.join(directory, file);
|
|
1954
2139
|
let prettyLocalPath = path8.join(config.path, block.category, file);
|
|
@@ -1980,16 +2165,16 @@ ${remoteContent}`;
|
|
|
1980
2165
|
changes,
|
|
1981
2166
|
expand: options.expand,
|
|
1982
2167
|
maxUnchanged: options.maxUnchanged,
|
|
1983
|
-
colorAdded:
|
|
1984
|
-
colorRemoved:
|
|
1985
|
-
colorCharsAdded:
|
|
1986
|
-
colorCharsRemoved:
|
|
2168
|
+
colorAdded: color11.greenBright,
|
|
2169
|
+
colorRemoved: color11.redBright,
|
|
2170
|
+
colorCharsAdded: color11.bgGreenBright,
|
|
2171
|
+
colorCharsRemoved: color11.bgRedBright,
|
|
1987
2172
|
prefix: () => `${VERTICAL_LINE} `,
|
|
1988
|
-
onUnchanged: ({ from: from2, to, prefix }) => `${prefix?.() ?? ""}${
|
|
2173
|
+
onUnchanged: ({ from: from2, to, prefix }) => `${prefix?.() ?? ""}${color11.cyan(from2)} \u2192 ${color11.gray(to)} ${color11.gray("(unchanged)")}
|
|
1989
2174
|
`,
|
|
1990
2175
|
intro: ({ from: from2, to, changes: changes2, prefix }) => {
|
|
1991
2176
|
const totalChanges = changes2.filter((a) => a.added).length;
|
|
1992
|
-
return `${prefix?.() ?? ""}${
|
|
2177
|
+
return `${prefix?.() ?? ""}${color11.cyan(from2)} \u2192 ${color11.gray(to)} (${totalChanges} change${totalChanges === 1 ? "" : "s"})
|
|
1993
2178
|
${prefix?.() ?? ""}
|
|
1994
2179
|
`;
|
|
1995
2180
|
}
|
|
@@ -1999,8 +2184,8 @@ ${prefix?.() ?? ""}
|
|
|
1999
2184
|
break;
|
|
2000
2185
|
}
|
|
2001
2186
|
if (!found) {
|
|
2002
|
-
|
|
2003
|
-
|
|
2187
|
+
program4.error(
|
|
2188
|
+
color11.red(`Invalid block! ${color11.bold(blockSpecifier)} does not exist!`)
|
|
2004
2189
|
);
|
|
2005
2190
|
}
|
|
2006
2191
|
}
|
|
@@ -2008,38 +2193,38 @@ ${prefix?.() ?? ""}
|
|
|
2008
2193
|
|
|
2009
2194
|
// src/commands/init.ts
|
|
2010
2195
|
import fs9 from "node:fs";
|
|
2011
|
-
import { cancel as
|
|
2012
|
-
import
|
|
2013
|
-
import { Command as
|
|
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";
|
|
2014
2199
|
import { detect as detect2, resolveCommand as resolveCommand3 } from "package-manager-detector";
|
|
2015
2200
|
import path9 from "pathe";
|
|
2016
|
-
import * as
|
|
2017
|
-
var
|
|
2018
|
-
path:
|
|
2019
|
-
repos:
|
|
2020
|
-
watermark:
|
|
2021
|
-
tests:
|
|
2022
|
-
project:
|
|
2023
|
-
registry:
|
|
2024
|
-
script:
|
|
2025
|
-
yes:
|
|
2026
|
-
cwd:
|
|
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()
|
|
2027
2212
|
});
|
|
2028
|
-
var init = new
|
|
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(
|
|
2029
2214
|
"--no-watermark",
|
|
2030
2215
|
"Will not add a watermark to each file upon adding it to your project."
|
|
2031
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) => {
|
|
2032
|
-
const options =
|
|
2217
|
+
const options = v9.parse(schema6, opts);
|
|
2033
2218
|
_intro(context.package.version);
|
|
2034
2219
|
if (options.registry !== void 0 && options.project !== void 0) {
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
`You cannot provide both ${
|
|
2220
|
+
program5.error(
|
|
2221
|
+
color12.red(
|
|
2222
|
+
`You cannot provide both ${color12.bold("--project")} and ${color12.bold("--registry")} at the same time.`
|
|
2038
2223
|
)
|
|
2039
2224
|
);
|
|
2040
2225
|
}
|
|
2041
2226
|
if (options.registry === void 0 && options.project === void 0) {
|
|
2042
|
-
const response = await
|
|
2227
|
+
const response = await select2({
|
|
2043
2228
|
message: "Initialize a project or registry?",
|
|
2044
2229
|
options: [
|
|
2045
2230
|
{ value: "project", label: "project" },
|
|
@@ -2047,8 +2232,8 @@ var init = new Command4("init").description("Initializes your project with a con
|
|
|
2047
2232
|
],
|
|
2048
2233
|
initialValue: "project"
|
|
2049
2234
|
});
|
|
2050
|
-
if (
|
|
2051
|
-
|
|
2235
|
+
if (isCancel4(response)) {
|
|
2236
|
+
cancel4("Canceled!");
|
|
2052
2237
|
process.exit(0);
|
|
2053
2238
|
}
|
|
2054
2239
|
options.registry = response === "registry";
|
|
@@ -2058,9 +2243,10 @@ var init = new Command4("init").description("Initializes your project with a con
|
|
|
2058
2243
|
} else {
|
|
2059
2244
|
await _initProject(options);
|
|
2060
2245
|
}
|
|
2061
|
-
|
|
2246
|
+
outro5(color12.green("All done!"));
|
|
2062
2247
|
});
|
|
2063
2248
|
var _initProject = async (options) => {
|
|
2249
|
+
const storage = get();
|
|
2064
2250
|
const initialConfig = getConfig(options.cwd);
|
|
2065
2251
|
const loading = spinner5();
|
|
2066
2252
|
if (!options.path) {
|
|
@@ -2071,8 +2257,8 @@ var _initProject = async (options) => {
|
|
|
2071
2257
|
},
|
|
2072
2258
|
initialValue: initialConfig.isOk() ? initialConfig.unwrap().path : "src/blocks"
|
|
2073
2259
|
});
|
|
2074
|
-
if (
|
|
2075
|
-
|
|
2260
|
+
if (isCancel4(result)) {
|
|
2261
|
+
cancel4("Canceled!");
|
|
2076
2262
|
process.exit(0);
|
|
2077
2263
|
}
|
|
2078
2264
|
options.path = result;
|
|
@@ -2080,13 +2266,13 @@ var _initProject = async (options) => {
|
|
|
2080
2266
|
if (!options.repos) {
|
|
2081
2267
|
options.repos = initialConfig.isOk() ? initialConfig.unwrap().repos : [];
|
|
2082
2268
|
while (true) {
|
|
2083
|
-
const confirmResult = await
|
|
2269
|
+
const confirmResult = await confirm4({
|
|
2084
2270
|
message: `Add ${options.repos.length > 0 ? "another" : "a"} repo?`,
|
|
2085
2271
|
initialValue: options.repos.length === 0
|
|
2086
2272
|
// default to yes for first repo
|
|
2087
2273
|
});
|
|
2088
|
-
if (
|
|
2089
|
-
|
|
2274
|
+
if (isCancel4(confirmResult)) {
|
|
2275
|
+
cancel4("Canceled!");
|
|
2090
2276
|
process.exit(0);
|
|
2091
2277
|
}
|
|
2092
2278
|
if (!confirmResult) break;
|
|
@@ -2094,15 +2280,45 @@ var _initProject = async (options) => {
|
|
|
2094
2280
|
message: "Where should we download the blocks from?",
|
|
2095
2281
|
placeholder: "github/ieedan/std",
|
|
2096
2282
|
validate: (val) => {
|
|
2097
|
-
if (
|
|
2098
|
-
|
|
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(", ")})`;
|
|
2099
2286
|
}
|
|
2100
2287
|
}
|
|
2101
2288
|
});
|
|
2102
|
-
if (
|
|
2103
|
-
|
|
2289
|
+
if (isCancel4(result)) {
|
|
2290
|
+
cancel4("Canceled!");
|
|
2104
2291
|
process.exit(0);
|
|
2105
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
|
+
}
|
|
2106
2322
|
options.repos.push(result);
|
|
2107
2323
|
}
|
|
2108
2324
|
}
|
|
@@ -2131,25 +2347,25 @@ var _initRegistry = async (options) => {
|
|
|
2131
2347
|
initialValue: "./blocks",
|
|
2132
2348
|
placeholder: "./blocks"
|
|
2133
2349
|
});
|
|
2134
|
-
if (
|
|
2135
|
-
|
|
2350
|
+
if (isCancel4(response)) {
|
|
2351
|
+
cancel4("Canceled!");
|
|
2136
2352
|
process.exit(0);
|
|
2137
2353
|
}
|
|
2138
2354
|
options.path = response;
|
|
2139
2355
|
}
|
|
2140
2356
|
const packagePath = path9.join(options.cwd, "package.json");
|
|
2141
2357
|
if (!fs9.existsSync(packagePath)) {
|
|
2142
|
-
|
|
2358
|
+
program5.error(color12.red(`Couldn't find your ${color12.bold("package.json")}!`));
|
|
2143
2359
|
}
|
|
2144
2360
|
const pkg = JSON.parse(fs9.readFileSync(packagePath).toString());
|
|
2145
2361
|
const scriptAlreadyExists = pkg.scripts !== void 0 && pkg.scripts[options.script] !== void 0;
|
|
2146
2362
|
if (!options.yes && scriptAlreadyExists) {
|
|
2147
|
-
const response = await
|
|
2148
|
-
message: `The \`${
|
|
2363
|
+
const response = await confirm4({
|
|
2364
|
+
message: `The \`${color12.cyan(options.script)}\` already exists overwrite?`,
|
|
2149
2365
|
initialValue: false
|
|
2150
2366
|
});
|
|
2151
|
-
if (
|
|
2152
|
-
|
|
2367
|
+
if (isCancel4(response)) {
|
|
2368
|
+
cancel4("Canceled!");
|
|
2153
2369
|
process.exit(0);
|
|
2154
2370
|
}
|
|
2155
2371
|
if (!response) {
|
|
@@ -2162,8 +2378,8 @@ var _initRegistry = async (options) => {
|
|
|
2162
2378
|
if (val.trim().length === 0) return "Please provide a value!";
|
|
2163
2379
|
}
|
|
2164
2380
|
});
|
|
2165
|
-
if (
|
|
2166
|
-
|
|
2381
|
+
if (isCancel4(response2)) {
|
|
2382
|
+
cancel4("Canceled!");
|
|
2167
2383
|
process.exit(0);
|
|
2168
2384
|
}
|
|
2169
2385
|
options.script = response2;
|
|
@@ -2172,12 +2388,12 @@ var _initRegistry = async (options) => {
|
|
|
2172
2388
|
const alreadyInstalled = pkg.devDependencies && pkg.devDependencies.jsrepo !== void 0;
|
|
2173
2389
|
let installAsDevDependency = options.yes || alreadyInstalled;
|
|
2174
2390
|
if (!options.yes && !alreadyInstalled) {
|
|
2175
|
-
const response = await
|
|
2391
|
+
const response = await confirm4({
|
|
2176
2392
|
message: `Add ${JSREPO} as a dev dependency?`,
|
|
2177
2393
|
initialValue: true
|
|
2178
2394
|
});
|
|
2179
|
-
if (
|
|
2180
|
-
|
|
2395
|
+
if (isCancel4(response)) {
|
|
2396
|
+
cancel4("Canceled!");
|
|
2181
2397
|
process.exit(0);
|
|
2182
2398
|
}
|
|
2183
2399
|
installAsDevDependency = response;
|
|
@@ -2188,7 +2404,7 @@ var _initRegistry = async (options) => {
|
|
|
2188
2404
|
buildScript += "jsrepo build ";
|
|
2189
2405
|
} else {
|
|
2190
2406
|
const command = resolveCommand3(pm, "execute", ["jsrepo", "build"]);
|
|
2191
|
-
if (!command)
|
|
2407
|
+
if (!command) program5.error(color12.red(`Error resolving execute command for ${pm}`));
|
|
2192
2408
|
buildScript += `${command.command} ${command.args.join(" ")} `;
|
|
2193
2409
|
}
|
|
2194
2410
|
if (options.path !== "./build") {
|
|
@@ -2198,23 +2414,23 @@ var _initRegistry = async (options) => {
|
|
|
2198
2414
|
pkg.scripts = {};
|
|
2199
2415
|
}
|
|
2200
2416
|
pkg.scripts[options.script] = buildScript;
|
|
2201
|
-
loading.start(`Adding \`${
|
|
2417
|
+
loading.start(`Adding \`${color12.cyan(options.script)}\` to scripts in package.json`);
|
|
2202
2418
|
try {
|
|
2203
2419
|
fs9.writeFileSync(packagePath, JSON.stringify(pkg, null, " "));
|
|
2204
2420
|
} catch (err) {
|
|
2205
|
-
|
|
2421
|
+
program5.error(color12.red(`Error writing to \`${color12.bold(packagePath)}\`. Error: ${err}`));
|
|
2206
2422
|
}
|
|
2207
|
-
loading.stop(`Added \`${
|
|
2423
|
+
loading.stop(`Added \`${color12.cyan(options.script)}\` to scripts in package.json`);
|
|
2208
2424
|
let installed = alreadyInstalled;
|
|
2209
2425
|
if (installAsDevDependency && !alreadyInstalled) {
|
|
2210
2426
|
let shouldInstall = options.yes;
|
|
2211
2427
|
if (!options.yes) {
|
|
2212
|
-
const response = await
|
|
2428
|
+
const response = await confirm4({
|
|
2213
2429
|
message: "Install dependencies?",
|
|
2214
2430
|
initialValue: true
|
|
2215
2431
|
});
|
|
2216
|
-
if (
|
|
2217
|
-
|
|
2432
|
+
if (isCancel4(response)) {
|
|
2433
|
+
cancel4("Canceled!");
|
|
2218
2434
|
process.exit(0);
|
|
2219
2435
|
}
|
|
2220
2436
|
shouldInstall = response;
|
|
@@ -2231,7 +2447,7 @@ var _initRegistry = async (options) => {
|
|
|
2231
2447
|
() => loading.stop(`Installed ${JSREPO}.`),
|
|
2232
2448
|
(err) => {
|
|
2233
2449
|
loading.stop(`Failed to install ${JSREPO}.`);
|
|
2234
|
-
|
|
2450
|
+
program5.error(err);
|
|
2235
2451
|
}
|
|
2236
2452
|
);
|
|
2237
2453
|
installed = true;
|
|
@@ -2241,13 +2457,13 @@ var _initRegistry = async (options) => {
|
|
|
2241
2457
|
if (!installed && installAsDevDependency) {
|
|
2242
2458
|
const cmd = resolveCommand3(pm, "install", ["jsrepo", "-D"]);
|
|
2243
2459
|
steps.push(
|
|
2244
|
-
`Install ${JSREPO} as a dev dependency \`${
|
|
2460
|
+
`Install ${JSREPO} as a dev dependency \`${color12.cyan(`${cmd?.command} ${cmd?.args.join(" ")}`)}\``
|
|
2245
2461
|
);
|
|
2246
2462
|
}
|
|
2247
|
-
steps.push(`Add blocks to \`${
|
|
2463
|
+
steps.push(`Add blocks to \`${color12.cyan(options.path)}\`.`);
|
|
2248
2464
|
const runScript = resolveCommand3(pm, "run", [options.script]);
|
|
2249
2465
|
steps.push(
|
|
2250
|
-
`Run \`${
|
|
2466
|
+
`Run \`${color12.cyan(`${runScript?.command} ${runScript?.args.join(" ")}`)}\` to build the registry.`
|
|
2251
2467
|
);
|
|
2252
2468
|
steps = steps.map((step, i) => `${i + 1}. ${step}`);
|
|
2253
2469
|
const next = nextSteps(steps);
|
|
@@ -2256,27 +2472,27 @@ var _initRegistry = async (options) => {
|
|
|
2256
2472
|
|
|
2257
2473
|
// src/commands/test.ts
|
|
2258
2474
|
import fs10 from "node:fs";
|
|
2259
|
-
import { cancel as
|
|
2260
|
-
import
|
|
2261
|
-
import { Argument, Command as
|
|
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";
|
|
2262
2478
|
import { execa as execa2 } from "execa";
|
|
2263
2479
|
import { resolveCommand as resolveCommand4 } from "package-manager-detector/commands";
|
|
2264
2480
|
import { detect as detect3 } from "package-manager-detector/detect";
|
|
2265
2481
|
import path10 from "pathe";
|
|
2266
2482
|
import { Project as Project2 } from "ts-morph";
|
|
2267
|
-
import * as
|
|
2268
|
-
var
|
|
2269
|
-
repo:
|
|
2270
|
-
allow:
|
|
2271
|
-
debug:
|
|
2272
|
-
verbose:
|
|
2273
|
-
cwd:
|
|
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()
|
|
2274
2490
|
});
|
|
2275
|
-
var test = new
|
|
2276
|
-
const options =
|
|
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);
|
|
2277
2493
|
_intro(context.package.version);
|
|
2278
2494
|
await _test(blockNames, options);
|
|
2279
|
-
|
|
2495
|
+
outro6(color13.green("All done!"));
|
|
2280
2496
|
});
|
|
2281
2497
|
var _test = async (blockNames, options) => {
|
|
2282
2498
|
const verbose = (msg) => {
|
|
@@ -2287,43 +2503,42 @@ var _test = async (blockNames, options) => {
|
|
|
2287
2503
|
verbose(`Attempting to test ${JSON.stringify(blockNames)}`);
|
|
2288
2504
|
const config = getConfig(options.cwd).match(
|
|
2289
2505
|
(val) => val,
|
|
2290
|
-
(err) =>
|
|
2506
|
+
(err) => program6.error(color13.red(err))
|
|
2291
2507
|
);
|
|
2292
2508
|
const loading = spinner6();
|
|
2293
2509
|
const blocksMap = /* @__PURE__ */ new Map();
|
|
2294
2510
|
let repoPaths = config.repos;
|
|
2295
2511
|
if (options.repo) repoPaths = [options.repo];
|
|
2296
2512
|
if (!options.allow && options.repo) {
|
|
2297
|
-
const result = await
|
|
2298
|
-
message: `Allow ${
|
|
2513
|
+
const result = await confirm5({
|
|
2514
|
+
message: `Allow ${color13.cyan("jsrepo")} to download and run code from ${color13.cyan(options.repo)}?`,
|
|
2299
2515
|
initialValue: true
|
|
2300
2516
|
});
|
|
2301
|
-
if (
|
|
2302
|
-
|
|
2517
|
+
if (isCancel5(result) || !result) {
|
|
2518
|
+
cancel5("Canceled!");
|
|
2303
2519
|
process.exit(0);
|
|
2304
2520
|
}
|
|
2305
2521
|
}
|
|
2306
|
-
verbose(`Fetching blocks from ${
|
|
2307
|
-
if (!options.verbose) loading.start(`Fetching blocks from ${
|
|
2522
|
+
verbose(`Fetching blocks from ${color13.cyan(repoPaths.join(", "))}`);
|
|
2523
|
+
if (!options.verbose) loading.start(`Fetching blocks from ${color13.cyan(repoPaths.join(", "))}`);
|
|
2308
2524
|
for (const repo of repoPaths) {
|
|
2309
2525
|
const providerInfo = (await getProviderInfo(repo)).match(
|
|
2310
2526
|
(info) => info,
|
|
2311
|
-
(err) =>
|
|
2527
|
+
(err) => program6.error(color13.red(err))
|
|
2312
2528
|
);
|
|
2313
|
-
const
|
|
2314
|
-
verbose(`Got info for provider ${
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
`There was an error fetching the \`${OUTPUT_FILE}\` from the repository ${color12.cyan(
|
|
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)}`);
|
|
2533
|
+
program6.error(
|
|
2534
|
+
color13.red(
|
|
2535
|
+
`There was an error fetching the \`${OUTPUT_FILE}\` from the repository ${color13.cyan(
|
|
2321
2536
|
repo
|
|
2322
2537
|
)} make sure the target repository has a \`${OUTPUT_FILE}\` in its root?`
|
|
2323
2538
|
)
|
|
2324
2539
|
);
|
|
2325
2540
|
}
|
|
2326
|
-
const categories =
|
|
2541
|
+
const categories = manifest.unwrap();
|
|
2327
2542
|
for (const category of categories) {
|
|
2328
2543
|
for (const block of category.blocks) {
|
|
2329
2544
|
blocksMap.set(
|
|
@@ -2336,12 +2551,12 @@ var _test = async (blockNames, options) => {
|
|
|
2336
2551
|
}
|
|
2337
2552
|
}
|
|
2338
2553
|
}
|
|
2339
|
-
verbose(`Retrieved blocks from ${
|
|
2340
|
-
if (!options.verbose) loading.stop(`Retrieved blocks from ${
|
|
2554
|
+
verbose(`Retrieved blocks from ${color13.cyan(repoPaths.join(", "))}`);
|
|
2555
|
+
if (!options.verbose) loading.stop(`Retrieved blocks from ${color13.cyan(repoPaths.join(", "))}`);
|
|
2341
2556
|
const tempTestDirectory = path10.resolve(
|
|
2342
2557
|
path10.join(options.cwd, `blocks-tests-temp-${Date.now()}`)
|
|
2343
2558
|
);
|
|
2344
|
-
verbose(`Trying to create the temp directory ${
|
|
2559
|
+
verbose(`Trying to create the temp directory ${color13.bold(tempTestDirectory)}.`);
|
|
2345
2560
|
fs10.mkdirSync(tempTestDirectory, { recursive: true });
|
|
2346
2561
|
const cleanUp = () => {
|
|
2347
2562
|
fs10.rmSync(tempTestDirectory, { recursive: true, force: true });
|
|
@@ -2355,7 +2570,7 @@ var _test = async (blockNames, options) => {
|
|
|
2355
2570
|
}
|
|
2356
2571
|
if (testingBlocks.length === 0) {
|
|
2357
2572
|
cleanUp();
|
|
2358
|
-
|
|
2573
|
+
program6.error(color13.red("There were no blocks found in your project!"));
|
|
2359
2574
|
}
|
|
2360
2575
|
const testingBlocksMapped = [];
|
|
2361
2576
|
for (const blockSpecifier of testingBlocks) {
|
|
@@ -2381,15 +2596,11 @@ var _test = async (blockNames, options) => {
|
|
|
2381
2596
|
}
|
|
2382
2597
|
const providerInfo = (await getProviderInfo(repo)).match(
|
|
2383
2598
|
(val) => val,
|
|
2384
|
-
(err) =>
|
|
2599
|
+
(err) => program6.error(color13.red(err))
|
|
2385
2600
|
);
|
|
2386
|
-
const
|
|
2387
|
-
providerInfo,
|
|
2388
|
-
OUTPUT_FILE
|
|
2389
|
-
);
|
|
2390
|
-
const categories = (await getManifest(manifestUrl)).match(
|
|
2601
|
+
const categories = (await providerInfo.provider.fetchManifest(providerInfo)).match(
|
|
2391
2602
|
(val) => val,
|
|
2392
|
-
(err) =>
|
|
2603
|
+
(err) => program6.error(color13.red(err))
|
|
2393
2604
|
);
|
|
2394
2605
|
for (const category of categories) {
|
|
2395
2606
|
for (const block2 of category.blocks) {
|
|
@@ -2406,31 +2617,31 @@ var _test = async (blockNames, options) => {
|
|
|
2406
2617
|
block = blocksMap.get(blockSpecifier);
|
|
2407
2618
|
}
|
|
2408
2619
|
if (!block) {
|
|
2409
|
-
|
|
2410
|
-
|
|
2620
|
+
program6.error(
|
|
2621
|
+
color13.red(`Invalid block! ${color13.bold(blockSpecifier)} does not exist!`)
|
|
2411
2622
|
);
|
|
2412
2623
|
}
|
|
2413
2624
|
testingBlocksMapped.push({ name: blockSpecifier, block });
|
|
2414
2625
|
}
|
|
2415
|
-
for (const {
|
|
2626
|
+
for (const { block } of testingBlocksMapped) {
|
|
2416
2627
|
const providerInfo = block.sourceRepo;
|
|
2628
|
+
const fullSpecifier = `${block.sourceRepo.url}/${block.category}/${block.name}`;
|
|
2417
2629
|
if (!options.verbose) {
|
|
2418
|
-
loading.start(`Setting up test file for ${
|
|
2630
|
+
loading.start(`Setting up test file for ${color13.cyan(fullSpecifier)}`);
|
|
2419
2631
|
}
|
|
2420
2632
|
if (!block.tests) {
|
|
2421
|
-
loading.stop(`No tests found for ${
|
|
2633
|
+
loading.stop(`No tests found for ${color13.cyan(fullSpecifier)}`);
|
|
2422
2634
|
continue;
|
|
2423
2635
|
}
|
|
2424
2636
|
const getSourceFile = async (filePath) => {
|
|
2425
|
-
const
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
program5.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}`));
|
|
2430
2641
|
}
|
|
2431
|
-
return
|
|
2642
|
+
return content.unwrap();
|
|
2432
2643
|
};
|
|
2433
|
-
verbose(`Downloading and copying test files for ${
|
|
2644
|
+
verbose(`Downloading and copying test files for ${fullSpecifier}`);
|
|
2434
2645
|
const testFiles = [];
|
|
2435
2646
|
for (const testFile of block.files.filter((file) => isTestFile(file))) {
|
|
2436
2647
|
const content = await getSourceFile(path10.join(block.directory, testFile));
|
|
@@ -2469,19 +2680,19 @@ var _test = async (blockNames, options) => {
|
|
|
2469
2680
|
}
|
|
2470
2681
|
}
|
|
2471
2682
|
project.saveSync();
|
|
2472
|
-
verbose(`Completed ${
|
|
2683
|
+
verbose(`Completed ${color13.cyan.bold(fullSpecifier)} test file`);
|
|
2473
2684
|
if (!options.verbose) {
|
|
2474
|
-
loading.stop(`Completed setup for ${
|
|
2685
|
+
loading.stop(`Completed setup for ${color13.bold(fullSpecifier)}`);
|
|
2475
2686
|
}
|
|
2476
2687
|
}
|
|
2477
2688
|
verbose("Beginning testing");
|
|
2478
2689
|
const pm = await detect3({ cwd: options.cwd });
|
|
2479
2690
|
if (pm == null) {
|
|
2480
|
-
|
|
2691
|
+
program6.error(color13.red("Could not detect package manager"));
|
|
2481
2692
|
}
|
|
2482
2693
|
const resolved = resolveCommand4(pm.agent, "execute", ["vitest", "run", tempTestDirectory]);
|
|
2483
2694
|
if (resolved == null) {
|
|
2484
|
-
|
|
2695
|
+
program6.error(color13.red(`Could not resolve add command for '${pm.agent}'.`));
|
|
2485
2696
|
}
|
|
2486
2697
|
const { command, args } = resolved;
|
|
2487
2698
|
const testCommand = `${command} ${args.join(" ")}`;
|
|
@@ -2498,7 +2709,7 @@ var _test = async (blockNames, options) => {
|
|
|
2498
2709
|
} catch (err) {
|
|
2499
2710
|
if (options.debug) {
|
|
2500
2711
|
console.info(
|
|
2501
|
-
`${
|
|
2712
|
+
`${color13.bold("--debug")} flag provided. Skipping cleanup. Run '${color13.bold(
|
|
2502
2713
|
testCommand
|
|
2503
2714
|
)}' to retry tests.
|
|
2504
2715
|
`
|
|
@@ -2506,41 +2717,41 @@ var _test = async (blockNames, options) => {
|
|
|
2506
2717
|
} else {
|
|
2507
2718
|
cleanUp();
|
|
2508
2719
|
}
|
|
2509
|
-
|
|
2720
|
+
program6.error(color13.red(`Tests failed! Error ${err}`));
|
|
2510
2721
|
}
|
|
2511
2722
|
};
|
|
2512
2723
|
|
|
2513
2724
|
// src/commands/update.ts
|
|
2514
2725
|
import fs11 from "node:fs";
|
|
2515
|
-
import { cancel as
|
|
2516
|
-
import
|
|
2517
|
-
import { Command as
|
|
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";
|
|
2518
2729
|
import { diffLines as diffLines2 } from "diff";
|
|
2519
2730
|
import { resolveCommand as resolveCommand5 } from "package-manager-detector/commands";
|
|
2520
2731
|
import { detect as detect4 } from "package-manager-detector/detect";
|
|
2521
2732
|
import path11 from "pathe";
|
|
2522
|
-
import * as
|
|
2523
|
-
var
|
|
2524
|
-
all:
|
|
2525
|
-
expand:
|
|
2526
|
-
maxUnchanged:
|
|
2527
|
-
repo:
|
|
2528
|
-
allow:
|
|
2529
|
-
yes:
|
|
2530
|
-
verbose:
|
|
2531
|
-
cwd:
|
|
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()
|
|
2532
2743
|
});
|
|
2533
|
-
var update = new
|
|
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(
|
|
2534
2745
|
"--max-unchanged <number>",
|
|
2535
2746
|
"Maximum unchanged lines that will show without being collapsed.",
|
|
2536
2747
|
(val) => Number.parseInt(val),
|
|
2537
2748
|
// this is such a dumb api thing
|
|
2538
2749
|
3
|
|
2539
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) => {
|
|
2540
|
-
const options =
|
|
2751
|
+
const options = v11.parse(schema8, opts);
|
|
2541
2752
|
_intro(context.package.version);
|
|
2542
2753
|
await _update(blockNames, options);
|
|
2543
|
-
|
|
2754
|
+
outro7(color14.green("All done!"));
|
|
2544
2755
|
});
|
|
2545
2756
|
var _update = async (blockNames, options) => {
|
|
2546
2757
|
const verbose = (msg) => {
|
|
@@ -2552,40 +2763,40 @@ var _update = async (blockNames, options) => {
|
|
|
2552
2763
|
const loading = spinner7();
|
|
2553
2764
|
const config = getConfig(options.cwd).match(
|
|
2554
2765
|
(val) => val,
|
|
2555
|
-
(err) =>
|
|
2766
|
+
(err) => program7.error(color14.red(err))
|
|
2556
2767
|
);
|
|
2557
2768
|
let repoPaths = config.repos;
|
|
2558
2769
|
if (options.repo) repoPaths = [options.repo];
|
|
2559
2770
|
for (const blockSpecifier of blockNames) {
|
|
2560
2771
|
if (blockSpecifier.startsWith("github")) {
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
`Invalid value provided for block names \`${
|
|
2772
|
+
program7.error(
|
|
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>")}\``
|
|
2564
2775
|
)
|
|
2565
2776
|
);
|
|
2566
2777
|
}
|
|
2567
2778
|
}
|
|
2568
2779
|
if (!options.allow && options.repo) {
|
|
2569
|
-
const result = await
|
|
2570
|
-
message: `Allow ${
|
|
2780
|
+
const result = await confirm6({
|
|
2781
|
+
message: `Allow ${color14.cyan("jsrepo")} to download and run code from ${color14.cyan(options.repo)}?`,
|
|
2571
2782
|
initialValue: true
|
|
2572
2783
|
});
|
|
2573
|
-
if (
|
|
2574
|
-
|
|
2784
|
+
if (isCancel6(result) || !result) {
|
|
2785
|
+
cancel6("Canceled!");
|
|
2575
2786
|
process.exit(0);
|
|
2576
2787
|
}
|
|
2577
2788
|
}
|
|
2578
|
-
verbose(`Fetching blocks from ${
|
|
2579
|
-
if (!options.verbose) loading.start(`Fetching blocks from ${
|
|
2789
|
+
verbose(`Fetching blocks from ${color14.cyan(repoPaths.join(", "))}`);
|
|
2790
|
+
if (!options.verbose) loading.start(`Fetching blocks from ${color14.cyan(repoPaths.join(", "))}`);
|
|
2580
2791
|
const blocksMap = (await fetchBlocks(...repoPaths)).match(
|
|
2581
2792
|
(val) => val,
|
|
2582
2793
|
({ repo, message }) => {
|
|
2583
|
-
loading.stop(`Failed fetching blocks from ${
|
|
2584
|
-
|
|
2794
|
+
loading.stop(`Failed fetching blocks from ${color14.cyan(repo)}`);
|
|
2795
|
+
program7.error(color14.red(message));
|
|
2585
2796
|
}
|
|
2586
2797
|
);
|
|
2587
|
-
if (!options.verbose) loading.stop(`Retrieved blocks from ${
|
|
2588
|
-
verbose(`Retrieved blocks from ${
|
|
2798
|
+
if (!options.verbose) loading.stop(`Retrieved blocks from ${color14.cyan(repoPaths.join(", "))}`);
|
|
2799
|
+
verbose(`Retrieved blocks from ${color14.cyan(repoPaths.join(", "))}`);
|
|
2589
2800
|
const installedBlocks = getInstalled(blocksMap, config, options.cwd);
|
|
2590
2801
|
let updatingBlockNames = blockNames;
|
|
2591
2802
|
if (options.all) {
|
|
@@ -2596,22 +2807,22 @@ var _update = async (blockNames, options) => {
|
|
|
2596
2807
|
message: "Which blocks would you like to update?",
|
|
2597
2808
|
options: installedBlocks.map((block) => {
|
|
2598
2809
|
return {
|
|
2599
|
-
label: `${
|
|
2810
|
+
label: `${color14.cyan(block.block.category)}/${block.block.name}`,
|
|
2600
2811
|
value: block.specifier
|
|
2601
2812
|
};
|
|
2602
2813
|
}),
|
|
2603
2814
|
required: true
|
|
2604
2815
|
});
|
|
2605
|
-
if (
|
|
2606
|
-
|
|
2816
|
+
if (isCancel6(promptResult)) {
|
|
2817
|
+
cancel6("Canceled!");
|
|
2607
2818
|
process.exit(0);
|
|
2608
2819
|
}
|
|
2609
2820
|
updatingBlockNames = promptResult;
|
|
2610
2821
|
}
|
|
2611
|
-
verbose(`Preparing to update ${
|
|
2822
|
+
verbose(`Preparing to update ${color14.cyan(updatingBlockNames.join(", "))}`);
|
|
2612
2823
|
const updatingBlocks = (await resolveTree(updatingBlockNames, blocksMap, repoPaths)).match(
|
|
2613
2824
|
(val) => val,
|
|
2614
|
-
|
|
2825
|
+
program7.error
|
|
2615
2826
|
);
|
|
2616
2827
|
const pm = (await detect4({ cwd: options.cwd }))?.agent ?? "npm";
|
|
2617
2828
|
const tasks = [];
|
|
@@ -2625,13 +2836,12 @@ var _update = async (blockNames, options) => {
|
|
|
2625
2836
|
const directory = path11.join(options.cwd, config.path, block.category);
|
|
2626
2837
|
const files = [];
|
|
2627
2838
|
const getSourceFile = async (filePath) => {
|
|
2628
|
-
const
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
program6.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}`));
|
|
2633
2843
|
}
|
|
2634
|
-
return
|
|
2844
|
+
return content.unwrap();
|
|
2635
2845
|
};
|
|
2636
2846
|
for (const sourceFile of block.files) {
|
|
2637
2847
|
if (!config.includeTests && isTestFile(sourceFile)) continue;
|
|
@@ -2683,28 +2893,28 @@ ${remoteContent}`;
|
|
|
2683
2893
|
changes,
|
|
2684
2894
|
expand: options.expand,
|
|
2685
2895
|
maxUnchanged: options.maxUnchanged,
|
|
2686
|
-
colorAdded:
|
|
2687
|
-
colorRemoved:
|
|
2688
|
-
colorCharsAdded:
|
|
2689
|
-
colorCharsRemoved:
|
|
2896
|
+
colorAdded: color14.greenBright,
|
|
2897
|
+
colorRemoved: color14.redBright,
|
|
2898
|
+
colorCharsAdded: color14.bgGreenBright,
|
|
2899
|
+
colorCharsRemoved: color14.bgRedBright,
|
|
2690
2900
|
prefix: () => `${VERTICAL_LINE} `,
|
|
2691
|
-
onUnchanged: ({ from: from2, to: to2, prefix }) => `${prefix?.() ?? ""}${
|
|
2901
|
+
onUnchanged: ({ from: from2, to: to2, prefix }) => `${prefix?.() ?? ""}${color14.cyan(from2)} \u2192 ${color14.gray(to2)} ${color14.gray("(unchanged)")}
|
|
2692
2902
|
`,
|
|
2693
2903
|
intro: ({ from: from2, to: to2, changes: changes2, prefix }) => {
|
|
2694
2904
|
const totalChanges = changes2.filter((a) => a.added).length;
|
|
2695
|
-
return `${prefix?.() ?? ""}${
|
|
2905
|
+
return `${prefix?.() ?? ""}${color14.cyan(from2)} \u2192 ${color14.gray(to2)} (${totalChanges} change${totalChanges === 1 ? "" : "s"})
|
|
2696
2906
|
${prefix?.() ?? ""}
|
|
2697
2907
|
`;
|
|
2698
2908
|
}
|
|
2699
2909
|
});
|
|
2700
2910
|
process.stdout.write(formattedDiff);
|
|
2701
2911
|
if (changes.length > 1) {
|
|
2702
|
-
const confirmResult = await
|
|
2912
|
+
const confirmResult = await confirm6({
|
|
2703
2913
|
message: "Accept changes?",
|
|
2704
2914
|
initialValue: true
|
|
2705
2915
|
});
|
|
2706
|
-
if (
|
|
2707
|
-
|
|
2916
|
+
if (isCancel6(confirmResult)) {
|
|
2917
|
+
cancel6("Canceled!");
|
|
2708
2918
|
process.exit(0);
|
|
2709
2919
|
}
|
|
2710
2920
|
acceptedChanges = confirmResult;
|
|
@@ -2714,8 +2924,8 @@ ${prefix?.() ?? ""}
|
|
|
2714
2924
|
await runTasks(
|
|
2715
2925
|
[
|
|
2716
2926
|
{
|
|
2717
|
-
loadingMessage: `Writing changes to ${
|
|
2718
|
-
completedMessage: `Wrote changes to ${
|
|
2927
|
+
loadingMessage: `Writing changes to ${color14.cyan(file.destPath)}`,
|
|
2928
|
+
completedMessage: `Wrote changes to ${color14.cyan(file.destPath)}.`,
|
|
2719
2929
|
run: async () => fs11.writeFileSync(file.destPath, remoteContent)
|
|
2720
2930
|
}
|
|
2721
2931
|
],
|
|
@@ -2746,12 +2956,12 @@ ${prefix?.() ?? ""}
|
|
|
2746
2956
|
if (hasDependencies) {
|
|
2747
2957
|
let install = options.yes;
|
|
2748
2958
|
if (!options.yes) {
|
|
2749
|
-
const result = await
|
|
2959
|
+
const result = await confirm6({
|
|
2750
2960
|
message: "Would you like to install dependencies?",
|
|
2751
2961
|
initialValue: true
|
|
2752
2962
|
});
|
|
2753
|
-
if (
|
|
2754
|
-
|
|
2963
|
+
if (isCancel6(result)) {
|
|
2964
|
+
cancel6("Canceled!");
|
|
2755
2965
|
process.exit(0);
|
|
2756
2966
|
}
|
|
2757
2967
|
install = result;
|
|
@@ -2759,7 +2969,7 @@ ${prefix?.() ?? ""}
|
|
|
2759
2969
|
if (install) {
|
|
2760
2970
|
if (deps.size > 0) {
|
|
2761
2971
|
if (!options.verbose)
|
|
2762
|
-
loading.start(`Installing dependencies with ${
|
|
2972
|
+
loading.start(`Installing dependencies with ${color14.cyan(pm)}`);
|
|
2763
2973
|
(await installDependencies({
|
|
2764
2974
|
pm,
|
|
2765
2975
|
deps: Array.from(deps),
|
|
@@ -2768,17 +2978,17 @@ ${prefix?.() ?? ""}
|
|
|
2768
2978
|
})).match(
|
|
2769
2979
|
(installed) => {
|
|
2770
2980
|
if (!options.verbose)
|
|
2771
|
-
loading.stop(`Installed ${
|
|
2981
|
+
loading.stop(`Installed ${color14.cyan(installed.join(", "))}`);
|
|
2772
2982
|
},
|
|
2773
2983
|
(err) => {
|
|
2774
2984
|
if (!options.verbose) loading.stop("Failed to install dependencies");
|
|
2775
|
-
|
|
2985
|
+
program7.error(err);
|
|
2776
2986
|
}
|
|
2777
2987
|
);
|
|
2778
2988
|
}
|
|
2779
2989
|
if (devDeps.size > 0) {
|
|
2780
2990
|
if (!options.verbose)
|
|
2781
|
-
loading.start(`Installing dependencies with ${
|
|
2991
|
+
loading.start(`Installing dependencies with ${color14.cyan(pm)}`);
|
|
2782
2992
|
(await installDependencies({
|
|
2783
2993
|
pm,
|
|
2784
2994
|
deps: Array.from(devDeps),
|
|
@@ -2787,11 +2997,11 @@ ${prefix?.() ?? ""}
|
|
|
2787
2997
|
})).match(
|
|
2788
2998
|
(installed) => {
|
|
2789
2999
|
if (!options.verbose)
|
|
2790
|
-
loading.stop(`Installed ${
|
|
3000
|
+
loading.stop(`Installed ${color14.cyan(installed.join(", "))}`);
|
|
2791
3001
|
},
|
|
2792
3002
|
(err) => {
|
|
2793
3003
|
if (!options.verbose) loading.stop("Failed to install dev dependencies");
|
|
2794
|
-
|
|
3004
|
+
program7.error(err);
|
|
2795
3005
|
}
|
|
2796
3006
|
);
|
|
2797
3007
|
}
|
|
@@ -2801,13 +3011,13 @@ ${prefix?.() ?? ""}
|
|
|
2801
3011
|
if (deps.size > 0) {
|
|
2802
3012
|
const cmd = resolveCommand5(pm, "install", [...deps]);
|
|
2803
3013
|
steps.push(
|
|
2804
|
-
`Install dependencies \`${
|
|
3014
|
+
`Install dependencies \`${color14.cyan(`${cmd?.command} ${cmd?.args.join(" ")}`)}\``
|
|
2805
3015
|
);
|
|
2806
3016
|
}
|
|
2807
3017
|
if (devDeps.size > 0) {
|
|
2808
3018
|
const cmd = resolveCommand5(pm, "install", [...devDeps, "-D"]);
|
|
2809
3019
|
steps.push(
|
|
2810
|
-
`Install dev dependencies \`${
|
|
3020
|
+
`Install dev dependencies \`${color14.cyan(`${cmd?.command} ${cmd?.args.join(" ")}`)}\``
|
|
2811
3021
|
);
|
|
2812
3022
|
}
|
|
2813
3023
|
}
|
|
@@ -2815,7 +3025,7 @@ ${prefix?.() ?? ""}
|
|
|
2815
3025
|
if (!install) {
|
|
2816
3026
|
steps.push("");
|
|
2817
3027
|
}
|
|
2818
|
-
steps.push(`Import the blocks from \`${
|
|
3028
|
+
steps.push(`Import the blocks from \`${color14.cyan(config.path)}\``);
|
|
2819
3029
|
const next = nextSteps(steps);
|
|
2820
3030
|
process.stdout.write(next);
|
|
2821
3031
|
}
|
|
@@ -2838,8 +3048,8 @@ var context = {
|
|
|
2838
3048
|
},
|
|
2839
3049
|
resolveRelativeToRoot
|
|
2840
3050
|
};
|
|
2841
|
-
|
|
2842
|
-
|
|
3051
|
+
program8.name(name).description(description).version(version).addCommand(add).addCommand(auth).addCommand(init).addCommand(test).addCommand(build).addCommand(update).addCommand(diff);
|
|
3052
|
+
program8.parse();
|
|
2843
3053
|
export {
|
|
2844
3054
|
context
|
|
2845
3055
|
};
|