Socket
Socket
Sign inDemoInstall

gulp-bump

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.9 to 0.1.10

34

index.js

@@ -8,3 +8,3 @@ var gutil = require('gulp-util');

opts.key = opts.key || 'version';
opts.indent = opts.indent || 2;
opts.indent = opts.indent || void 0;
// default type bump is patch

@@ -22,2 +22,14 @@ if (!opts.type || !semver.inc('0.0.1', opts.type)) {

// Preserver new line at the end of a file
var possibleNewline = function (json) {
var lastChar = (json.slice(-1) === '\n') ? '\n' : '';
return lastChar;
};
// Figured out which "space" params to be used for JSON.stringfiy.
var space = function space(json) {
var match = json.match(/^(?:(\t+)|( +))"/m);
return match ? (match[1] ? '\t' : match[2].length) : '';
};
module.exports = function(opts) {

@@ -31,3 +43,3 @@ // set task options

var json;
var content, json;

@@ -41,5 +53,6 @@ return through.obj(function(file, enc, cb) {

}
json = file.contents.toString();
try {
json = JSON.parse(file.contents.toString());
content = JSON.parse(json);
} catch (e) {

@@ -51,11 +64,11 @@ return cb(new gutil.PluginError('gulp-bump', 'Problem parsing JSON file ' + file.path));

if (version) {
if (!json[key]) {
if (!content[key]) {
// log to user that key didn't exist before
gutil.log('Creating key', gutil.colors.red(key), 'with version:', gutil.colors.cyan(version));
}
json[key] = version;
content[key] = version;
}
else if (semver.valid(json[key])) {
else if (semver.valid(content[key])) {
// increment the key with type
json[key] = semver.inc(json[key], type);
content[key] = semver.inc(content[key], type);
}

@@ -65,8 +78,7 @@ else {

}
file.contents = new Buffer(JSON.stringify(content, null, indent || space(json)) + possibleNewline(json));
file.contents = new Buffer(JSON.stringify(json, null, indent) + '\n');
gutil.log('Bumped ' + gutil.colors.magenta(key) + ' to: ' + gutil.colors.cyan(json[key]));
gutil.log('Bumped ' + gutil.colors.magenta(key) + ' to: ' + gutil.colors.cyan(content[key]));
cb(null, file);
});
};
{
"name": "gulp-bump",
"description": "Bump npm versions with Gulp (gulpjs.com)",
"version": "0.1.9",
"version": "0.1.10",
"homepage": "http://github.com/stevelacy/gulp-bump",

@@ -6,0 +6,0 @@ "repository": "git://github.com/stevelacy/gulp-bump.git",

@@ -10,3 +10,3 @@ # gulp-bump

<table>
<tr>
<tr>
<td>Package</td><td>gulp-bump</td>

@@ -84,3 +84,4 @@ </tr>

// Define the tab size for indenting
// Override the tab size for indenting
// (or simply omit to keep the current formatting)
gulp.task('bump', function(){

@@ -188,3 +189,3 @@ gulp.src('./package.json')

Type: `Number`
Default: `2`
Default: Same as original source file

@@ -191,0 +192,0 @@

@@ -11,3 +11,3 @@ var fs = require('fs');

describe('gulp-bump', function() {
describe('gulp-bump - JSON comparison fixtures', function() {

@@ -195,5 +195,5 @@

var fakeFile = new gutil.File({
base: "test/",
cwd: "test/",
path: "test/fixtures/package.json",
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: fixtureFile

@@ -216,5 +216,5 @@ });

var fakeFile = new gutil.File({
base: "test/",
cwd: "test/",
path: "test/fixtures/package.json",
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: fixtureFile

@@ -237,5 +237,5 @@ });

var fakeFile = new gutil.File({
base: "test/",
cwd: "test/",
path: "test/fixtures/package.json",
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: fixtureFile

@@ -258,5 +258,5 @@ });

var fakeFile = new gutil.File({
base: "test/",
cwd: "test/",
path: "test/fixtures/package.json",
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: fixtureFile

@@ -279,9 +279,9 @@ });

var fakeFile = new gutil.File({
base: "test/",
cwd: "test/",
path: "test/fixtures/key.json",
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/key.json',
contents: fs.readFileSync('test/fixtures/key.json')
});
var bumpS = bump({key: "appversion"});
var bumpS = bump({key: 'appversion'});

@@ -298,2 +298,82 @@ bumpS.once('data', function(newFile) {

});
});
describe('gulp-bump - Whitespace preserving', function() {
var fixtureObj = { version: '1.0.0' };
var expectedObj = { version: '1.0.1' };
var createFile = function (tabType) {
return new gutil.File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: new Buffer(JSON.stringify(fixtureObj, null, tabType))
});
};
it('should preserve tab whitespace settings', function (done) {
var fakeFile = createFile('\t');
var bumpS = bump();
bumpS.once('data', function(newFile) {
String(newFile.contents).should.equal(JSON.stringify(expectedObj, null, '\t'));
done();
});
bumpS.write(fakeFile);
});
it('should preserve spaces whitespace settings', function (done) {
var fakeFile = createFile(3);
var bumpS = bump();
bumpS.once('data', function(newFile) {
String(newFile.contents).should.equal(JSON.stringify(expectedObj, null, 3));
done();
});
bumpS.write(fakeFile);
});
it('should override whitespace if indent defined', function (done) {
var fakeFile = createFile(3);
var bumpS = bump({ indent: 2 });
bumpS.once('data', function(newFile) {
String(newFile.contents).should.equal(JSON.stringify(expectedObj, null, 2));
done();
});
bumpS.write(fakeFile);
});
it('should preserve whitespace at end', function (done) {
var fakeFile = new gutil.File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: new Buffer(JSON.stringify(fixtureObj, null, 2) + '\n')
});
var bumpS = bump();
bumpS.once('data', function(newFile) {
String(newFile.contents.slice(-1)).should.equal('\n');
done();
});
bumpS.write(fakeFile);
});
it('should not add new line to file', function (done) {
var fakeFile = new gutil.File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: new Buffer(JSON.stringify(fixtureObj, null, 2))
});
var bumpS = bump();
bumpS.once('data', function(newFile) {
String(newFile.contents.slice(-1)).should.not.equal('\n');
done();
});
bumpS.write(fakeFile);
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc