如何通过咕嘟咕嘟任务递增版本号? [英] How to Increment Version Number via Gulp Task?
问题描述
我想更换一个字符串,指示在JavaScript文件( myConstantsFile.js
)的版本号,用另一个字符串。因此,例如,我的版本号是这样的:15年1月11日,这样写的 myConstantsFile.js
与其他常量:
.constant('的ProductVersion','15年1月11日');
现在,我的任务是这样的:
gulp.task('增量版本',函数(){
gulp.src(['./ somedir / myConstantsFile.js'])
.pipe(替换(/'的ProductVersion','(。*)'/克,'99 .99.99'))
.pipe(gulp.dest('./ somedir /'));
});
正如你所看到的,我使用的是恒定的,不运行增量$ C $ ç,这将是这样的:
VAR numberString ='0.0.1';
变种versionParts = numberString.split('。');
VAR VARRAY = {
vMajor:versionParts [0],
vMinor:versionParts [1],
vPatch:versionParts [2]
} vArray.vPatch = parseFloat(vArray.vPatch)+ 1;
变种periodString =; VAR newVersionNumberString = vArray.vMajor + periodString +
vArray.vMinor + periodString +
vArray.vPatch;
我需要:
- 通过通过文件的正则表达式来选择当前版本号的方法。
- 要知道我在哪里可以把逻辑在过去code座递增的数量,并建立新的字符串。
NPM安装一饮而尽焊球--save-dev的
NPM安装yargs --save-dev的
需要一饮而尽凸点
VAR凹凸=要求('一饮而尽焊球');
需要yargs
变参=要求('yargs')的argv。
您凹凸任务
gulp.task('撞',函数(){
///<总结>
///它对颠簸的修订
///用法:
/// 1.一饮而尽凹凸:颠簸的package.json和bower.json到下一个小版本。
///即从0.1.1至0.1.2
/// 2.一饮而尽凹凸--version 1.1.1:点/设置的package.json和bower.json到
///指定的修订。
/// 3.一饮而尽凹凸--type专业:颠簸1.0.0
///一饮而尽凹凸--type轻微:颠簸0.1.0
///一饮而尽凹凸--type补丁:颠簸0.0.2
///一饮而尽凹凸--type $ P $租赁前:颠簸0.0.1-2
///< /总结> VAR类型= args.type;
VAR的版本= args.version;
VAR的选择= {};
如果(版本){
options.version =版本;
味精+ ='到'+版本;
}其他{
options.type =类型;
味精+ ='的'+型;
}
回报一饮而尽
的.src(['路径到你的package.json','路径,您bower.json'])
.pipe(凹凸(选项))
.pipe(gulp.dest('路径到根目录'));
});
VSO注:我相信有很多人来到这个线程恰好上方寻找答案。在code以下是编辑存储的地方除了NPM /凉亭包文件,如角常量一个版本号:
gulp.task('增量版本',函数(){
//文档字符串是从中你会得到你常量字符串文件
VAR文档字符串= fs.readFileSync('./ someFolder / constants.js','UTF8'); //下面的code得到您的语义v#从文档字符串
VAR versionNumPattern = /'someText preceedingVNumber','(*)'/; //这只是一个为版本号的捕获组的正则表达式
VAR vNumRexEx =新的RegExp(versionNumPattern);
变种oldVersionNumber =(vNumRexEx.exec(文档字符串))[1]; //这得到了俘获组 //...Split版本号字符串划分为元素,所以你会碰到一个你想要的
变种versionParts = oldVersionNumber.split('。');
VAR VARRAY = {
vMajor:versionParts [0],
vMinor:versionParts [1],
vPatch:versionParts [2]
}; vArray.vPatch = parseFloat(vArray.vPatch)+ 1;
变种periodString =; VAR newVersionNumber = vArray.vMajor + periodString +
vArray.vMinor + periodString +
vArray.vPatch; gulp.src(['./ someFolder / constants.js'])
.pipe(替换(/'someText preceedingVNumber','(。*)'/克,newVersionNumber))
.pipe(gulp.dest('./ someFolder /'));
});
我ommitted一些天书,在pretty字符串写入我不变的,但是这是要点和它的作品。
I would like to replace a string indicating version number in a javascript file (myConstantsFile.js
), with another string. So, for example, my version number looks like this: "01.11.15", written like this in myConstantsFile.js
with other constants:
.constant('productVersion', '1.11.15');
Right now, my task looks like this:
gulp.task('increment-version', function(){
gulp.src(['./somedir/myConstantsFile.js'])
.pipe(replace(/'productVersion', '(.*)'/g, '99.99.99'))
.pipe(gulp.dest('./somedir/'));
});
As you can see, I am using a constant, not running incrementation code, which would look like this:
var numberString = '0.0.1';
var versionParts = numberString.split('.');
var vArray = {
vMajor : versionParts[0],
vMinor : versionParts[1],
vPatch : versionParts[2]
}
vArray.vPatch = parseFloat(vArray.vPatch) + 1;
var periodString = ".";
var newVersionNumberString = vArray.vMajor + periodString +
vArray.vMinor+ periodString +
vArray.vPatch;
I need:
- A way to select the current version number via regex via the file.
- To know where I can put the logic in the last code block to increment the number and build the new string.
Install gulp-bump
npm install gulp-bump --save-dev
Install yargs
npm install yargs --save-dev
Require gulp-bump
var bump = require('gulp-bump');
Require yargs
var args = require('yargs').argv;
Your bump task
gulp.task('bump', function () {
/// <summary>
/// It bumps revisions
/// Usage:
/// 1. gulp bump : bumps the package.json and bower.json to the next minor revision.
/// i.e. from 0.1.1 to 0.1.2
/// 2. gulp bump --version 1.1.1 : bumps/sets the package.json and bower.json to the
/// specified revision.
/// 3. gulp bump --type major : bumps 1.0.0
/// gulp bump --type minor : bumps 0.1.0
/// gulp bump --type patch : bumps 0.0.2
/// gulp bump --type prerelease : bumps 0.0.1-2
/// </summary>
var type = args.type;
var version = args.version;
var options = {};
if (version) {
options.version = version;
msg += ' to ' + version;
} else {
options.type = type;
msg += ' for a ' + type;
}
return gulp
.src(['Path to your package.json', 'path to your bower.json'])
.pipe(bump(options))
.pipe(gulp.dest('path to your root directory'));
});
VSO Note: I believe a lot of people coming to this thread will be looking exactly for the answer above. The code below is to edit a version number stored somewhere BESIDES the npm/bower package files, such as in angular constants:
gulp.task('increment-version', function(){
//docString is the file from which you will get your constant string
var docString = fs.readFileSync('./someFolder/constants.js', 'utf8');
//The code below gets your semantic v# from docString
var versionNumPattern=/'someTextPreceedingVNumber', '(.*)'/; //This is just a regEx with a capture group for version number
var vNumRexEx = new RegExp(versionNumPattern);
var oldVersionNumber = (vNumRexEx.exec(docString))[1]; //This gets the captured group
//...Split the version number string into elements so you can bump the one you want
var versionParts = oldVersionNumber.split('.');
var vArray = {
vMajor : versionParts[0],
vMinor : versionParts[1],
vPatch : versionParts[2]
};
vArray.vPatch = parseFloat(vArray.vPatch) + 1;
var periodString = ".";
var newVersionNumber = vArray.vMajor + periodString +
vArray.vMinor+ periodString +
vArray.vPatch;
gulp.src(['./someFolder/constants.js'])
.pipe(replace(/'someTextPreceedingVNumber', '(.*)'/g, newVersionNumber))
.pipe(gulp.dest('./someFolder/'));
});
I ommitted some mumbo-jumbo that writes my constant in a pretty string, but that's the gist and it works.
这篇关于如何通过咕嘟咕嘟任务递增版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!