-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
99 lines (88 loc) · 3.04 KB
/
index.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env node
const boxen = require('boxen')
const argv = require('minimist')(process.argv.slice(2))
const packageInfo = require('./package.json')
const prompts = require('prompts')
const stackFanatic = require('stack-fanatic')
const check = async opts => {
await stackFanatic
.check(opts)
.then(res => {
let status = `${res.badge} (${res.type}) - ${res.now}/${res.max} (${res.percent}%)`
if (!opts.plain) status = boxen(status, { padding: 1 })
console.log(status)
})
.catch(async err => {
if (err.message === 'Not logged in') {
console.log('You need to log in:')
const response = await prompts([
{
type: 'text',
name: 'loginEmail',
message: 'Email:',
initial: opts.loginEmail
},
{
type: 'password',
name: 'loginPassword',
message: 'Password:',
initial: opts.loginPassword
}
])
await stackFanatic
.login(Object.assign(opts, response))
.then(res => {
if (res) {
check(opts)
} else {
console.log('Something unexpected happened while attempting to log in')
}
})
.catch(err => {
console.log('Login error:', err.message)
})
} else {
console.log(err.message)
}
})
}
if (argv['help']) {
console.log(`
Usage
$ stack-fanatic
[--debug]
[--plain]
[--login-password=password1345]
[--site=https://stackoverflow.com]
[--user-data-dir=/tmp/stack-fanatic]
Options
--debug Output debugging info in the console
--login-email The email address asssociated with the Stack Overflow account that you would like to log in to
--login-password The password for the StackOverflow account that you would like to log in to
--plain Only display the badge status text, no fancy box
--site The URL for the Stack Exchange site that you would like to pull badge info from
Should include the protocol at the beginning and no trailing slash (Defaults to "https://stackoverflow.com")
--user-data-dir Directory to save session data and cache to (Defaults to ""./userData")
Examples
$ stack-fanatic
$ stack-fanatic --site=https://gamedev.stackexchange.com
$ stack-fanatic [email protected] --login-password=password1234
`)
process.exit()
}
if (argv['version']) {
console.log(`stack-fanatic-cli v${packageInfo.version} - https://github.com/kodie/stack-fanatic-cli`)
console.log('by Kodie Grantham - https://kodieg.com')
process.exit()
}
check({
debug: argv['debug'],
loginEmail: argv['login-email'],
loginPassword: argv['login-password'],
plain: argv['plain'],
puppeteerOpts: {
userDataDir: argv['user-data-dir'] ? argv['user-data-dir'] === 'false' ? false : argv['user-data-dir'] : './userData'
},
site: argv['site'] || 'https://stackoverflow.com'
})