在Grunt任务中运行命令 [英] Running a command in a Grunt Task

查看:154
本文介绍了在Grunt任务中运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用 Grunt (用于JavaScript项目的基于任务的命令行构建工具)。我创建了一个自定义标签,我想知道是否可以运行一个命令到它。



为了澄清,我试图使用Closure模板和任务应该调用jar文件将Soy文件预编译为javascript文件。



我从命令行运行这个jar,但是我想设置它作为一个任务。

解决方案

我找到了一个解决方案,

我在节点下使用grunt,所以需要'child_process'模块调用终端命令。



  var myTerminal = require(child_process)。exec,
commandToBeExecuted =sh myCommand.sh;

myTerminal(commandToBeExecuted,function(error,stdout,stderr){
if(!error){
// do something
}
} ;


I'm using Grunt (task-based command line build tool for JavaScript projects) in my project. I've created a custom tag and I am wondering if it is possible to run a command into it.

To clarify, I'm trying to use Closure Templates and "the task" should call the jar file to pre-compile the Soy file to a javascript file.

I'm running this jar from command line, but I want to set it as a task.

解决方案

I've found a solution so I'd like to share with you.

I'm using grunt under node so, to call terminal commands you need to require 'child_process' module.

For example,

var myTerminal = require("child_process").exec,
    commandToBeExecuted = "sh myCommand.sh";

myTerminal(commandToBeExecuted, function(error, stdout, stderr) {
    if (!error) {
         //do something
    }
});

这篇关于在Grunt任务中运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