Skip to content

Commit c6b5663

Browse files
committed
chore: merge to fix logger
1 parent 7d07e0b commit c6b5663

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+236
-198
lines changed

.commitlintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
extends: ['@commitlint/config-conventional']
2+
extends: ['@commitlint/config-conventional'],
33
}

.eslintrc.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ module.exports = {
22
env: {
33
browser: true,
44
commonjs: true,
5-
es2021: true
5+
es2021: true,
66
},
77
extends: '@antfu',
88
overrides: [
99
{
1010
env: {
11-
node: true
11+
node: true,
1212
},
1313
files: ['.eslintrc.{js,cjs}'],
1414
parserOptions: {
15-
sourceType: 'script'
16-
}
17-
}
15+
sourceType: 'script',
16+
},
17+
},
1818
],
1919
parserOptions: {
20-
ecmaVersion: 'latest'
20+
ecmaVersion: 'latest',
2121
},
22-
rules: {}
22+
rules: {},
2323
}

bin/lc.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { easyLanguageView } from '#common/view/language.view.js'
1919
import { DefaultVer } from '#common/constants/question.const.js'
2020
import {
2121
create,
22-
createQuestionById
22+
createQuestionById,
2323
} from '#common/utils/create-check/createUtil.js'
2424
import { logger } from '#common/utils/logger/logger.js'
2525

@@ -37,7 +37,7 @@ program
3737
.option('-l, --language [language]', 'Set/Get the code language of question.')
3838
.option(
3939
'-u, --update',
40-
'Check the version to determine whether to update to the latest one.'
40+
'Check the version to determine whether to update to the latest one.',
4141
)
4242
.parse(process.argv)
4343

@@ -57,7 +57,8 @@ const cmdOpts = program.opts()
5757
if (cmdOpts.language) {
5858
if (cmdOpts.language !== true) {
5959
await easyLanguageView(cmdOpts.language)
60-
} else {
60+
}
61+
else {
6162
const lang = await getQuestionLanguage()
6263
logger.info(`当前CLI语言环境为:${lang}`)
6364
}
@@ -97,7 +98,7 @@ export const callModeAction = {
9798
identity: async (id) => {
9899
await createQuestionById(id, baseDir)
99100
process.exit(0)
100-
}
101+
},
101102
}
102103
// 获取模式和参数
103104
const mode = referMode(cmdArgs, cmdOpts)

bin/lf.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ program
2121
.option('-d, --directory <directory>', 'Set the question directory.')
2222
.option(
2323
'-u, --update',
24-
'Check the version to determine whether to update to the latest one.'
24+
'Check the version to determine whether to update to the latest one.',
2525
)
2626
.parse(process.argv)
2727

