-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
55 lines (42 loc) · 1.28 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
51
52
53
54
var JoinPlugin = require('join-webpack-plugin');
var merge = require("merge");
var flatten = require('flat');
function flattenLowness(lowness, obj, opts) {
var res = {};
if(lowness) {
Object.keys(obj).forEach(function(key) {
if(obj[key] instanceof Array || obj[key] instanceof Object) {
res[key] = flattenLowness(lowness-1, obj[key], opts);
} else {
res[key] = obj[key]
}
});
} else {
res = flatten(obj, opts);
}
return res;
}
function IntlPlugin(options) {
options.join = function(common, addition) {
return merge.recursive(
common ? common : {},
addition ? JSON.parse(addition) : {}
);
};
var lowness = options.flattenLowness;
lowness = undefined === lowness ? 1 : lowness;
var depth = options.flattenDepth;
var flattenOpts = depth ? {maxDepth: depth} : {};
options.save = function(common) {
return JSON.stringify(
flattenLowness(lowness, common, flattenOpts)
);
};
options.group = options.group || "[name]"
options.name = options.name || '[name].[hash].json'
JoinPlugin.call(this,options);
}
IntlPlugin.prototype = Object.create(JoinPlugin.prototype);
IntlPlugin.prototype.loader = JoinPlugin.prototype.loader;
IntlPlugin.loader = JoinPlugin.loader;
module.exports = IntlPlugin;