Skip to content

Commit

Permalink
Merge branch 'dev' into npm
Browse files Browse the repository at this point in the history
  • Loading branch information
vannvan committed Sep 7, 2023
2 parents 249e3ae + baeaf14 commit e2deeba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yuque-tools",
"version": "2.1.1",
"version": "2.1.2",
"description": "语雀知识库内容批量导出和二次处理工具",
"keywords": [
"yuque",
Expand Down
23 changes: 20 additions & 3 deletions src/lib/dev/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@ const issuesLink = 'https://github.com/vannvan/yuque-tools/issues/new'
* 打印日志
*/
export const Log = {
error: (text: string) => {
const link = terminalLink('👉提个bug', issuesLink)
log(chalk.red(text + ' '.repeat(4) + link))
error: (text: string, info?: { title: string; body: string }) => {
const stack = new Error().stack
const errorBody = [
`Node: ${process.versions.node} OS: ${process.platform}`,
`错误信息: ${info.body}\n${stack}\n`,
`以上信息可删除路径等隐私信息,但需要保留之后的行数哦~`,
]

const errorInfo = {
title: 'Error上报/' + info.title,
body: errorBody.join('\n'),
}
const queryString = new URLSearchParams(Object.entries(errorInfo)).toString()
const link = terminalLink('👉提个BUG(cmd/ctrl+click)', `${issuesLink}?${queryString}`)
if (info) {
log(chalk.red(text + ' '.repeat(4) + link))
process.exit(1)
} else {
log(chalk.red(text))
}
},
info: (text: string, indent?: number) => {
indent ? log(chalk.white(' '.repeat(indent) + text)) : log(chalk.white(text))
Expand Down
4 changes: 2 additions & 2 deletions src/lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const get = <T>(url: string): Promise<{ data: T }> => {
resolve(res.data)
})
.catch((error) => {
Log.error(error.code)
Log.error(error.code, { title: 'GET请求报错', body: error })
reject(error.code)
})
})
Expand Down Expand Up @@ -63,7 +63,7 @@ export const post = <T>(url: string, params: any, header?: object): Promise<{ da
resolve(res.data)
})
.catch((error) => {
Log.error(error.code)
Log.error(error.code, { title: 'POST请求报错', body: error })
reject(error.code)
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const delayedGetDocCommands = (
typeof finishCallBack === 'function' && finishCallBack(bookList)
})
.catch((error) => {
Log.error(error)
Log.error(error, { title: '知识库数据获取报错', body: error })
})
}

Expand Down

0 comments on commit e2deeba

Please sign in to comment.