我试图创建一个具有任务add .,commit以及push在一个命令行,如:gulp gitsend -m "My changes"
var gulp = require('gulp');
var argv = require('yargs').argv;
var git = require('gulp-git');
gulp.task('gitsend', function() {
if (argv.m) {
console.log('adding, commiting and pushing to git...');
return gulp.src('.')
.pipe(git.add())
.pipe(git.commit(argv.m)
.pipe(git.push('origin', 'master', function (err) {
if (err) throw err;
})));
}
});
Run Code Online (Sandbox Code Playgroud)
但这不起作用:它引发异常:
/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623
var written = dest.write(chunk);
^
TypeError: undefined is not a function
at write (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
at flow (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
at DestroyableTransform.pipeOnReadable (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:664:5)
at DestroyableTransform.emit (events.js:104:17)
at emitReadable_ (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:448:10)
at emitReadable (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:444:5)
at readableAddChunk (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:187:9)
at DestroyableTransform.Readable.push (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:149:10)
at DestroyableTransform.Transform.push (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:145:32)
at Array.forEach (native)
Run Code Online (Sandbox Code Playgroud)
知道出了什么问题,我该如何存档我的需求?谢谢你。
您可以拆分单个任务(添加、提交、推送),然后使用 run-sequence 运行它们,以确保在推送之前先完成添加和提交。
var gulp = require('gulp');
var argv = require('yargs').argv;
var git = require('gulp-git');
var runSequence = require('run-sequence');
gulp.task('init', function() {
console.log(argv.m);
});
gulp.task('add', function() {
console.log('adding...');
return gulp.src('.')
.pipe(git.add());
});
gulp.task('commit', function() {
console.log('commiting');
if (argv.m) {
return gulp.src('.')
.pipe(git.commit(argv.m));
}
});
gulp.task('push', function(){
console.log('pushing...');
git.push('origin', 'master', function (err) {
if (err) throw err;
});
});
gulp.task('gitsend', function() {
runSequence('add', 'commit', 'push');
});Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3580 次 |
| 最近记录: |