---
title: "git grunt jshint实例"
author: "李俊良"
date: "2014-04-17T13:06:07Z"
tags: []
categories: ["研发管理"]
slug: "git-grunt-jshint"
draft: false
lastmod: "2014-04-17T13:06:07Z"
id: 2047762
url: "https://frosh.iteye.com/blog/2047762"
---

编辑.git/hook/pre-commit 文件

 

```
#!/usr/bin/env node                                                                                                                                                                
var spawn = require('child_process').spawn;
var grunt = spawn('grunt',['-gruntfile', '/opt/ninja-server/grunt/Gruntfile.js']);

grunt.stderr.on('data',function(data){
    console.log(data.toString());
});
grunt.stdout.on('data',function(data){
    data = data.toString();
    console.log(data);
    if(data.indexOf('without error') > -1){
        console.log('无语法错误，提交成功');
        process.exit(0);
    }else if(data.indexOf('Aborted due to warnings') > -1){
        console.log('存在语法错误，请先修改语法错误');
        process.exit(1);
    }   
});
```