简体   繁体   中英

Grunt-init template execute shell command

Is there a way to execute a shell command when creating a grunt-init scaffolding template? For example I would like to execute "bower install" and "git init" after the project is created without having to enter the commands afterwards. The API does not seem to include this functionality.

The template.js is executed by node, so you can use anything node has to offer you.

I've managed to that with the child_process.exec :

var exec = require("child_process").exec;
...
exec("bower install", function(error, stdout, stderr) {
    if (error !== null) {
        console.log("Error: " + error);
    }
    done();
});

The only "problem" that I see is that you don't have any logs from bower, so if you are installing many components, it may take a while before any other visual feedback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM