UNPKG

gulp-bump-version

Version:

gulp-bump-version eases and automates the management of semver version strings in the source code of almost any file type.

1 lines 1.79 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const replacestream_1=require("replacestream");class bump{constructor(){this.operations={patch:0,minor:1,major:2,version:3,prerelease:4},this.regex=/((@version:[ ]*)((?:(\d+).){1}(?:(\d+).){1}(?:(\d+)){1}))+(?:(-[\+\!\~a-zA-Z0-9]+))?/gm,this.regexPieces={preKey:"((",postKey:"[ ]*)((?:(\\d+).){1}(?:(\\d+).){1}(?:(\\d+)){1}))+(?:(-[\\+\\!\\~a-zA-Z0-9]+))?"}}bumpVersion(e,r){if(e.isNull())return e;if(!r||!r.version&&!r.type)return-3;if(r.key){let e=RegExp(this.regexPieces.preKey+r.key+this.regexPieces.postKey,"gm");this.regex=e}if("string"==typeof r.version)this.replacementOperation=this.operations.version,this.replacementSemver=r.version;else{if(!r.version&&r.type&&"string"==typeof r.type)switch(r.type){case"patch":this.replacementOperation=this.operations.patch;break;case"minor":this.replacementOperation=this.operations.minor;break;case"major":this.replacementOperation=this.operations.major;break;case"prerelease":this.replacementOperation=this.operations.prerelease}if(-1===r.version)return e.contents=new Buffer(String(e.contents).match(this.regex)[0]),e}return e.isStream()&&(e.contents=e.contents.pipe(replacestream_1.default(this.regex,this.replaceVersion.bind(this)))),e.isBuffer()&&(e.contents=new Buffer(String(e.contents).replace(this.regex,this.replaceVersion.bind(this)))),e}replaceVersion(e,r,t,s,i,a,n,o){let p=t;switch(this.replacementOperation){case this.operations.patch:p+=i+"."+a+"."+(parseInt(n)+1);break;case this.operations.minor:p+=i+"."+(parseInt(a)+1)+".0";break;case this.operations.major:p+=parseInt(i)+1+".0.0";break;case this.operations.version:p+=this.replacementSemver;break;case this.operations.prerelease:p+=i+"."+a+"."+n+(o?parseInt(o)+1:"-1")}return p}}exports.default=bump;