-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
51 lines (50 loc) · 1.45 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Level } from 'level'
import { processors } from './processor/index.mjs'
import { runTasks } from './lib/task-queue.mjs'
export async function scrape (opts = {}) {
let { state, cache, signal, ...rest } = opts
if (!signal) {
signal = (new AbortController()).signal
}
const log = (...args) => {
if (opts.quiet) {
process.stdout.write('.')
} else {
console.log('[SCRAPER]', ...args)
}
}
const cacheDb = new Level(cache ?? 'cache')
const db = new Level(state ?? 'state')
if (!opts.token?.gitlab) {
throw new Error('Gitlab token missing! Did you set the GITLAB_TOKEN environment variable?')
}
if (!opts.token?.github) {
throw new Error('Github token missing! Did you set the GITLAB_TOKEN environment variable?')
}
const outModes = ['history', 'override']
if (!outModes.includes(opts.outMode)) {
throw new Error(`Unsupported --out-mode=${opts.outMode}, suppoorted modes are: ${outModes.join(', ')}`)
}
await runTasks({
db,
cacheDb,
preferCache: false,
blessedFile: './blessed.json',
outFolder: './out',
concurrency: 10,
maxRetries: 2,
maxDepth: 5,
signal,
...rest,
processors,
extendAPI (db, api) {
return {
...api,
packages: db.sublevel('packages', { valueEncoding: 'json' }),
repos: db.sublevel('repos', { valueEncoding: 'json' }),
people: db.sublevel('people', { valueEncoding: 'json' })
}
},
log
})
}