我不太擅长 shell 脚本,但仍然找不到解决方案。我想运行命令 gulp tslint
如果返回错误,则中止脚本。
到目前为止我尝试了gulp tslint || exit 1
没有成功。我认为它以某种方式返回 true,即使当我在命令提示符下运行它时出现错误,例如
[12:30:14] Starting 'tslint'...
[12:30:14] Finished 'tslint' after 9.49 ms
[12:30:16] [gulp-tslint] error (quotemark) payment-types.ts[18, 53]: " should be '
我怎样才能让它发挥作用?
任何帮助表示赞赏。谢谢!
最佳答案
这看起来像是一个 gulp 问题,而不是一个 shell 问题。当 gulp 成功完成(即到达退出而没有引发错误)时,它不会告诉 shell 有任何问题。解决此问题的最佳方法是重新配置 gulp,将 lint 失败解释为错误。
您可以发布您的gulpfile.js
吗?特别是您的 tslint
任务。
可能看起来像
gulp.task('tslint', function() {
gulp.src("**/*.ts")
.pipe(tslint.report('prose'))
});
您可以通过将其更改为:
来指示您的记者在错误时失败:gulp.task('tslint', function() {
gulp.src("**/*.ts")
.pipe(tslint.report('prose', {emitError: true}))
});
编辑:查看 gulp-tslint README有关emitError的更多详细信息
关于linux - 如果命令在 Unix shell 中失败,如何中止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30478584/