-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddType.js
36 lines (31 loc) · 874 Bytes
/
addType.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
const debug = require('debug')('ejson');
const { checkMeteor, getGlobal } = require('meteor-globals');
const tryRequire = require('try-require');
debug("-> Checking for available EJSON's");
const EJSONs = [];
const npmEJSON = tryRequire('ejson');
const meteorEJSON = checkMeteor() ? getGlobal('ejson', 'EJSON') : null;
if (npmEJSON) {
debug('-> Found npm.ejson');
EJSONs.push(npmEJSON);
} else {
debug('-> Did not find npm.ejson');
}
if (meteorEJSON) {
debug('-> found meteor.ejson');
EJSONs.push(meteorEJSON);
} else {
debug('-> Did not find meteor.ejson');
}
module.exports = function addType(name, factory) {
EJSONs.forEach(EJSON => {
try {
EJSON.addType(name, factory);
} catch (error) {
debug(
'Failed to add %o. There was probably already a custom type defined with the same name.',
name,
);
}
});
};