jharding / grunt-exec

Grunt plugin for executing shell commands.
https://npmjs.org/package/grunt-exec
Other
248 stars 47 forks source link

Provide an option to handle the data event #31

Closed qawemlilo closed 10 years ago

qawemlilo commented 11 years ago

It would be nice if users can create their own custom functions to handle the data event. I'm executing a command that checks my php files for syntax errors. I would like to be able parse each output as it comes and check if there are no errors, otherwise exit the process.

Example


---
    exec: {
        test: {
            cmd: "find ./component -name '*.php' -exec php -l {} ;",

            onOutData: function (data) {
                console.log(data);

                if (data.match(/Errors parsing|PHP Parse error/g)) {
                    process.exit(1);
                }
            },

            onErrData: function (data) {
                console.log(data);

                if (data.match(/Errors parsing|PHP Parse error/g)) {
                    process.exit(1);
                }
            }
    }

---
jharding commented 10 years ago

Hmm I'd prefer if this wasn't added to grunt-exec. For the use case you propose, I would suggest just modifying your shell command to look for the parse error itself and exit with 1 if it's found.