-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbSeed.js
31 lines (30 loc) · 955 Bytes
/
dbSeed.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
const Language = require("./models/Language");
const dbConnect = require("./dbConnect");
const fs = require("fs");
const path = require("path");
(async () => {
await dbConnect();
const languages = await Language.find({});
if (languages.length) {
return;
}
const languagesFromGitHub = JSON.parse(
fs.readFileSync(
path.join(__dirname, "./data/languages-from-github.json"),
"utf8"
)
);
const languagesToAdd = Object.keys(languagesFromGitHub).map((key) => {
const name = key;
const iconKey = languagesFromGitHub[key];
const iconUrl = `https://github.com/abrahamcalf/programming-languages-logos/raw/master/src/${iconKey}/${iconKey}.svg`;
return { name, iconUrl };
});
try {
await Language.insertMany(languagesToAdd);
console.log("Languages added to database");
} catch (e) {
console.log("Error while instering languages", e);
}
process.exit(0);
})();