-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (41 loc) · 1.32 KB
/
index.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
const fs = require("fs");
const junk = require("junk");
const async = require("async");
const helpers = require("./helpers");
let FillMeUp = {};
FillMeUp.run = (models, seed_path) => {
return new Promise((resolve, reject) => {
const seeds = fs.readdirSync(seed_path);
let ops = [];
seeds.filter(junk.not).forEach((seed) => {
ops.push((cb) => {
let seed_json = helpers.read_seed_json(seed, seed_path);
let model = helpers.get_first_key(seed_json);
helpers.clear_model(models, model)
.then(() => {
return helpers
.bulk_add(models, model, seed_json)
.then(() => {
cb();
return null;
})
.catch((err) => {
cb(err);
return null;
});
})
.catch(() => {
console.log(`FillMeUp -> There was a problem clearing the ${model} model`);
});
});
});
async.series(ops, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
module.exports = FillMeUp;