-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·46 lines (38 loc) · 1.15 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
#!/usr/bin/env node
require('dotenv').config()
const fs = require("fs")
const writeFile = require("writefile")
const starFetcher = require("./star-fetcher")
const starReporter = require("./star-reporter")
const args = process.argv.slice(2)
const verb = args[0]
async function main() {
if (verb === "fetch") {
const item = args[1]
if(item === "stars") {
const [owner, repo] = args[2].split("/")
console.log(`downloading stargazer data for ${owner}'s ${repo} repository`)
await starFetcher(owner, repo)
process.exit(0)
}
}
if(verb === "report") {
const item = args[1]
if(item === "stars") {
const [owner, repo] = args[2].split("/")
try {
const data = fs.readFileSync(`./star-data/${owner}-${repo}.json`)
const obj = JSON.parse(data)
const path = `./star-reports/${owner}-${repo}.csv`
const projection = await starReporter(obj)
await writeFile(path, projection)
console.log(`report saved to ${path}`)
} catch(e) {
console.error(e)
console.error("Fatal error: Could not read star data.")
process.exit(1)
}
}
}
}
main()