-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperties.js
41 lines (37 loc) · 1.33 KB
/
properties.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
define(['text', 'java.properties'], function (text, javaProperties) {
var buildMap = {};
var flattenObject = function (ob) {
return Object.keys(ob).reduce(function (toReturn, k) {
if ((typeof ob[k]) === 'object' && ob[k]) {
var flatObject = flattenObject(ob[k]);
Object.keys(flatObject).forEach(function (k2) {
toReturn[k + '.' + k2] = flatObject[k2];
});
}
else {
toReturn[k] = ob[k];
}
return toReturn;
}, {});
};
return {
write: function (pluginName, name, write) {
if (name in buildMap) {
write('define("' + pluginName + '!' + name + '", function(){ return ' + JSON.stringify(buildMap[name]) + '; });\n');
}
},
load: function (name, parentRequire, onload, config) {
text.get(parentRequire.toUrl(name), function (propertiesString) {
try {
var result = javaProperties.propertiesToObject(propertiesString);
var flattened = flattenObject(result);
buildMap[name] = flattened;
onload(flattened);
} catch (e){
onload.error(e);
}
});
}
, version: '0.1.0'
};
});