gulp-json-editor
Advanced tools
Comparing version 1.0.2 to 1.1.0
15
index.js
/* jshint node: true */ | ||
var jsbeautify = require('js-beautify').js_beautify; | ||
var through = require('through2'); | ||
var PluginError = require('gulp-util').PluginError; | ||
module.exports = function (editor) { | ||
module.exports = function (editor, beautify) { | ||
@@ -29,3 +30,13 @@ // check options | ||
try { | ||
file.contents = new Buffer(JSON.stringify(editor(JSON.parse(file.contents.toString('utf8'))))); | ||
var json = JSON.stringify(editor(JSON.parse(file.contents.toString('utf8')))); | ||
if (beautify) { | ||
json = jsbeautify(json, { | ||
'indent_with_tabs': false, | ||
'indent_size': 2, | ||
'indent_char': ' ', | ||
'indent_level': 0, | ||
'brace_style': 'collapse' | ||
}); | ||
} | ||
file.contents = new Buffer(json); | ||
} | ||
@@ -32,0 +43,0 @@ catch (err) { |
{ | ||
"name": "gulp-json-editor", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "A gulp plugin to edit JSON object", | ||
@@ -28,3 +28,4 @@ "license": "MIT", | ||
"gulp-util": "~2.2.14", | ||
"through2": "~0.4.1" | ||
"through2": "~0.4.1", | ||
"js-beautify": "~1.4.2" | ||
}, | ||
@@ -31,0 +32,0 @@ "devDependencies": { |
@@ -10,3 +10,3 @@ # gulp-json-editor | ||
gulp.src("./manifest.json") | ||
.pipe(jeditor(function(json) { | ||
.pipe(jeditor(function(json, true) { | ||
// json is normal JSON object. You can modify / add / remove any properties. | ||
@@ -21,10 +21,13 @@ json.version = "1.2.3"; | ||
### Note | ||
In case of such situation, all of comment and white space in source file isn't kept in destination file. | ||
In case of such above situation, all of comment in source file isn't kept in destination file. | ||
## API | ||
### jeditor(editorFunction) | ||
### jeditor(editorFunction, [beautify]) | ||
#### editorFunction | ||
The `editorFunction` must have the following signature: `function (json) {}`, and must return JSON object. | ||
#### beautify | ||
Pass `true` to beautify before output (default `false`). | ||
## License | ||
[MIT License](http://en.wikipedia.org/wiki/MIT_License) |
8452
220
31
3
+ Addedjs-beautify@~1.4.2
+ Addedabbrev@1.1.1(transitive)
+ Addedconfig-chain@1.1.13(transitive)
+ Addedini@1.3.8(transitive)
+ Addedjs-beautify@1.4.2(transitive)
+ Addedmkdirp@0.3.5(transitive)
+ Addednopt@2.1.2(transitive)
+ Addedproto-list@1.2.4(transitive)