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/', |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
32264
772
0
5
3
+ Addedplugin-error@^0.1.2
+ Addedplugin-log@^0.1.0
+ Addedansi-cyan@0.1.1(transitive)
+ Addedansi-red@0.1.1(transitive)
+ Addedarr-diff@1.1.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@2.1.0(transitive)
+ Addedarray-find-index@1.0.2(transitive)
+ Addedarray-slice@0.2.3(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedcamelcase-keys@2.1.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddateformat@1.0.12(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddot-object@1.9.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedextend-shallow@1.1.4(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedindent-string@2.1.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedkind-of@1.1.0(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedloud-rejection@1.6.0(transitive)
+ Addedmap-obj@1.0.1(transitive)
+ Addedmeow@3.7.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedplugin-error@0.1.2(transitive)
+ Addedplugin-log@0.1.0(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedredent@1.0.0(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedstrip-indent@1.0.1(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtrim-newlines@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedgulp-util@^3.0.4
- Removedansi-gray@0.1.1(transitive)
- Removedarray-differ@1.0.0(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedbeeper@1.1.1(transitive)
- Removedclone@1.0.4(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removeddateformat@2.2.0(transitive)
- Removeddot-object@0.6.0(transitive)
- Removedduplexer2@0.0.2(transitive)
- Removedfancy-log@1.3.3(transitive)
- Removedglogg@1.0.2(transitive)
- Removedgulp-util@3.0.8(transitive)
- Removedgulplog@1.0.0(transitive)
- Removedhas-gulplog@0.1.0(transitive)
- Removedisarray@1.0.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._basetostring@3.0.1(transitive)
- Removedlodash._basevalues@3.0.0(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash._reescape@3.0.0(transitive)
- Removedlodash._reevaluate@3.0.0(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash._root@3.0.1(transitive)
- Removedlodash.escape@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedlodash.template@3.6.2(transitive)
- Removedlodash.templatesettings@3.1.1(transitive)
- Removedmultipipe@0.1.2(transitive)
- Removedobject-assign@3.0.0(transitive)
- Removedparse-node-version@1.0.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@1.1.142.3.8(transitive)
- Removedreplace-ext@0.0.1(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsemver@4.3.6(transitive)
- Removedsparkles@1.0.1(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedthrough2@2.0.5(transitive)
- Removedtime-stamp@1.1.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvinyl@0.5.3(transitive)
- Removedxtend@4.0.2(transitive)
Updateddot-object@^1.2.0
Updatedsemver@^5.0.3