-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwriteEnums.js
63 lines (57 loc) · 1.31 KB
/
writeEnums.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
// import axiosInstance from './util/axiosInstance';
const axios = require("axios");
const config = require("./src/env");
const _ = require("lodash");
const fs = require("fs");
const enums = [
"frequency",
"datasettype",
"dataformat",
"datasetorigin",
"rank",
"taxonomicstatus",
"infoGroup",
"taxGroup",
"issue",
"nametype",
"namefield",
"nomstatus",
"license",
"nomcode",
"importstate",
"environment",
"importstate",
"country",
"estimatetype",
"setting",
"Gazetteer",
"entitytype",
"speciesinteractiontype",
"doiresolution"
];
let env;
try {
console.log("process.env.NODE_ENV: " + process?.env?.NODE_ENV);
env = _.get(config, process?.env?.NODE_ENV, config.prod);
} catch (err) {
env = config.prod;
}
const writeEnums = () => {
console.log(`Retrieving enumerations from ${env.env} API: ${env.dataApi}`);
enums.map((e) =>
axios(`${env.dataApi}vocab/${e}`).then(({ data }) =>
fs.writeFile(
`${__dirname}/src/enumeration/${e}.json`,
JSON.stringify(data, null, 2),
(err) => {
if (err) throw err;
console.log(`Writing ${e}.json`);
}
)
).catch(error => {
console.log(`Error retrieving ${e}`)
console.log(`Status ${error?.response?.status} ${error?.response?.statusText}`)
})
);
};
writeEnums();