merge-jsons-webpack-plugin
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -31,3 +31,4 @@ { | ||
"devDependencies": { | ||
"webpack": "2.2.1" | ||
"webpack": "2.2.1", | ||
"webpack-dev-server": "2.4.1" | ||
}, | ||
@@ -37,4 +38,6 @@ "main": "index.js", | ||
"webpack": "webpack", | ||
"test": "webpack" | ||
"test": "webpack", | ||
"start": "webpack-dev-server --inline --progress --port 8080" | ||
} | ||
} |
84
index.js
@@ -11,8 +11,6 @@ "use strict"; | ||
this.apply = function (compiler) { | ||
compiler.plugin("compile", function (params) { | ||
console.log("merge-jsons-webpack-plugin compilation starts"); | ||
compiler.plugin("this-compilation", function (compilation) { | ||
console.log("MergeJsonWebpackPlugin compiling...."); | ||
_this.init(); | ||
}); | ||
compiler.plugin("done", function (params) { | ||
console.log("merge-jsons-webpack-plugin compilation done"); | ||
}); | ||
}; | ||
@@ -61,2 +59,25 @@ this.load = function (files) { | ||
}; | ||
this.mergeDeep = function (target, source) { | ||
if (typeof target == "object" && typeof source == "object") { | ||
for (var key in source) { | ||
if (source[key] === null && (target[key] === undefined || target[key] === null)) { | ||
target[key] = null; | ||
} | ||
else if (source[key] instanceof Array) { | ||
if (!target[key]) | ||
target[key] = []; | ||
target[key] = target[key].concat(source[key]); | ||
} | ||
else if (typeof source[key] == "object") { | ||
if (!target[key]) | ||
target[key] = {}; | ||
_this.mergeDeep(target[key], source[key]); | ||
} | ||
else { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
this.write = function (_path, data) { | ||
@@ -74,20 +95,2 @@ try { | ||
}; | ||
this.resolve = function (options) { | ||
var output = options.output; | ||
var pattern = ""; | ||
if (output.groupBy) { | ||
var groupBy = output.groupBy; | ||
if (!Array.isArray(groupBy) || groupBy.length == 0) { | ||
throw new Error('\"groupBy\" must be a non empty array, eg \"groupBy\":[{\"pattern":\"**/**\",\"fileName\":\"sampleOutput\"}]'); | ||
} | ||
var matches = []; | ||
for (var _i = 0, groupBy_1 = groupBy; _i < groupBy_1.length; _i++) { | ||
var g = groupBy_1[_i]; | ||
if (!g.pattern) { | ||
throw new Error('When you are merging using \"groupBy\" options ,please specifiy a file/directory pattern to group by ' + JSON.stringify(g)); | ||
} | ||
matches.push(_this._glob(g.pattern)); | ||
} | ||
} | ||
}; | ||
this._glob = function (pattern) { | ||
@@ -103,5 +106,5 @@ return new es6_promise_1.Promise(function (resolve, reject) { | ||
}; | ||
this.init = function (options) { | ||
var files = options.files; | ||
var output = options.output; | ||
this.init = function () { | ||
var files = _this.options.files; | ||
var output = _this.options.output; | ||
var groupBy = output.groupBy; | ||
@@ -140,4 +143,4 @@ if (files && groupBy) { | ||
}; | ||
for (var _i = 0, groupBy_2 = groupBy; _i < groupBy_2.length; _i++) { | ||
var g = groupBy_2[_i]; | ||
for (var _i = 0, groupBy_1 = groupBy; _i < groupBy_1.length; _i++) { | ||
var g = groupBy_1[_i]; | ||
_loop_1(g); | ||
@@ -165,29 +168,6 @@ } | ||
}; | ||
this.init(options); | ||
this.options = options; | ||
} | ||
MergeJsonWebpackPlugin.prototype.mergeDeep = function (target, source) { | ||
if (typeof target == "object" && typeof source == "object") { | ||
for (var key in source) { | ||
if (source[key] === null && (target[key] === undefined || target[key] === null)) { | ||
target[key] = null; | ||
} | ||
else if (source[key] instanceof Array) { | ||
if (!target[key]) | ||
target[key] = []; | ||
target[key] = target[key].concat(source[key]); | ||
} | ||
else if (typeof source[key] == "object") { | ||
if (!target[key]) | ||
target[key] = {}; | ||
this.mergeDeep(target[key], source[key]); | ||
} | ||
else { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return MergeJsonWebpackPlugin; | ||
}()); | ||
module.exports = MergeJsonWebpackPlugin; |
{ | ||
"name": "merge-jsons-webpack-plugin", | ||
"description": "This plugin is used to merge json files into single json file,using glob or file names", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"author": { | ||
@@ -49,1 +49,2 @@ "email": "sudharsan_tk@yahoo.co.in", | ||
} | ||
27936
284