Skip to content

Commit

Permalink
feat: get env info
Browse files Browse the repository at this point in the history
  • Loading branch information
FliPPeDround committed Apr 12, 2024
1 parent f2f436d commit f88c2aa
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
63 changes: 51 additions & 12 deletions src/commands/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
Expand All @@ -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() !== '')
}

Expand All @@ -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 {
Expand All @@ -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')

Check warning on line 118 in src/commands/info/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log('基础环境信息:')

Check warning on line 119 in src/commands/info/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.table(baseEnvInfo)

Check warning on line 120 in src/commands/info/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log('\n')

Check warning on line 121 in src/commands/info/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log('基础依赖信息:')

Check warning on line 122 in src/commands/info/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.table(baseDependencies)

Check warning on line 123 in src/commands/info/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log('\n')

Check warning on line 124 in src/commands/info/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log('uni-helper依赖信息:')

Check warning on line 125 in src/commands/info/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.table(errorDependencies)

Check warning on line 126 in src/commands/info/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log('\n')

Check warning on line 127 in src/commands/info/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log('uni-helper插件信息:')
console.table(errorExtensions)
console.log('\n')
process.exit(0)
}
4 changes: 2 additions & 2 deletions src/commands/info/question/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
7 changes: 7 additions & 0 deletions src/utils/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f88c2aa

Please sign in to comment.