-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull.mjs
28 lines (21 loc) · 821 Bytes
/
pull.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
// Make a http request to https://api.lightsouts.com/v1/series/formula-1
import axios from "axios";
import fs from "fs";
import jsonDiff from "json-diff";
import { createInterface } from "readline";
const data = await axios.get("https://api.lightsouts.com/v1/series/formula-1");
const events = data.data.events;
// Show difference between current file and new file
const old = fs.readFileSync("./src/events.json", "utf8");
console.dir(jsonDiff.diffString(JSON.parse(old), events), { depth: null });
// Take user input for overriding the file
const readline = createInterface({
input: process.stdin,
output: process.stdout,
});
readline.question("Override events.json? (y/n) ", (answer) => {
if (answer === "y") {
fs.writeFileSync("./src/events.json", JSON.stringify(events));
}
readline.close();
});