-
Notifications
You must be signed in to change notification settings - Fork 7
/
registry.js
83 lines (68 loc) · 1.65 KB
/
registry.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const Normalize = require('./normalize');
const Registry = {
externalRenderer: false,
dependencies: {},
fields: {
assets: {},
extensions: {},
links: {},
metadata: {}
},
exportFields() {
return this.fields;
},
importFields(fields) {
fields = Normalize.fields(fields);
for(let key in this.fields) {
Object.assign(this.fields[key], fields[key]);
}
},
getDependency(name) {
if (!this.dependencies[name]) {
console.warn(`Dependency '${name}' not registered.`);
}
return this.dependencies[name];
},
addDependency(name, library) {
this.dependencies[name] = library;
},
addExtension(prefix, spec) {
this.fields.extensions[prefix] = Normalize.field(spec, this.fields.extensions);
},
addMetadataField(field, spec) {
this.fields.metadata[field] = Normalize.field(spec, this.fields.metadata);
},
addLinkField(field, spec) {
this.fields.links[field] = Normalize.field(spec, this.fields.links);
},
addAssetField(field, spec) {
this.fields.assets[field] = Normalize.field(spec, this.fields.assets);
},
addMetadataFields(specs) {
for(var key in specs) {
Registry.addMetadataField(key, specs[key]);
}
},
getExtension(name) {
if (this.fields.extensions[name]) {
return this.fields.extensions[name];
}
else {
return {};
}
},
getSpecification(field, type = null) {
let spec = {};
if (type === 'assets' && this.fields.assets[field]) {
spec = this.fields.assets[field];
}
else if (type === 'links' && this.fields.links[field]) {
spec = this.fields.links[field];
}
else if (this.fields.metadata[field]) {
spec = this.fields.metadata[field];
}
return spec;
}
};
module.exports = Registry;