@@ -36,7 +36,8 @@ const cmdOpts = program.opts()
3636
if (cmdOpts.language) {
3737
if (cmdOpts.language !== true) {
3838
await easyLanguageView(cmdOpts.language)
39-
} else {
39+
}
40+
else {
4041
const lang = await getQuestionLanguage()
4142
logger.info(`当前CLI语言环境为:${lang}`)
4243
}

common/structures/ListNode.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export class ListNode {
1212
}
1313

1414
static parse(arr) {
15-
if (arr.length === 0) return null // Return null for an empty array
15+
if (arr.length === 0)
16+
return null // Return null for an empty array
1617

1718
const head = new ListNode(arr.shift(), null)
1819
let current = head
@@ -24,7 +25,8 @@ export class ListNode {
2425
}
2526

2627
static toArray(listNodes, arr = []) {
27-
if (listNodes === undefined || listNodes === null) return arr
28+
if (listNodes === undefined || listNodes === null)
29+
return arr
2830

2931
arr.push(listNodes.val)
3032
return ListNode.toArray(listNodes.next, arr)

common/structures/Node.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ export class Node {
3030
}
3131

3232
static toArray(node) {
33-
if (!node) return []
33+
if (!node)
34+
return []
3435

3536
const visited = new Set()
3637
const result = []
3738

3839
const dfs = (currentNode) => {
39-
if (visited.has(currentNode.val)) return
40+
if (visited.has(currentNode.val))
41+
return
4042

4143
const { neighbors, val } = currentNode
4244
visited.add(val)

common/structures/TreeNode.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export class TreeNode {
77
}
88

99
static parse(arr) {
10-
if (arr.length === 0) return null
10+
if (arr.length === 0)
11+
return null
1112
const root = new TreeNode(arr[0])
1213
const queue = [root]
1314
for (let i = 1; i < arr.length; i += 2) {
@@ -26,7 +27,8 @@ export class TreeNode {
2627

2728
static toArray(treeNode) {
2829
const result = []
29-
if (!treeNode) return result
30+
if (!treeNode)
31+
return result
3032

3133
const queue = [treeNode]
3234

@@ -36,7 +38,8 @@ export class TreeNode {
3638
result.push(node.val)
3739
queue.push(node.left)
3840
queue.push(node.right)
39-
} else {
41+
}
42+
else {
4043
result.push(null)
4144
}
4245
}
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// 推测模式
22
export function referMode(args, opts) {
3-
if (args.length > 0 || opts.identity) return 'identity'
3+
if (args.length > 0 || opts.identity)
4+
return 'identity'
45

5-
if (opts.random) return 'random'
6+
if (opts.random)
7+
return 'random'
68

79
return 'today'
810
}

common/utils/etc/createColorFont.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export function createColorFont(font) {
77
const code = gradient_string([
88
{ color: '#ff0000', pos: 0 },
99
{ color: '#ffc600', pos: 0.5 },
10-
{ color: '#003dff', pos: 1 }
10+
{ color: '#003dff', pos: 1 },
1111
])(font)
1212
writeFileSync(path.resolve(process.cwd(), 'colorFont.js'), code)
1313
console.log(
14-
`[ColorFont]Create color font: ${font}\ncode location:${path.resolve(process.cwd(), 'colorFont.js')}`
14+
`[ColorFont]Create color font: ${font}\ncode location:${path.resolve(process.cwd(), 'colorFont.js')}`,
1515
)
1616
console.log(code)
1717
}

common/utils/etc/typeof_.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @private
66
*/
77
export function typeof_(data) {
8-
if (data === null) return 'null'
8+
if (data === null)
9+
return 'null'
910
else return typeof data
1011
}

common/utils/file/getCountBySameName.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import { readdirSync } from 'node:fs'
77
* @returns {number}
88
*/
99
export function getCountBySameName(dir, name) {
10-
return readdirSync(dir).filter((filename) => filename.includes(name)).length
10+
return readdirSync(dir).filter(filename => filename.includes(name)).length
1111
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readdirSync } from 'node:fs'
22

33
export function getFileListBySameName(dir, name) {
4-
return readdirSync(dir).filter((filename) => filename.includes(name))
4+
return readdirSync(dir).filter(filename => filename.includes(name))
55
}

common/utils/file/getFilePathById.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import fs from 'node:fs'
88
*/
99
export function getFilePathById(id, baseDir = process.cwd()) {
1010
const dir = fs.readdirSync(baseDir)
11-
const files = dir.filter((o) => o.startsWith(`${id}.`))
12-
if (files.length > 1) return files
11+
const files = dir.filter(o => o.startsWith(`${id}.`))
12+
if (files.length > 1)
13+
return files
1314
return files?.[0]
1415
}

common/utils/file/getRootPath.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { __dirname } from '#common/utils/file/getDirname.js'
33
import { currentEnv } from '#common/utils/etc/checkEnv.js'
44

55
// 在cli环境下 执行目录为 bin 目录 根目录就是上一层目录
6-
export const rootPath =
7-
currentEnv() === 'project'
6+
export const rootPath
7+
= currentEnv() === 'project'
88
? path.dirname(path.dirname(path.dirname(__dirname)))
99
: path.dirname(__dirname)

common/utils/functions/isSameData.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
export function isSameData(a, b) {
88
const typeA = typeof a
99
const typeB = typeof b
10-
if (typeA !== typeB) return false
10+
if (typeA !== typeB)
11+
return false
1112
switch (typeA) {
1213
case 'bigint':
1314
case 'boolean':
@@ -19,12 +20,14 @@ export function isSameData(a, b) {
1920
case 'function':
2021
return a.toString() === b.toString()
2122
case 'object': {
22-
if (a === null || a === undefined) return a === b
23+
if (a === null || a === undefined)
24+
return a === b
2325

2426
const keysA = Object.keys(a)
2527
const keysB = Object.keys(b)
26-
if (keysA.length !== keysB.length) return false
27-
return keysA.every((key) => isSameData(a[key], b[key]))
28+
if (keysA.length !== keysB.length)
29+
return false
30+
return keysA.every(key => isSameData(a[key], b[key]))
2831
}
2932
}
3033
}

common/utils/functions/sizeUtil.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ export const PB = 1024 * GB
1515
* @return {size: number, label: string}
1616
*/
1717
export function getFileSizeUnit(size) {
18-
if (size < KB) return { size: 1, label: 'B' }
19-
if (size < MB) return { size: KB, label: 'KB' }
20-
if (size < GB) return { size: MB, label: 'MB' }
21-
if (size < TB) return { size: GB, label: 'GB' }
22-
if (size < PB) return { size: TB, label: 'TB' }
18+
if (size < KB)
19+
return { size: 1, label: 'B' }
20+
if (size < MB)
21+
return { size: KB, label: 'KB' }
22+
if (size < GB)
23+
return { size: MB, label: 'MB' }
24+
if (size < TB)
25+
return { size: GB, label: 'GB' }
26+
if (size < PB)
27+
return { size: TB, label: 'TB' }
2328

2429
return { size: PB, label: 'PB' }
2530
}

common/utils/http/fetch_.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
* @private
77
*/
88
export async function fetch_(url, options) {
9-
return await fetch(url, options).then((res) => res.json())
9+
return await fetch(url, options).then(res => res.json())
1010
}

common/utils/question-getter/getPlanQuestionList.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getPlanQuestionListJson } from '#resources/headers/planQuestionListJson
44
export async function getPlanQuestionList(slug) {
55
const res = await graphql(getPlanQuestionListJson(slug))
66
const {
7-
data: { studyPlanV2Detail }
7+
data: { studyPlanV2Detail },
88
} = res
99
return studyPlanV2Detail
1010
}

common/utils/question-getter/getQuestionById.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { graphql } from '#common/utils/http/graphql.js'
55
export async function getQuestionById(id) {
66
const base = await graphql(getQuestionSearchJson(id.toString()))
77
const questionContent = base?.data?.problemsetQuestionList?.questions?.find(
8-
(o) => o?.frontendQuestionId === id.toString()
8+
o => o?.frontendQuestionId === id.toString(),
99
)
1010
if (!questionContent) {
1111
return {
12-
id: null
12+
id: null,
1313
}
1414
}
1515
const slug = questionContent.titleSlug

common/utils/question-getter/getQuestionRandom.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function getQuestionRandom() {
77
const id = await getRandomId()
88
const base = await graphql(getQuestionSearchJson(id.toString()))
99
const slug = base.data.problemsetQuestionList.questions.find(
10-
(o) => o.frontendQuestionId === id.toString()
10+
o => o.frontendQuestionId === id.toString(),
1111
).titleSlug
1212
const question = await getQuestionDetail(slug)
1313
return question

common/utils/question-getter/getStudyPlanList.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getStudyPlanListJson } from '#resources/headers/studyPlanListJson.js'
44
export async function getStudyPlanList() {
55
const res = await graphql(getStudyPlanListJson())
66
const {
7-
data: { studyPlansV2AdQuestionPage }
7+
data: { studyPlansV2AdQuestionPage },
88
} = res
99
return studyPlansV2AdQuestionPage
1010
}

common/utils/question-handler/checkQuestion.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function checkQuestion(path) {
2323
path,
2424
vm.createContext({
2525
showLogs,
26-
console
27-
})
26+
console,
27+
}),
2828
)
2929
}

common/utils/question-handler/code.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs'
22
import { getQuestionCodeList } from '#common/utils/question-getter/getQuestionCodeList.js'
33
import {
44
getLangByExtension,
5-
setLineComment
5+
setLineComment,
66
} from '#common/utils/question-handler/questionLanguage.js'
77
import { DefaultLang } from '#common/constants/question.const.js'
88

@@ -14,7 +14,7 @@ import { DefaultLang } from '#common/constants/question.const.js'
1414
*/
1515
export async function getCodeBySlug(slug, lang) {
1616
const list = await getQuestionCodeList(slug)
17-
return list.find((o) => o.langSlug === lang)?.code
17+
return list.find(o => o.langSlug === lang)?.code
1818
}
1919
/**
2020
* 获取支持的代码语言
@@ -23,7 +23,7 @@ export async function getCodeBySlug(slug, lang) {
2323
*/
2424
export async function getSupportCode(slug) {
2525
const list = await getQuestionCodeList(slug)
26-
return list.map((code) => code?.langSlug)
26+
return list.map(code => code?.langSlug)
2727
}
2828

2929
/**
@@ -36,12 +36,12 @@ export function getCodeRange(lang, code) {
3636
if (!code) {
3737
return setLineComment(
3838
lang,
39-
`!important: 此题目没有当前语言[${lang}]的代码模板!`
39+
`!important: 此题目没有当前语言[${lang}]的代码模板!`,
4040
)
4141
}
4242
return `${setLineComment(lang, '@QUESTION_START') + code}\n${setLineComment(
4343
lang,
44-
'@QUESTION_END'
44+
'@QUESTION_END',
4545
)}`
4646
}
4747
/**
@@ -55,6 +55,7 @@ export function getCodeInFile(filePath) {
5555
const rangeReg = new RegExp(`${startTag}.*${endTag}`, 'ms')
5656
const rangeTagReg = new RegExp(`(${startTag}|${endTag})+`, 'mg')
5757
const match = data.match(rangeReg)
58-
if (!match) return null
58+
if (!match)
59+
return null
5960
return match[0]?.replace(rangeTagReg, '')
6061
}

0 commit comments

Comments
 (0)