UNPKG

850 BJavaScriptView Raw
1"use strict";
2
3const path = require(`path`);
4
5const fs = require(`fs-extra`);
6
7const axios = require(`axios`);
8
9const API_FILE = `https://unpkg.com/gatsby/apis.json`;
10const ROOT = path.join(__dirname, `..`, `..`);
11const OUTPUT_FILE = path.join(ROOT, `latest-apis.json`);
12
13module.exports = async function getLatestAPI() {
14 try {
15 const {
16 data
17 } = await axios.get(API_FILE, {
18 timeout: 5000
19 });
20 await fs.writeFile(OUTPUT_FILE, JSON.stringify(data, null, 2), `utf8`);
21 return data;
22 } catch (e) {
23 if (await fs.exists(OUTPUT_FILE)) {
24 return fs.readJSON(OUTPUT_FILE);
25 } // possible offline/network issue
26
27
28 return fs.readJSON(path.join(ROOT, `apis.json`)).catch(() => {
29 return {
30 browser: {},
31 node: {},
32 ssr: {}
33 };
34 });
35 }
36};
37//# sourceMappingURL=get-latest-apis.js.map
\No newline at end of file