【发布时间】:2013-11-27 16:53:48
【问题描述】:
我想访问 grunt 生态系统中的许多可用插件和任务,以使我的生活更轻松,但我想控制每个任务的运行时间和方式。最重要的是,我想要一种以编程方式运行 grunt 任务的方法,而不是从带有Gruntfile 的文件夹中的命令行运行grunt。所以我开始在grunt-cli 和grunt 周围寻找“进入”的途径。
来自GruntJS的源码:
// Expose the task interface. I've never called this manually, and have no idea
// how it will work. But it might.
grunt.tasks = function(tasks, options, done) {
...
如您所见,Allman 先生提醒我们注意界面...我的问题是,有没有人让它工作?
到目前为止,我的实验使我相信以编程方式控制 grunt 的最佳方法是通过子进程模仿命令行调用:
$ npm install grunt-cli //notice no -g flag
// From runner.js
var exec =require('child_process').exec
exec('node_modules/.bin/grunt-cli tasks to run', {
cwd: 'path/to/directory/with/a/gruntfile'
}, function() { /* do stuff here */ });
这看起来很脏,所以我正在考虑简单地编写我自己的任务运行器,它为 grunt 任务公开一个接口。但是,如果有人在 grunt.tasks() 上取得成功,尽管有 Allman 先生的警告,我不想重复工作。
【问题讨论】:
-
如果你举个例子说明你正在尝试做什么,这可能会更容易回答。
-
谢谢...我会添加一些伪代码
标签: javascript node.js gruntjs