@olorehq/olore 0.1.4 → 0.1.5
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/cli.js +39 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -884,6 +884,31 @@ function parsePackageSpec(spec) {
|
|
|
884
884
|
}
|
|
885
885
|
return { name: spec };
|
|
886
886
|
}
|
|
887
|
+
function levenshtein(a, b) {
|
|
888
|
+
const m = a.length;
|
|
889
|
+
const n = b.length;
|
|
890
|
+
const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
891
|
+
for (let i = 0; i <= m; i++) dp[i][0] = i;
|
|
892
|
+
for (let j = 0; j <= n; j++) dp[0][j] = j;
|
|
893
|
+
for (let i = 1; i <= m; i++) {
|
|
894
|
+
for (let j = 1; j <= n; j++) {
|
|
895
|
+
dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return dp[m][n];
|
|
899
|
+
}
|
|
900
|
+
function findSimilarPackages(input, packages, maxResults = 3) {
|
|
901
|
+
const results = [];
|
|
902
|
+
for (const [name, entry] of Object.entries(packages)) {
|
|
903
|
+
const distance = levenshtein(input.toLowerCase(), name.toLowerCase());
|
|
904
|
+
const isSubstring = name.toLowerCase().includes(input.toLowerCase()) || input.toLowerCase().includes(name.toLowerCase());
|
|
905
|
+
if (distance <= 3 || isSubstring) {
|
|
906
|
+
results.push({ name, description: entry.description, distance });
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
results.sort((a, b) => a.distance - b.distance);
|
|
910
|
+
return results.slice(0, maxResults).map(({ name, description }) => ({ name, description }));
|
|
911
|
+
}
|
|
887
912
|
async function installFromRemote(pkg, optionsVersion) {
|
|
888
913
|
const { name, version: specVersion } = parsePackageSpec(pkg);
|
|
889
914
|
const requestedVersion = optionsVersion || specVersion || "latest";
|
|
@@ -901,6 +926,20 @@ Installing ${name}@${requestedVersion} from registry...
|
|
|
901
926
|
if (error.code === "NOT_FOUND") {
|
|
902
927
|
console.log(pc3.yellow(`
|
|
903
928
|
Package "${name}" not found in registry.`));
|
|
929
|
+
try {
|
|
930
|
+
const index = await fetchPackageIndex();
|
|
931
|
+
const similar = findSimilarPackages(name, index.packages);
|
|
932
|
+
if (similar.length > 0) {
|
|
933
|
+
console.log(pc3.bold("\nDid you mean?"));
|
|
934
|
+
for (const pkg2 of similar) {
|
|
935
|
+
console.log(` ${pc3.cyan(pkg2.name)} ${pc3.gray("-")} ${pc3.gray(pkg2.description)}`);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
} catch {
|
|
939
|
+
}
|
|
940
|
+
console.log(
|
|
941
|
+
pc3.gray("\nRun ") + pc3.cyan("olore search") + pc3.gray(" to see all available packages.")
|
|
942
|
+
);
|
|
904
943
|
console.log(pc3.gray("\nFor local packages, use a path:"));
|
|
905
944
|
console.log(pc3.cyan(` olore install ./vault/packages/${name}/<version>`));
|
|
906
945
|
console.log("");
|