关于 issue I am having with gulp-tag-version ,那里的自述文件建议:
function inc(importance) {
// get all the files to bump version in
return gulp.src(['./package.json', './bower.json'])
// bump the version number in those files
.pipe(bump({type: importance}))
// save it back to filesystem
.pipe(gulp.dest('./'))
/* Recompile the Javascript here */
// commit the changed version number
.pipe(git.commit('bumps package version'))
// read only one file to get the version number
.pipe(filter('package.json'))
// **tag it in the repository**
.pipe(tag_version())
}
gulp.task('patch', function() { return inc('patch'); })
gulp.task('feature', function() { return inc('minor'); })
gulp.task('release', function() { return inc('major'); })
我想在被修改的版本和 git 标记之间重新编译一些 Javascript。我有一个任务,js
,但不清楚如何调用 js
任务(或以其他方式重新排序 bump/tag 任务)来完成此任务常见且理想的结果(即在编译代码的 header 中包含版本)。
还值得注意的是,如果有三个任务 bump
、compile
和 tag
,则 bump
的 package.json
似乎被缓存并且没有被单独的 tag
任务重新读取。
最佳答案
实现此功能的一个简单方法是获取 3 个相互依赖的新任务:
tag
依赖于commit
,因为标签将应用于最后一次提交,我们必须在此之前完成commit
依赖于js
,因为我们应该用 bumped 版本重新构建你的文件js
依赖于bump
,在做任何事情之前先修改 list 文件的版本bump
没有依赖关系。
问题在于您必须更改 js
以添加 bump
依赖项,我敢肯定您不想每次都碰到你重新编译或者你的一个 watch
被触发。
所以你可以使用类似 run-sequence 的东西 绕过它。
还有一件事我喜欢减少 gulp 任务的数量是使用参数,但如果你愿意,你可以坚持使用 inc
函数,这是一个细节(这里 --major
, --minor
, or --patch
).
所以你可以这样做(按照执行顺序从上到下):
gulp.task('uprev', function () {
return gulp.src(['./package.json', './bower.json'])
.pipe(bump({ type: process.argv[3] ? process.argv[3].substr(2) : 'patch' }))
.pipe(gulp.dest('./'));
});
gulp.task('rebuild', function (cb) {
runSequence('uprev', 'js', cb); //uprev will here be executed before js
});
gulp.task('commit', ['rebuild'], function () {
return gulp.src(['./package.json', './bower.json', 'dist/**/*'])
.pipe(git.add())
.pipe(git.commit('bump version'));
});
gulp.task('bump', ['commit'], function () {
return gulp.src('package.json')
.pipe(tagVersion());
});
对于您的提交,您可能想要添加您的 list 和编译文件,我已经添加了一个随机 dist
文件夹的所有内容用于演示。
我特意削减了 bump
和 commit
任务,这样您就不必使用 gulp-filter,这在我看来是这样的对于这种小东西来说没什么用,但它当然是你想要的。
最后一件事( promise ),您可以通过使用简单的 node fs 调用 结合 gulp-git< 来避免使用 gulp-tag-version/em> 你已经拥有:
gulp.task('bump', ['commit'], function (cb) {
fs.readFile('./package.json', function (err, data) {
if (err) { return cb(err); }
var version = JSON.parse(data.toString()).version;
git.tag(version, 'Version message', function (err) {
cb(err);
});
});
关于javascript - Gulp - 重新编译一个用于标记的 bumped 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26365569/