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

gulp-bump - npm Package Compare versions

Comparing version 0.3.1 to 1.0.0

82

index.js
'use strict';
var path = require('path');
var gutil = require('gulp-util');
var pluginError = require('plugin-error');
var log = require('plugin-log');
var through = require('through2');

@@ -13,5 +14,4 @@ var semver = require('semver');

var content, json, ver;
return through.obj(function(file, enc, cb) {
return through.obj(function(file, enc, cb) {
if (file.isNull()) {

@@ -21,38 +21,56 @@ return cb(null, file);

if (file.isStream()) {
return cb(new gutil.PluginError('gulp-bump', 'Streaming not supported'));
return cb(new pluginError('gulp-bump', 'Streaming not supported'));
}
json = file.contents.toString();
var content = String(file.contents);
var json;
var ver;
var dot;
try {
content = JSON.parse(json);
json = JSON.parse(content);
} catch (e) {
return cb(new gutil.PluginError('gulp-bump', 'Problem parsing JSON file', {fileName: file.path, showStack: true}));
return cb(new pluginError('gulp-bump', 'Problem parsing JSON file', {
fileName: file.path,
showStack: true
}));
}
// just set a version to the key
if (opts.version) {
if (!content[opts.key]) {
// log to user that key didn't exist before
gutil.log('Creating key', gutil.colors.red(opts.key), 'with version:', gutil.colors.cyan(opts.version));
// get the version and key
if (opts.key.indexOf('.') > -1) {
dot = new Dot();
opts.value = dot.pick(opts.key, json);
ver = bump(opts);
}
else {
opts.value = json[opts.key];
if (!semver.valid(opts.value) && !opts.version) {
return cb(new pluginError('gulp-bump', 'Detected invalid semver ' + opts.key, {
fileName: file.path,
showStack: false
}));
}
content[opts.key] = opts.version;
ver = content[opts.key];
ver = bump(opts);
}
else if (semver.valid(content[opts.key])) {
// increment the key with type
content[opts.key] = semver.inc(content[opts.key], opts.type, opts.preid);
ver = content[opts.key];
// set key
if (!json[opts.key]) {
// log to user that key didn't exist before
log('Creating key', log.colors.red(opts.key), 'with version:', log.colors.cyan(ver));
}
else if (opts.key.indexOf('.') > -1) {
var dot = new Dot();
var value = dot.pick(opts.key, content);
ver = semver.inc(value, opts.type);
dot.str(opts.key, ver, content);
if (dot) {
dot.str(opts.key, ver, json);
}
else {
return cb(new gutil.PluginError('gulp-bump', 'Detected invalid semver ' + opts.key, {fileName: file.path, showStack: false}));
json[opts.key] = ver;
}
file.contents = new Buffer(JSON.stringify(content, null, opts.indent || space(json)) + possibleNewline(json));
gutil.log('Bumped \'' + gutil.colors.cyan(path.basename(file.path)) + '\' ' + gutil.colors.magenta(opts.key) + ' to: ' + gutil.colors.cyan(ver));
file.contents = new Buffer(JSON.stringify(json, null, opts.indent || space(content)) + possibleNewline(content));
log('Bumped \'' + log.colors.cyan(path.basename(file.path)) +
'\' ' + log.colors.magenta(opts.key) +
' to: ' + log.colors.cyan(ver));
cb(null, file);

@@ -62,2 +80,10 @@ });

function bump(opts) {
if (opts.version) {
return opts.version;
}
return semver.inc(opts.value, opts.type, opts.preid);
}
function setDefaultOptions(opts) {

@@ -73,3 +99,3 @@ opts = opts || {};

if (opts.version && !semver.valid(opts.version, opts.type)) {
gutil.log('invalid version used as option', gutil.colors.red(opts.version));
log('invalid version used as option', log.colors.red(opts.version));
opts.version = null;

@@ -80,3 +106,3 @@ }

// Preserver new line at the end of a file
// Preserve new line at the end of a file
function possibleNewline(json) {

@@ -83,0 +109,0 @@ var lastChar = (json.slice(-1) === '\n') ? '\n' : '';

{
"name": "gulp-bump",
"description": "Bump npm versions with Gulp (gulpjs.com)",
"version": "0.3.1",
"version": "1.0.0",
"homepage": "http://github.com/stevelacy/gulp-bump",

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

"dependencies": {
"dot-object": "^0.6.0",
"gulp-util": "^3.0.4",
"semver": "^4.3.1",
"dot-object": "^1.2.0",
"plugin-error": "^0.1.2",
"plugin-log": "^0.1.0",
"semver": "^5.0.3",
"through2": "^0.5.1"

@@ -18,3 +19,4 @@ },

"mocha": "*",
"should": "*"
"should": "*",
"vinyl": "^0.5.3"
},

@@ -21,0 +23,0 @@ "scripts": {

'use strict';
var gutil = require('gulp-util');
var File = require('vinyl');
var should = require('should');

@@ -17,3 +17,3 @@ var bump = require('..');

it('should bump dot notation', function (done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',

@@ -35,3 +35,3 @@ cwd: 'test/',

it('should bump dot notation with type', function (done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',

@@ -55,2 +55,22 @@ cwd: 'test/',

it('should bump dot notation with specified version', function (done) {
var fakeFile = new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: new Buffer(JSON.stringify(dotObject, null, 2))
});
var bumpS = bump({
key: 'subversion.version',
version: '2.0.0'
});
bumpS.once('data', function(newFile) {
var json = JSON.parse(String(newFile.contents));
json.subversion.version.should.equal('2.0.0');
done();
});
bumpS.write(fakeFile);
});
});
'use strict';
var gutil = require('gulp-util');
var File = require('vinyl');
var should = require('should');

@@ -11,9 +11,11 @@ var bump = require('..');

var fakeFile = new File({
path: 'some-dir/dummyfile.js',
contents: new Buffer('{ "version": "0.0.0" }')
});
it('should fail when not detect a valid semver version', function(done) {
var file = 'some-dir/dummyfile.js';
var fakeFile = new gutil.File({
path: file,
contents: new Buffer('{ "version": "0.A.1" }')
});
fakeFile.contents = new Buffer('{ "version": "0.A.1" }');
var bumpS = bump();

@@ -24,3 +26,3 @@

e.message.should.equal('Detected invalid semver version');
e.fileName.should.containEql(file);
e.fileName.should.containEql(fakeFile.path);
return done();

@@ -32,8 +34,4 @@ });

it('should fail when not detect a valid semver version and wrong key', function(done) {
var file = 'some-dir/dummyfile.js';
var fakeFile = new gutil.File({
path: file,
contents: new Buffer('{ "version": "0.0.1" }')
});
it('should fail with an invalid semver version', function(done) {
fakeFile.contents = new Buffer('{ "version": "0.0.1" }');

@@ -45,3 +43,3 @@ var bumpS = bump({key: 'appversion'});

e.message.should.containEql('Detected invalid semver appversion');
e.fileName.should.containEql(file);
e.fileName.should.containEql(fakeFile.path);
return done();

@@ -54,7 +52,3 @@ });

it('should fail when supplied with an invalid JSON', function(done) {
var file = 'some-dir/dummyfile.js';
var fakeFile = new gutil.File({
path: file,
contents: new Buffer('{ invalid json oh no!!!}')
});
fakeFile.contents = new Buffer('{ invalid json oh no!!!}');

@@ -67,3 +61,3 @@ var bumpS = bump();

e.message.should.containEql('Problem parsing JSON file');
e.fileName.should.containEql(file);
e.fileName.should.containEql(fakeFile.path);
return done();

@@ -76,5 +70,4 @@ });

it('should fallback to defaults when supplied with invalid semver version', function(done) {
var fakeFile = new gutil.File({
contents: new Buffer('{ "version": "0.0.1" }')
});
fakeFile.contents = new Buffer('{ "version": "0.0.1" }');
var bumpS = bump({version: '0.A.2'});

@@ -81,0 +74,0 @@

'use strict';
var fs = require('fs');
var gutil = require('gulp-util');
var File = require('vinyl');
var should = require('should');

@@ -15,3 +15,3 @@ var bump = require('..');

it('should bump minor by default', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',

@@ -36,3 +36,3 @@ cwd: 'test/',

it('should bump major if options.bump = major', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',

@@ -57,3 +57,3 @@ cwd: 'test/',

it('should bump minor if options.bump = minor', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',

@@ -78,3 +78,3 @@ cwd: 'test/',

it('should set version to value specified by options.version', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',

@@ -99,3 +99,3 @@ cwd: 'test/',

it('should set the key to a custom version', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',

@@ -102,0 +102,0 @@ cwd: 'test/',

'use strict';
var gutil = require('gulp-util');
var File = require('vinyl');
var should = require('should');

@@ -12,3 +12,3 @@ var bump = require('..');

it('should bump patch version by default', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.0.9" }'),

@@ -31,3 +31,3 @@ path: 'test/fixtures/test.json'

it('should bump patch version as default and a key=appversion', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "appversion": "0.0.1" }'),

@@ -50,3 +50,3 @@ path: 'test/fixtures/test.json'

it('should ignore invalid type and use type=patch', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.0.1" }'),

@@ -70,3 +70,3 @@ path: 'test/fixtures/test.json'

it('should set the correct version when supplied', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.0.1" }'),

@@ -89,3 +89,3 @@ path: 'test/fixtures/test.json'

it('should set the correct version when supplied even if key did not exist', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{}'),

@@ -108,3 +108,3 @@ path: 'test/fixtures/test.json'

it('should bump prerelease version', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.0.1-0"}'),

@@ -127,3 +127,3 @@ path: 'test/fixtures/test.json'

it('should bump to a prerelease version with a preid', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.0.1"}'),

@@ -146,3 +146,3 @@ path: 'test/fixtures/test.json'

it('should bump preid version', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.1.0-zeta.1"}'),

@@ -149,0 +149,0 @@ path: 'test/fixtures/test.json'

'use strict';
var gutil = require('gulp-util');
var File = require('vinyl');
var should = require('should');

@@ -15,3 +15,3 @@ var bump = require('..');

var createFile = function (tabType) {
return new gutil.File({
return new File({
base: 'test/',

@@ -58,3 +58,3 @@ cwd: 'test/',

it('should preserve whitespace at end', function (done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',

@@ -75,3 +75,3 @@ cwd: 'test/',

it('should not add new line to file', function (done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',

@@ -78,0 +78,0 @@ cwd: 'test/',

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc