Skip to content

Commit

Permalink
fix: eslint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gxr404 committed Dec 25, 2023
1 parent 47e4fad commit 7fed396
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ dist
types
node_modules
bin
test
test
temp
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"Gener",
"sourcecode",
"yuque"
],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"build:types": "tsc --emitDeclarationOnly --outDir types -p tsconfig.base.json",
"clean": "rm -rf dist types",
"np": "np",
"release": "run-s clean build np"
"release": "run-s clean build np",
"eslintLog": "eslint . > eslint.log"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/ProgressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class ProgressBar {
this.bar = new cliProgress.SingleBar({
format: 'Download [{bar}] {percentage}% | {value}/{total}',
// hideCursor: true
}, cliProgress.Presets.legacy);
}, cliProgress.Presets.legacy)
this.bar.start(this.total, this.curr)
}

Expand Down Expand Up @@ -97,7 +97,7 @@ export default class ProgressBar {
if (line <= 0) return
process.stderr.cursorTo(0)
for (let i = 0; i< line;i++){
process.stderr.moveCursor(0, -1);
process.stderr.moveCursor(0, -1)
process.stderr.clearLine(1)
}
}
Expand Down
21 changes: 10 additions & 11 deletions src/Summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class Summary {
const toc = progressItem.toc
const parentId = toc['parent_uuid']
const findRes = this.findTree(summary, parentId)
const dirNameReg = /[\\\/:\*\?"<>\|\n\r]/g
const dirNameReg = /[\\/:*?"<>|\n\r]/g
const tocText = toc.title.replace(dirNameReg, '_').replace(/\s/, '')
const item: SummaryItem = {
text: tocText,
Expand All @@ -49,8 +49,8 @@ export default class Summary {

if (typeof findRes !== 'boolean') {
if (!Array.isArray(findRes.children)) findRes.children = []
item.level = findRes.level + 1,
findRes.children!.push(item)
item.level = findRes.level + 1
findRes.children.push(item)
} else {
item.level = 1
summary.push(item)
Expand All @@ -61,16 +61,16 @@ export default class Summary {
item.link = tocType=== 'link' ? progressItem.toc.url : progressItem.path
if (typeof findRes !== 'boolean') {
if (!Array.isArray(findRes.children)) findRes.children = []
item.level = findRes.level + 1,
findRes.children!.push(item)
item.level = findRes.level + 1
findRes.children.push(item)
} else {
item.level = 1
summary.push(item)
}
}
})

let summaryContent = this.genSummaryContent(summary, '')
const summaryContent = this.genSummaryContent(summary, '')
mdContent += summaryContent
try {
await fs.writeFile(`${bookPath}/SUMMARY.md`, mdContent)
Expand All @@ -81,8 +81,7 @@ export default class Summary {
}

genSummaryContent(summary: SummaryItem[], summaryContent: string): string {
for (let i = 0; i < summary.length; i++) {
const item = summary[i]
for (const item of summary) {
if (item.type === 'title') {
summaryContent += `\n${''.padStart(item.level + 1, '#')} ${item.text}\n\n`
} else if (item.type === 'link') {
Expand All @@ -108,9 +107,9 @@ export default class Summary {
}
findTree(tree: SummaryItem[], id: string): SummaryItem | boolean {
if (!id) return false
for (let i = 0; i< tree.length; i++) {
const findRes = this.findIdItem(tree[i], id)
if (findRes) return findRes
for (const item of tree) {
const findRes = this.findIdItem(item, id)
if (findRes) return findRes
}
return false
}
Expand Down
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const getDocsMdData: TGetMdData = (params) => {
'merge_dynamic_data': String(false),
mode: 'markdown'
}
const query = new URLSearchParams(queryParams).toString();
const query = new URLSearchParams(queryParams).toString()
apiUrl = `${apiUrl}?${query}`
return axios.get<ArticleResponse.RootObject>(apiUrl, {
headers: getHeaders(token),
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function downloadArticle(params: IDownloadArticleParams, progressBar: Prog
const spinnerDiscardingStdin = ora({
text: `下载 "${articleTitle}" 的图片中...`
})
spinnerDiscardingStdin.start();
spinnerDiscardingStdin.start()
try {
mdData = await mdImg.run(mdData, {
dist: savePath,
Expand Down Expand Up @@ -126,8 +126,8 @@ async function downloadArticleList(params: IDownloadArticleListParams) {
let errArticleCount = 0
let totalArticleCount = 0
let warnArticleCount = 0
let errArticleInfo = []
let warnArticleInfo = []
const errArticleInfo = []
const warnArticleInfo = []
for (let i = 0; i < total; i++) {
const item = tocList[i]
if (typeof item.type !== 'string') continue
Expand All @@ -140,8 +140,8 @@ async function downloadArticleList(params: IDownloadArticleListParams) {
|| itemType === ARTICLE_TOC_TYPE.LINK
) {
let tempItem: KnowledgeBase.Toc | undefined = item
let pathTitleList = []
let pathIdList = []
const pathTitleList = []
const pathIdList = []
while (tempItem) {
pathTitleList.unshift(fixPath(tempItem.title))
pathIdList.unshift(tempItem.uuid)
Expand Down
32 changes: 16 additions & 16 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import randUserAgentLib from 'rand-user-agent'

function randUserAgent({ browser = 'chrome', os = 'mac os', device = 'desktop' }) {
device = device.toLowerCase()
browser = browser.toLowerCase()
os = os.toLowerCase()
let UA = randUserAgentLib(device, browser, os)
device = device.toLowerCase()
browser = browser.toLowerCase()
os = os.toLowerCase()
let UA = randUserAgentLib(device, browser, os)

if (browser === 'chrome') {
while (UA.includes('Chrome-Lighthouse')
|| UA.includes('Gener8')
|| UA.includes('HeadlessChrome')
|| UA.includes('SMTBot')) {
UA = randUserAgentLib(device, browser, os);
}
if (browser === 'chrome') {
while (UA.includes('Chrome-Lighthouse')
|| UA.includes('Gener8')
|| UA.includes('HeadlessChrome')
|| UA.includes('SMTBot')) {
UA = randUserAgentLib(device, browser, os)
}
if (browser === 'safari') {
while (UA.includes('Applebot')) {
UA = randUserAgentLib(device, browser, os);
}
}
if (browser === 'safari') {
while (UA.includes('Applebot')) {
UA = randUserAgentLib(device, browser, os)
}
return UA;
}
return UA
}

export {
Expand Down

0 comments on commit 7fed396

Please sign in to comment.