在 Grunt 任务中运行命令 [英] Running a command in a Grunt Task
问题描述
我在我的项目中使用 Grunt(用于 JavaScript 项目的基于任务的命令行构建工具).我创建了一个自定义标记,我想知道是否可以在其中运行命令.
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.
澄清一下,我正在尝试使用闭包模板,任务"应该调用 jar 文件将 Soy 文件预编译为 javascript 文件.
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.
我正在从命令行运行这个 jar,但我想将它设置为一个任务.
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.
我在 node 下使用 grunt,因此调用终端命令需要child_process"模块.
I'm using grunt under node so, to call terminal commands you need to require 'child_process' module.
例如
var myTerminal = require("child_process").exec,
commandToBeExecuted = "sh myCommand.sh";
myTerminal(commandToBeExecuted, function(error, stdout, stderr) {
if (!error) {
//do something
}
});
这篇关于在 Grunt 任务中运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!