build: 缩短构建组件时CLI提示长度

- 之前展示的是完整路径 当路径过长时会导致提示信息过长 选取体验很差
- 做统一截取处理 只展示能够区分当前组件的部分
This commit is contained in:
ZiuChen 2023-05-10 17:13:34 +08:00
parent 9576cfc7df
commit bd3b452631

View File

@ -1,17 +1,23 @@
import path from 'path'
import glob from 'glob'
import { buildByEntry } from './config'
const shorten = (p: string) => path.dirname(p).replace('./registry/lib/', '')
export const builders = Object.fromEntries(
['component', 'plugin', 'doc'].map(type => {
const src = `./registry/lib/${type}s/`
return [
type,
async ({ buildAll = false } = {}) => {
const entries = glob.sync(`${src}**/index.ts`)
const entries = glob.sync(`${src}**/index.ts`).map(entry => ({
name: shorten(entry),
value: entry,
}))
if (buildAll) {
console.log(`[build all] discovered ${entries.length} ${type}s`)
return entries.map(entry => buildByEntry({ src, type, entry }))
return entries.map(({ value }) => buildByEntry({ src, type, entry: value }))
}
let entry: string
@ -25,9 +31,9 @@ export const builders = Object.fromEntries(
})
entry = await prompt.run()
} else {
;[entry] = entries
console.log(`Build target · ${entry}`)
;[{ value: entry }] = entries
}
console.log(`Build target · ${entry}`)
return [buildByEntry({ src, type, entry })]
},
]