From 8a7a30da98ee2fa33babf04b847783a4382da898 Mon Sep 17 00:00:00 2001 From: Alexey Bondarenko Date: Thu, 21 Apr 2016 23:45:47 +0300 Subject: [PATCH 1/2] replace arguments with options argument --- index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index d1528b4..aeb4d9b 100644 --- a/index.js +++ b/index.js @@ -9,16 +9,20 @@ var File = gutil.File; var PLUGIN_NAME = 'gulp-extend'; -module.exports = function(fileName, deep, jsonSpace) { +module.exports = function(fileName, options) { if (!fileName) { throw new PluginError(PLUGIN_NAME, PLUGIN_NAME + ': Missing fileName parameter'); } + options = Object.assign({ + deep: true, + jsonSpace: 2 + }, options); + var buffer = []; var firstFile = null; - deep = (deep !== undefined) ? deep : true; - buffer.push(deep); // first argument + buffer.push(options.deep); // first argument function bufferContents(file) { if (file.isNull()) { @@ -56,7 +60,7 @@ module.exports = function(fileName, deep, jsonSpace) { cwd: firstFile.cwd, base: firstFile.base, path: joinedPath, - contents: new Buffer(JSON.stringify(joinedContents, null, jsonSpace)) + contents: new Buffer(JSON.stringify(joinedContents, null, options.jsonSpace)) }); this.emit('data', joinedFile); @@ -64,4 +68,4 @@ module.exports = function(fileName, deep, jsonSpace) { } return through(bufferContents, endStream); -}; \ No newline at end of file +}; From defebec7a668f0ed5eb02a2029e26d18a295d6cd Mon Sep 17 00:00:00 2001 From: Alexey Bondarenko Date: Thu, 21 Apr 2016 23:47:26 +0300 Subject: [PATCH 2/2] add strict mode --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index aeb4d9b..b0e7513 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,8 @@ module.exports = function(fileName, options) { options = Object.assign({ deep: true, - jsonSpace: 2 + jsonSpace: 2, + strict: false }, options); var buffer = []; @@ -43,7 +44,9 @@ module.exports = function(fileName, options) { jsonContent = JSON.parse(file.contents.toString('utf8')); } catch (e) { jsonContent = {}; - console.log('[' + gutil.colors.red('gulp-extend') + '] File "' + file.path + '" has errors and was skipped!'); + var message = '[' + gutil.colors.red('gulp-extend') + '] File "' + file.path + '" has errors and was skipped!'; + if (options.strict) throw new Error(message); + else console.log(message); } buffer.push(jsonContent);