2

我想为我的迁移提供生成器,例如:

jake migration:create <name>

jake migration:remove <name>

jake migration:execute <name>

代码是

namespace('migration', function(){
  desc('Create migration file');
  task('create', [], function(params) {
    console.log(arguments);
    //some code for creation
  });

  desc('Remove migration file');
  task('remove', [], function(params) {
    console.log(arguments);
    //some code for removing
  });

  desc('Execute migration file');
  task('execute', [], function(params) {
    console.log(arguments);
    //some code for executing
  });

});

但我没有找到如何<name>在“命名空间”杰克任务中传递参数。请你帮助我好吗?

UPD:即使来自https://github.com/isaacs/node-jake “将参数传递给 jake”的示例对我来说也不起作用,每次arguments都是空的,有什么建议吗?

4

1 回答 1

4

你应该检查:https ://github.com/mde/jake

您将参数作为逗号分隔的列表传递:

杰克迁移:创建[运行,富,酒吧]

然后在你的函数中捕获它们作为参数:

namespace('migration', function(){
    desc('Create migration file');
    task('create', [], function(p1,p2,p3) {
        console.log(p1,p2,p3);
        //some code for creation
  });

  desc('Remove migration file');
  task('remove', [], function(p1,p2,p3) {
    console.log(p1,p2,p3);
    //some code for removing
  });

  desc('Execute migration file');
  task('execute', [], function(p1,p2,p3) {
    console.log(p1,p2,p3);
    //some code for executing
  });

});
于 2011-09-13T13:47:50.380 回答