diff --git a/src/commands/info/index.ts b/src/commands/info/index.ts index 76c34d3..847b165 100644 --- a/src/commands/info/index.ts +++ b/src/commands/info/index.ts @@ -2,6 +2,8 @@ import process from 'node:process' import { execSync } from 'node:child_process' import { getPackageInfo } from 'local-pkg' import envinfo from 'envinfo' + +// import { link } from 'kolorist' import { ora } from '../../utils' import { question } from './question' @@ -16,20 +18,34 @@ async function getuniHelperDependencies() { return uniHelperDependencies } -async function findDependenciesVersionAndBugs(name: string) { +async function getDependenciesVersionAndBugs(name: string) { const { version, packageJson } = (await getPackageInfo(name))! const bugs = typeof packageJson?.bugs === 'string' ? packageJson.bugs : packageJson.bugs?.url return { version, bugs } } +async function getBaseDependencies() { + const baseDependenciesName = ['vue', 'vite', '@dcloudio/uni-app'] + const baseDependencies = [] + for (const name of baseDependenciesName) { + const packageInfo = await getPackageInfo(name) + baseDependencies.push({ + name, + version: packageInfo?.version, + }) + } + + return baseDependencies +} + async function getErrorDependencies() { const uniHelperDependencies = await getuniHelperDependencies() - const { errorIndexList } = await question(uniHelperDependencies) + const { errorIndexList } = await question(uniHelperDependencies, '请选择需要反馈的依赖') const errorDependencies = [] for (const index of errorIndexList) { const name = uniHelperDependencies[index] - const { version, bugs } = await findDependenciesVersionAndBugs(name) + const { version, bugs } = await getDependenciesVersionAndBugs(name) errorDependencies.push({ name, version, bugs }) } return errorDependencies @@ -46,8 +62,8 @@ async function getVSCodeInfo() { } } -function getVSCodeExtensions() { - const list = execSync('code --list-extensions --show-versions') +function getVSCodeExtensions(path: string) { + const list = execSync(`${path} --list-extensions --show-versions`) return list.toString().split(/\r?\n/).filter(line => line.trim() !== '') } @@ -65,15 +81,14 @@ function paserExtensionList(list: string[]) { } async function getErrorExtensions() { - console.log(111) const loading = ora('正在获取插件信息...').start() - await getVSCodeInfo() - const extensions = getVSCodeExtensions() + const { path } = (await getVSCodeInfo())! + const extensions = getVSCodeExtensions(path) const uniHelperExtensions = paserExtensionList(getUniHelperExtensions(extensions)) const choices = uniHelperExtensions.map(item => item.name) - loading.succeed('获取插件信息成功') + loading.finish() - const { errorIndexList } = await question(choices) + const { errorIndexList } = await question(choices, '请选择需要反馈的vscode插件') return errorIndexList.map((index: number) => { return { @@ -84,10 +99,34 @@ async function getErrorExtensions() { }) } +export async function getBaseEnvInfo() { + const os = (await envinfo.helpers.getOSInfo())?.[1] + const node = (await envinfo.helpers.getNodeInfo())?.[1] + const vscode = (await getVSCodeInfo())?.version + return { + os, + node, + vscode, + } +} + export async function getUniAppInfo() { const errorDependencies = await getErrorDependencies() - console.log(errorDependencies) const errorExtensions = await getErrorExtensions() - console.log(errorExtensions) + const baseEnvInfo = await getBaseEnvInfo() + const baseDependencies = await getBaseDependencies() + console.log('\n') + console.log('基础环境信息:') + console.table(baseEnvInfo) + console.log('\n') + console.log('基础依赖信息:') + console.table(baseDependencies) + console.log('\n') + console.log('uni-helper依赖信息:') + console.table(errorDependencies) + console.log('\n') + console.log('uni-helper插件信息:') + console.table(errorExtensions) + console.log('\n') process.exit(0) } diff --git a/src/commands/info/question/index.ts b/src/commands/info/question/index.ts index 4dcea0f..dcc1395 100644 --- a/src/commands/info/question/index.ts +++ b/src/commands/info/question/index.ts @@ -3,14 +3,14 @@ import prompts from 'prompts' import { bold, gray, red } from 'kolorist' import figures from 'prompts/lib/util/figures.js' -export async function question(choices: string[]) { +export async function question(choices: string[], message: string) { const instructions = gray('使用↑↓选择,空格或←→选中,a全选,回车确认') const questions = [ { name: 'errorIndexList', type: 'multiselect', - message: '请选择遇到问题的库?', + message, instructions, choices, }, diff --git a/src/utils/loading.ts b/src/utils/loading.ts index 03a7b0f..66e10b9 100644 --- a/src/utils/loading.ts +++ b/src/utils/loading.ts @@ -38,6 +38,13 @@ export class Ora { clearInterval(this.interval) process.stdout.write('\r' + `${green(figures.tick)} ${this.setFinishMessage(message)}\n`) } + + finish(): void { + if (!this.interval) + return + clearInterval(this.interval) + process.stdout.write('') + } } export function ora(message: string) {