-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.js
65 lines (56 loc) · 1.19 KB
/
init.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
import readline from 'readline';
import fs from 'fs';
import fetch from 'node-fetch';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const GRAPHQL_QUERY = username => `{
user(username: "${username}") {
username
name
tagline
isEvangelist
numFollowers
numFollowing
numPosts
numReactions
socialMedia {
twitter
github
stackoverflow
linkedin
google
facebook
website
}
photo
coverImage
blogHandle
publicationDomain
}
}`;
console.log(`
Thanks for using Hanna!
This CLI tool will help you set up your Hanna instance.
It will fetch your hashnode account data.
`);
rl.question('What is you hashnode username? ', async answer => {
const res = await fetch('https://api.hashnode.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: GRAPHQL_QUERY(answer),
}),
});
const {data: {user}} = await res.json();
if (user.name === undefined || user.name === null) {
console.log('Invalid username!');
process.exit(1);
}
console.log('Fetched user.');
fs.writeFileSync('src/lib/data/user.json', JSON.stringify(user, null, 2));
rl.close();
})