当我试图用gulp提示符实现git时,我得到了一些错误。我试图让用户在输入命令时输入自己唯一的git提交消息。应该在用户输入gulp命令之后显示消息。
这是gulp命令
//git commit task with gulp prompt
gulp.task('commit', function(){
var message;
gulp.src('./*', {buffer:false})
.pipe(prompt.prompt({
type: 'input',
name: 'commit',
message: 'Please enter commit message...'
}, function(res){
message = res.commit;
}))
.pipe(git.commit(message));
});目前,在将命令输入终端后,我将得到以下错误。
TypeError: Cannot call method 'indexOf' of undefined
at Object.module.exports [as commit] (/Users/me/Desktop/Example 4/node_modules/gulp-git/lib/commit.js:15:18)
at Gulp.gulp.task.gulp.src.pipe.git.add.args (/Users/me/Desktop/Example 4/gulpfile.js:190:15)
at module.exports (/Users/me/Desktop/Example 4/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/Users/me/Desktop/Example 4/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/Users/me/Desktop/Example 4/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at Gulp.Orchestrator.start (/Users/me/Desktop/Example 4/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
at process._tickCallback (node.js:442:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:929:3
[?] Please enter commit message...发布于 2015-04-10 21:23:24
gulp-提示符在流中不能很好地工作,所以当git.commit仍然是undefined时,git(这里是:undefined)将被执行。因此,gulp git块需要在gulp提示的回调中移动:
// git commit task with gulp prompt
gulp.task('commit', function(){
// just source anything here - we just wan't to call the prompt for now
gulp.src('package.json')
.pipe(prompt.prompt({
type: 'input',
name: 'commit',
message: 'Please enter commit message...'
}, function(res){
// now add all files that should be committed
// but make sure to exclude the .gitignored ones, since gulp-git tries to commit them, too
return gulp.src([ '!node_modules/', './*' ], {buffer:false})
.pipe(git.commit(res.commit));
}));
});https://stackoverflow.com/questions/29568957
复制相似问题