-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasyt-cli.js
56 lines (47 loc) · 1.72 KB
/
basyt-cli.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
var _ = require('lodash'),
fs = require("fs");
function InputError(errors) {
this.name = "Input Error";
this.err = errors;
this.statusCode = 200;
Error.captureStackTrace(this, InputError);
}
function BasytError(err, statusCode) {
this.name = "Basyt Internal Error";
this.err = err;
this.statusCode = statusCode;
Error.captureStackTrace(this, BasytError);
}
InputError.prototype = Object.create(Error.prototype);
InputError.prototype.constructor = InputError;
BasytError.prototype = Object.create(Error.prototype);
BasytError.prototype.constructor = BasytError;
function Basyt() {
//register basyt instance to process
process.basyt = this;
var config = GLOBAL.APP_CONFIG;
var entitiesFolder = config.basyt.entities_folder || config.base_folder + 'entities/';
//setup properties
this.collections = {};
this.ErrorDefinitions = {
InputError: InputError,
BasytError: BasytError
};
this.truncateEntities = function () {
_.forOwn(process.basyt.collections, function (entity) {
console.log(entity.name);
entity.delete({}, {multi: true}).catch(function () {});
});
};
//Import entities
if (fs.existsSync(entitiesFolder)) {
fs.readdirSync(entitiesFolder).forEach(function (file, index) {
var entityName = file.toLowerCase().slice(0, -3),
entityConfig = require(entitiesFolder + file),
storage = entityConfig.storage || 'mongodb',
Collection = require('basyt-' + storage + '-collection');
this.collections[entityConfig.collection.name] = new Collection(entityConfig.collection, entityName);
}, this);
}
}
module.exports = Basyt;