-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathgetAPIListData.js
More file actions
37 lines (31 loc) · 1.07 KB
/
Copy pathgetAPIListData.js
File metadata and controls
37 lines (31 loc) · 1.07 KB
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
const fs = require("fs");
const path = require("path");
const directoryPath = path.join(__dirname, "../api");
const generatedListPath = path.join(__dirname, "../GeneratedAPIList.js");
const buildAPIListData = () => {
const files = fs.readdirSync(directoryPath).filter((f) => !f.includes(".backup"));
return files.map((file) => {
const data = JSON.parse(fs.readFileSync(path.join(directoryPath, file)));
const endpoints = Object.keys(data);
const metaData = data.metaData[0];
const name = file.split(".")[0].toLowerCase();
return {
name,
link: name,
metaData,
endpoints: endpoints.filter((e) => e != "metaData"),
};
});
};
const getAPIListData = async () => buildAPIListData();
const generateAPIListData = async () => {
const apiData = buildAPIListData();
// Resolve against __dirname so regeneration doesn't depend on the process cwd.
const jsFileData = `module.exports = ${JSON.stringify(apiData)}`;
fs.writeFileSync(generatedListPath, jsFileData);
return true;
};
module.exports = {
getAPIListData,
generateAPIListData,
};