2

我花了很多时间在 Coffeescript 中构建这个美妙的 Cakefile 来构建所有东西,现在我希望能够cake build使用与我的程序相关的另一个别名从该目录外部运行命令。

有没有办法cake build从可执行文件中运行?我可以通过 npm 在“/bin”下执行什么?

4

2 回答 2

4

正如 Noli 所说,唯一的方法是逆向工程cake.js或更简单地cake从目标目录运行命令。在 Node 下,您可以通过将选项设置为所需的工作目录来使用child_process.spawn来执行此操作。cwd

于 2011-05-02T19:43:00.900 回答
3

看起来没有命令行选项可以做到这一点

https://github.com/jashkenas/coffee-script/blob/master/lib/cake.js#L38

  exports.run = function() {
    return path.exists('Cakefile', function(exists) {
      var arg, args, _i, _len, _ref, _results;
      if (!exists) {
        throw new Error("Cakefile not found in " + (process.cwd()));
      }

因此,您的进程可能需要先“cd”到 Cakefile 的目录才能运行它。(或者你可以修补咖啡脚本来争论)

于 2011-05-02T10:41:59.913 回答