@liangmi/mo 1.0.1 → 1.0.2
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/mo.mjs +62 -25
- package/package.json +1 -1
package/dist/mo.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { Buffer as Buffer$1 } from "node:buffer";
|
|
|
13
13
|
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
14
14
|
import prompts from "prompts";
|
|
15
15
|
//#region package.json
|
|
16
|
-
var version = "1.0.
|
|
16
|
+
var version = "1.0.2";
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/commands/clone.ts
|
|
19
19
|
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
@@ -25198,6 +25198,53 @@ const useInput = (inputHandler, options = {}) => {
|
|
|
25198
25198
|
]);
|
|
25199
25199
|
};
|
|
25200
25200
|
//#endregion
|
|
25201
|
+
//#region src/utils/search.ts
|
|
25202
|
+
function getMatchScore(text, query) {
|
|
25203
|
+
const normalizedText = text.toLowerCase();
|
|
25204
|
+
const normalizedQuery = query.trim().toLowerCase();
|
|
25205
|
+
if (!normalizedQuery) return null;
|
|
25206
|
+
if (!normalizedText.includes(normalizedQuery)) return null;
|
|
25207
|
+
if (normalizedText === normalizedQuery) return 0;
|
|
25208
|
+
if (normalizedText.startsWith(normalizedQuery)) return 1;
|
|
25209
|
+
return 2;
|
|
25210
|
+
}
|
|
25211
|
+
function searchReposByName(query, groups) {
|
|
25212
|
+
const matches = [];
|
|
25213
|
+
for (const group of groups) for (const repo of group.repos) {
|
|
25214
|
+
const score = getMatchScore(repo.name, query);
|
|
25215
|
+
if (score === null) continue;
|
|
25216
|
+
matches.push({
|
|
25217
|
+
repo,
|
|
25218
|
+
score
|
|
25219
|
+
});
|
|
25220
|
+
}
|
|
25221
|
+
matches.sort((a, b) => {
|
|
25222
|
+
if (a.score !== b.score) return a.score - b.score;
|
|
25223
|
+
if (a.repo.name.length !== b.repo.name.length) return a.repo.name.length - b.repo.name.length;
|
|
25224
|
+
const byName = a.repo.name.localeCompare(b.repo.name);
|
|
25225
|
+
if (byName !== 0) return byName;
|
|
25226
|
+
return a.repo.owner.localeCompare(b.repo.owner);
|
|
25227
|
+
});
|
|
25228
|
+
return matches;
|
|
25229
|
+
}
|
|
25230
|
+
function searchOwnerGroupsByName(query, groups) {
|
|
25231
|
+
const matches = [];
|
|
25232
|
+
for (const group of groups) {
|
|
25233
|
+
const score = getMatchScore(group.owner, query);
|
|
25234
|
+
if (score === null) continue;
|
|
25235
|
+
matches.push({
|
|
25236
|
+
group,
|
|
25237
|
+
score
|
|
25238
|
+
});
|
|
25239
|
+
}
|
|
25240
|
+
matches.sort((a, b) => {
|
|
25241
|
+
if (a.score !== b.score) return a.score - b.score;
|
|
25242
|
+
if (a.group.owner.length !== b.group.owner.length) return a.group.owner.length - b.group.owner.length;
|
|
25243
|
+
return a.group.owner.localeCompare(b.group.owner);
|
|
25244
|
+
});
|
|
25245
|
+
return matches.map((match) => match.group);
|
|
25246
|
+
}
|
|
25247
|
+
//#endregion
|
|
25201
25248
|
//#region node_modules/.pnpm/react@19.2.4/node_modules/react/cjs/react-jsx-runtime.production.js
|
|
25202
25249
|
/**
|
|
25203
25250
|
* @license React
|
|
@@ -25475,28 +25522,17 @@ function buildListItems(root, groups) {
|
|
|
25475
25522
|
function searchItems(query, groups, root) {
|
|
25476
25523
|
const q = query.toLowerCase();
|
|
25477
25524
|
const items = [];
|
|
25478
|
-
const
|
|
25479
|
-
const
|
|
25480
|
-
|
|
25481
|
-
|
|
25482
|
-
|
|
25483
|
-
|
|
25484
|
-
|
|
25485
|
-
|
|
25486
|
-
|
|
25487
|
-
type: "project",
|
|
25488
|
-
label: repo.name,
|
|
25489
|
-
owner: repo.owner,
|
|
25490
|
-
path: repo.path,
|
|
25491
|
-
selectable: true
|
|
25492
|
-
}
|
|
25493
|
-
});
|
|
25494
|
-
matchedOwners.add(repo.owner);
|
|
25495
|
-
}
|
|
25496
|
-
projectMatches.sort((a, b) => a.score - b.score || a.item.label.length - b.item.label.length);
|
|
25497
|
-
const sortedProjects = projectMatches.map((m) => m.item);
|
|
25525
|
+
const projectMatches = searchReposByName(query, groups);
|
|
25526
|
+
const sortedProjects = projectMatches.map((match) => ({
|
|
25527
|
+
type: "project",
|
|
25528
|
+
label: match.repo.name,
|
|
25529
|
+
owner: match.repo.owner,
|
|
25530
|
+
path: match.repo.path,
|
|
25531
|
+
selectable: true
|
|
25532
|
+
}));
|
|
25533
|
+
const matchedOwners = new Set(projectMatches.map((match) => match.repo.owner));
|
|
25498
25534
|
if ("<root>".includes(q)) {
|
|
25499
|
-
const rootScore = "<root>"
|
|
25535
|
+
const rootScore = getMatchScore("<root>", query) ?? 3;
|
|
25500
25536
|
const rootItem = {
|
|
25501
25537
|
type: "project",
|
|
25502
25538
|
label: "<root>",
|
|
@@ -25835,9 +25871,10 @@ function resolveTarget(root, target, groups) {
|
|
|
25835
25871
|
const candidate = path.join(root, ...segments);
|
|
25836
25872
|
if (existsSync(candidate) && statSync(candidate).isDirectory()) return candidate;
|
|
25837
25873
|
}
|
|
25838
|
-
const
|
|
25839
|
-
|
|
25840
|
-
|
|
25874
|
+
const repoMatches = searchReposByName(target, groups);
|
|
25875
|
+
if (repoMatches.length) return repoMatches[0].repo.path;
|
|
25876
|
+
const ownerMatches = searchOwnerGroupsByName(target, groups);
|
|
25877
|
+
if (ownerMatches.length) return ownerMatches[0].path;
|
|
25841
25878
|
return null;
|
|
25842
25879
|
}
|
|
25843
25880
|
//#endregion
|