Skip to content

Commit

Permalink
feat: format print info
Browse files Browse the repository at this point in the history
  • Loading branch information
FliPPeDround committed Apr 13, 2024
1 parent f88c2aa commit 879a464
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 23 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
npm create uni <项目名称> --ts -m pinia -m uniUse -u ano -e
```

```shell
npm create uni --info
# --info 获取当前项目环境信息
```

### 参数说明

| 配置项 | 参数 | 别名 | 可选值 |
Expand All @@ -49,6 +54,7 @@ npm create uni <项目名称> --ts -m pinia -m uniUse -u ano -e
| Module | moduleList | m |[模块列表](#模块列表) |
| UI | ui | u | uni/ano |
| Eslint | eslint | e | —— |
| info | info | —— | —— |

#### 📦插件列表

Expand Down
92 changes: 70 additions & 22 deletions src/commands/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ 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 { gray, link } from 'kolorist'
import { ora } from '../../utils'
import { question } from './question'

Expand Down Expand Up @@ -63,14 +62,24 @@ async function getVSCodeInfo() {
}

function getVSCodeExtensions(path: string) {
const list = execSync(`${path} --list-extensions --show-versions`)
let list
try {
list = execSync(`code --list-extensions --show-versions`)
}
catch (error) {
list = execSync(`${path} --list-extensions --show-versions`)
}
return list.toString().split(/\r?\n/).filter(line => line.trim() !== '')
}

function getUniHelperExtensions(extensions: string[]) {
return extensions.filter(item => item.includes('uni-helper.') || item.includes('mrmaoddxxaa.create-uniapp-view'))
}

function getVolarExtensions(extensions: string[]) {
return extensions.filter(item => item.includes('vue.volar'))
}

function paserExtensionList(list: string[]) {
return list.map((item) => {
const [name_, version] = item.split('@')
Expand All @@ -85,18 +94,22 @@ async function getErrorExtensions() {
const { path } = (await getVSCodeInfo())!
const extensions = getVSCodeExtensions(path)
const uniHelperExtensions = paserExtensionList(getUniHelperExtensions(extensions))
const volarExtensions = paserExtensionList(getVolarExtensions(extensions))
const choices = uniHelperExtensions.map(item => item.name)
loading.finish()

const { errorIndexList } = await question(choices, '请选择需要反馈的vscode插件')

return errorIndexList.map((index: number) => {
return {
name: uniHelperExtensions[index].name,
version: uniHelperExtensions[index].version,
bugs: uniHelperExtensions[index].bugs,
}
})
return {
errorExtensions: errorIndexList.map((index: number) => {
return {
name: uniHelperExtensions[index].name,
version: uniHelperExtensions[index].version,
bugs: uniHelperExtensions[index].bugs,
}
}),
volarExtensions,
}
}

export async function getBaseEnvInfo() {
Expand All @@ -112,21 +125,56 @@ export async function getBaseEnvInfo() {

export async function getUniAppInfo() {
const errorDependencies = await getErrorDependencies()
const errorExtensions = await getErrorExtensions()
const { errorExtensions, volarExtensions } = await getErrorExtensions()
const baseEnvInfo = await getBaseEnvInfo()
const baseDependencies = await getBaseDependencies()
console.log('\n')
const splitter = '----------------------------------------------'

let baseEnvInfoStr = ''
for (const [key, value] of Object.entries(baseEnvInfo))
baseEnvInfoStr += `- ${key}: \`${value}\`\n`
for (const { name, version } of volarExtensions)
baseEnvInfoStr += `- ${name}: \`${version}\`\n`

let baseDependenciesStr = ''
for (const { name, version } of baseDependencies)
baseDependenciesStr += `- ${name}: \`${version}\`\n`

let errorDependenciesStr = ''
for (const { name, version, bugs } of errorDependencies)
errorDependenciesStr += `- ${link(name, bugs!)}: \`${version}\`\n`

let errorExtensionsStr = ''
for (const { name, version, bugs } of errorExtensions)
errorExtensionsStr += `- ${link(name, bugs)}: \`${version}\`\n`

console.log(splitter)

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log()

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

View workflow job for this annotation

GitHub Actions / lint

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

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.table(baseEnvInfo)
console.log('\n')
console.table(baseEnvInfoStr)

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

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

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
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')
console.log(baseDependenciesStr)

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

if (errorDependencies.length > 0) {
console.log('uni-helper依赖信息:')

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log(errorDependenciesStr)

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}

if (errorExtensions.length > 0) {
console.log('uni-helper插件信息:')

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log(errorExtensionsStr)

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}

console.log(splitter)

console.log(
`${[
gray('感谢使用uni-helper,请提供以上信息以便我们排查问题。'),
'👉 uni-help官网: https://uni-helper.js.org/',
'👉 改进建议: https://github.com/uni-helper/create-uni/issues/new/choose',
].join('\n')}\n`,
)

process.exit(0)
}
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { join, resolve } from 'node:path'
import process from 'node:process'
import ejs from 'ejs'
import { bold, red } from 'kolorist'
import { bold, green, red } from 'kolorist'
import minimist from 'minimist'
import prompts from 'prompts'
import figures from 'prompts/lib/util/figures.js'
Expand Down Expand Up @@ -253,5 +253,7 @@ async function init() {

init().catch(() => {
console.log(`${red(figures.cross)} ${bold('操作已取消')}`)
console.log()
console.log(`🚀 遇到问题? 快速反馈:${green('https://github.com/uni-helper/create-uni/issues/new/choose')}`)
process.exit(0)
})

0 comments on commit 879a464

Please sign in to comment.