gulp-json-editor
Advanced tools
Comparing version 2.4.4 to 2.5.0
@@ -0,1 +1,11 @@ | ||
## 2.5.0 | ||
### Added | ||
- Add ability to pass options to deepmerge (#25 by @buuug7) | ||
### Changed | ||
- Update dependencies | ||
## 2.4.4 | ||
@@ -2,0 +12,0 @@ |
13
index.js
var jsbeautify = require('js-beautify').js_beautify; | ||
var merge = require('deepmerge'); | ||
var deepmerge = require('deepmerge'); | ||
var through = require('through2'); | ||
@@ -7,5 +7,10 @@ var PluginError = require('plugin-error'); | ||
module.exports = function (editor, jsbeautifyOptions) { | ||
module.exports = function (editor, jsbeautifyOptions, deepmergeOptions) { | ||
/* | ||
* deepmerge options | ||
*/ | ||
deepmergeOptions = deepmergeOptions || {}; | ||
/* | ||
* create 'editBy' function from 'editor' | ||
@@ -20,3 +25,3 @@ */ | ||
// edit JSON object by merging with user specific object | ||
editBy = function(json) { return merge(json, editor); }; | ||
editBy = function(json) { return deepmerge(json, editor, deepmergeOptions); }; | ||
} | ||
@@ -57,3 +62,3 @@ else if (typeof editor === 'undefined') { | ||
// beautify options for this particular file | ||
var beautifyOptions = merge({}, jsbeautifyOptions); // make copy | ||
var beautifyOptions = deepmerge({}, jsbeautifyOptions); // make copy | ||
beautifyOptions.indent_size = beautifyOptions.indent_size || indent.amount || 2; | ||
@@ -60,0 +65,0 @@ beautifyOptions.indent_char = beautifyOptions.indent_char || (indent.type === 'tab' ? '\t' : ' '); |
{ | ||
"name": "gulp-json-editor", | ||
"version": "2.4.4", | ||
"version": "2.5.0", | ||
"description": "A gulp plugin to edit JSON objects", | ||
@@ -17,3 +17,3 @@ "license": "MIT", | ||
"detect-indent": "^5.0.0", | ||
"js-beautify": "^1.8.8", | ||
"js-beautify": "^1.8.9", | ||
"plugin-error": "^1.0.1", | ||
@@ -23,3 +23,3 @@ "through2": "^3.0.0" | ||
"devDependencies": { | ||
"eslint": "^5.9.0", | ||
"eslint": "^5.11.0", | ||
"eslint-config-gulp": "^3.0.1", | ||
@@ -26,0 +26,0 @@ "gulp": "^4.0.0", |
@@ -32,3 +32,3 @@ # gulp-json-editor | ||
/* | ||
specify js-beautify option | ||
specify [js-beautify](https://github.com/beautify-web/js-beautify) option | ||
*/ | ||
@@ -45,2 +45,17 @@ gulp.src("./manifest.json") | ||
.pipe(gulp.dest("./dest")); | ||
/* | ||
specify [deepmerge](https://github.com/TehShrike/deepmerge) option | ||
*/ | ||
gulp.src("./manifest.json") | ||
.pipe(jeditor({ | ||
"authors": ["tomcat"] | ||
}, | ||
// the second argument is passed to js-beautify as its option | ||
{}, | ||
// the third argument is passed to deepmerge options, eg, arrayMerge options | ||
{ | ||
arrayMerge: function (dist,source,options) {return source;} | ||
})) | ||
.pipe(gulp.dest("./dest")); | ||
``` | ||
@@ -66,3 +81,3 @@ | ||
## API | ||
### jeditor(editorObject, [jsBeautifyOptions]) | ||
### jeditor(editorObject, [jsBeautifyOptions], [deepmergeOptions]) | ||
#### editorObject | ||
@@ -78,3 +93,8 @@ Type: `JSON object` | ||
### jeditor(editorFunction, [jsBeautifyOptions]) | ||
#### deepmergeOptions | ||
Type: `object` | ||
This object is passed to deepmerge as its [option](https://github.com/TehShrike/deepmerge#options). | ||
### jeditor(editorFunction, [jsBeautifyOptions], [deepmergeOptions]) | ||
#### editorFunction | ||
@@ -90,3 +110,8 @@ Type: `function` | ||
#### deepmergeOptions | ||
Type: `object` | ||
This object is passed to deepmerge as its [option](https://github.com/TehShrike/deepmerge#options). | ||
## License | ||
[MIT License](http://en.wikipedia.org/wiki/MIT_License) |
@@ -19,3 +19,4 @@ var json = require('../'); | ||
' "version": "1.0.0"\n' + | ||
' }\n' + | ||
' },\n' + | ||
' "authors": ["tom"]\n' + | ||
'}'; | ||
@@ -44,2 +45,3 @@ file.contents.toString().should.eql(expected); | ||
' },\n' + | ||
' "authors": ["tom"],\n' + | ||
' "description": "this is test"\n' + | ||
@@ -67,3 +69,4 @@ '}'; | ||
' "version": "1.0.0"\n' + | ||
' }\n' + | ||
' },\n' + | ||
' "authors": ["tom"]\n' + | ||
'}'; | ||
@@ -91,3 +94,4 @@ file.contents.toString().should.eql(expected); | ||
' "version": "2.0.1"\n' + | ||
' }\n' + | ||
' },\n' + | ||
' "authors": ["tom"]\n' + | ||
'}'; | ||
@@ -116,3 +120,4 @@ file.contents.toString().should.eql(expected); | ||
' "description": "this is test for nested"\n' + | ||
' }\n' + | ||
' },\n' + | ||
' "authors": ["tom"]\n' + | ||
'}'; | ||
@@ -139,3 +144,4 @@ file.contents.toString().should.eql(expected); | ||
' "version": "1.0.0"\n' + | ||
' }\n' + | ||
' },\n' + | ||
' "authors": ["tom"]\n' + | ||
'}'; | ||
@@ -168,2 +174,3 @@ file.contents.toString().should.eql(expected); | ||
' },\n' + | ||
' "authors": ["tom"],\n' + | ||
' "description": "this is test"\n' + | ||
@@ -170,0 +177,0 @@ '}'; |
@@ -18,3 +18,4 @@ var json = require('../'); | ||
' "version": "1.0.0"\n' + | ||
' }\n' + | ||
' },\n' + | ||
' "authors": ["tom"]\n' + | ||
'}'; | ||
@@ -42,2 +43,3 @@ file.contents.toString().should.eql(expected); | ||
' },\n' + | ||
' "authors": ["tom"],\n' + | ||
' "description": "this is test"\n' + | ||
@@ -67,3 +69,4 @@ '}'; | ||
' "version": "2.0.1"\n' + | ||
' }\n' + | ||
' },\n' + | ||
' "authors": ["tom"]\n' + | ||
'}'; | ||
@@ -93,3 +96,4 @@ file.contents.toString().should.eql(expected); | ||
' "description": "this is test for nested"\n' + | ||
' }\n' + | ||
' },\n' + | ||
' "authors": ["tom"]\n' + | ||
'}'; | ||
@@ -123,2 +127,3 @@ file.contents.toString().should.eql(expected); | ||
' },\n' + | ||
' "authors": ["tom"],\n' + | ||
' "description": "this is test"\n' + | ||
@@ -125,0 +130,0 @@ '}'; |
@@ -36,2 +36,3 @@ var json = require('../'); | ||
'\t\t\t},\n' + | ||
'\t\t\t"authors": ["tom"],\n' + | ||
'\t\t\t"description": "this is test",\n' + | ||
@@ -79,2 +80,3 @@ '\t\t\t"array": ["1234567890", "1234567890", "1234567890", "1234567890",\n' + | ||
' },\n' + | ||
' "authors": ["tom"],\n' + | ||
' "description": "this is test",\n' + | ||
@@ -109,3 +111,3 @@ ' "array": ["1234567890", "1234567890", "1234567890", "1234567890",\n' + | ||
stream.on('data', function(file) { | ||
var expected = '{"name":"test object","version":"2.0.0","nested":{"name":"nested object","version":"2.0.1","description":"this is test for nested"},"description":"this is test","array":["1234567890","1234567890","1234567890","1234567890","1234567890","1234567890","1234567890","1234567890"]}'; | ||
var expected = '{"name":"test object","version":"2.0.0","nested":{"name":"nested object","version":"2.0.1","description":"this is test for nested"},"authors":["tom"],"description":"this is test","array":["1234567890","1234567890","1234567890","1234567890","1234567890","1234567890","1234567890","1234567890"]}'; | ||
file.contents.toString().should.eql(expected); | ||
@@ -115,1 +117,28 @@ done(); | ||
}); | ||
it('should pass-through third argument to deepmerge and do an overwriteMerge', function(done) { | ||
var stream = gulp.src('test/test.json').pipe(json({ | ||
authors: ['tomcat'], | ||
},{},{ | ||
arrayMerge: function(dist,source,options) { | ||
return source; | ||
}, | ||
})); | ||
stream.on('data', function(file) { | ||
var expected = | ||
'{\n' + | ||
' "name": "test object",\n' + | ||
' "version": "1.0.0",\n' + | ||
' "nested": {\n' + | ||
' "name": "nested object",\n' + | ||
' "version": "1.0.0"\n' + | ||
' },\n' + | ||
' "authors": ["tomcat"]\n' + | ||
'}'; | ||
file.contents.toString().should.eql(expected); | ||
done(); | ||
}); | ||
}); |
@@ -7,3 +7,4 @@ { | ||
"version": "1.0.0" | ||
} | ||
}, | ||
"authors": ["tom"] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20983
491
113
Updatedjs-beautify@^1.8.9