Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update dependency crawler to v2 #241

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
node-version: [18, 20, 22]
steps:
- name: Checkout project
uses: actions/checkout@v4
Expand Down
2,963 changes: 1,331 additions & 1,632 deletions .pnp.cjs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
"@types/sax": "1.2.7",
"@types/source-map-support": "0.5.10",
"axios": "1.7.2",
"cheerio": "1.0.0-rc.12",
"commitizen": "4.3.0",
"concurrently": "8.2.2",
"crawler": "1.5.0",
"crawler": "2.0.2",
"cz-conventional-changelog": "3.3.0",
"dotenv-extended": "2.9.0",
"husky": "9.1.1",
Expand Down Expand Up @@ -74,7 +75,6 @@
}
},
"dependencies": {
"@types/crawler": "1.2.6",
"assert-never": "^1.2.1",
"google-auth-library": "9.11.0",
"soap": "1.1.0",
Expand Down
83 changes: 45 additions & 38 deletions src/build/wsdl.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,55 @@
import axios from 'axios'
import Crawler from 'crawler'
import { mkdirp } from 'mkdirp'
import { writeFile } from 'node:fs/promises'
import { basePath, baseURL, origin } from './wsdl-path'
import { CheerioAPI } from 'cheerio'
;(async () => {
const { default: Crawler } = await import('crawler')

const crawler = new Crawler({
maxConnections: 1,
callback: async (error, res, done) => {
if (error) {
console.error(error)
return done()
}
const crawler = new Crawler({
maxConnections: 1,
callback: async (error, res, done) => {
if (typeof done !== 'function')
throw new Error('`done` is not a function.')

const elements = res.$(`a[href$="?wsdl"]`)
if (error) {
console.error(error)
return done()
}

if (!elements.length) {
console.error(`Cannot find any WSDLs`)
return done()
}
const $: CheerioAPI = res.$
const elements = $(`a[href$="?wsdl"]`)

try {
await Promise.all(
elements.toArray().map(async (element) => {
const $element = res.$(element)
const title = $element.text()
const url = origin + $element.attr('href')
const versionRegExp = new RegExp(`${basePath}/([v0-9]+)/`)
const versionMatch = versionRegExp.exec(url)
if (!versionMatch) {
console.error(`Could not find a version in ${url}`)
return
}
const [, version] = versionMatch
await mkdirp(`src/wsdl/${version}`)
const response = await axios.get(url)
await writeFile(`src/wsdl/${version}/${title}.wsdl`, response.data)
}),
)
} catch (error) {
console.error(error)
}
if (!elements.length) {
console.error(`Cannot find any WSDLs`)
return done()
}

done()
},
})
try {
await Promise.all(
elements.toArray().map(async (element) => {
const $element = res.$(element)
const title = $element.text()
const url = origin + $element.attr('href')
const versionRegExp = new RegExp(`${basePath}/([v0-9]+)/`)
const versionMatch = versionRegExp.exec(url)
if (!versionMatch) {
console.error(`Could not find a version in ${url}`)
return
}
const [, version] = versionMatch
await mkdirp(`src/wsdl/${version}`)
const response = await axios.get(url)
await writeFile(`src/wsdl/${version}/${title}.wsdl`, response.data)
}),
)
} catch (error) {
console.error(error)
}

crawler.queue(baseURL)
done()
},
})

crawler.queue(baseURL)
})()
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"importHelpers": true,
"incremental": true,
"lib": ["ESNext"],
"module": "Node16",
"moduleResolution": "Node16",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noImplicitOverride": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
Expand Down
Loading