iter(g152): ua list 增加组件全览
无参仍列包,但每行带上组件数;--components 按包分组列 id / 标题 / 演示锚点。 末尾给出总数与后续命令提示,替代「没有关键词就只能肉眼猜 id」。
This commit is contained in:
@@ -114,12 +114,24 @@ function loadIndex() {
|
||||
return JSON.parse(fs.readFileSync(INDEX_FILE, 'utf8'));
|
||||
}
|
||||
|
||||
/*** 列出全部已注册包 ***/
|
||||
function cmdList() {
|
||||
/*** 列出已注册内容:默认列包,--components 改为按包分组列全部组件(id + 标题 + 现场演示锚点) ***/
|
||||
function cmdList(args = []) {
|
||||
const { packages } = loadIndex();
|
||||
if (!packages.length) return console.log('(no packages indexed)');
|
||||
if (args.includes('--components')) {
|
||||
let total = 0;
|
||||
for (const p of packages) {
|
||||
const comps = p.docs?.components ?? [];
|
||||
if (!comps.length) continue;
|
||||
total += comps.length;
|
||||
console.log(`\n${p.name} (${comps.length})`);
|
||||
for (const c of comps) console.log(` ${String(c.id).padEnd(16)} ${c.title ?? ''}${c.demo ? ` [${c.demo}]` : ''}`);
|
||||
}
|
||||
return console.log(`\n共 ${total} 个组件;查参数:ua info <组件id>,模糊找:ua search <关键词>`);
|
||||
}
|
||||
for (const p of packages) {
|
||||
console.log(`${p.name} v${p.version} [${p.type}] ${p.description}`);
|
||||
const n = p.docs?.components?.length ?? 0;
|
||||
console.log(`${p.name} v${p.version} [${p.type}] ${n} 个组件 ${p.description}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1273,7 +1285,7 @@ switch (cmd) {
|
||||
cmdIndex();
|
||||
break;
|
||||
case 'list':
|
||||
cmdList();
|
||||
cmdList(args);
|
||||
break;
|
||||
case 'search':
|
||||
cmdSearch(args[0], args.slice(1));
|
||||
|
||||
Reference in New Issue
Block a user