2012-01-10 102 views
6

我正在寻找为Node.js 编写的库,我可以使用它来管理我在Mercurial HG中创建的本地存储库的web应用程序 。适用于本地存储库的Node.js Mercurial HG库

任何人都执行类似的东西?

+1

如果它不是http://search.npmjs.org/或可能https://github.com/joyent/node/wiki/modules它不存在(公开) – 2012-01-10 10:35:15

回答

7

我从来没有听说过这样的图书馆 - 它尚未在our mailinglist上公布。 Mercurial的稳定API是command line,所以我建议直接启动hg并解析输出。它的设计易于屏幕抓取,您可以使用templates进一步对其进行自定义。

+1

如果使用命令服务器,则可以避免启动时的开销,但这需要更多的努力。 – 2012-01-10 11:01:09

+0

我想过了,但作为最终的解决方案。感谢您的回答。 – mrzepinski 2012-01-11 07:03:52

+0

如果您发现答案有帮助(认为它是负面的),那么请记住注册并接受它。 – 2012-01-13 12:58:32

6

正是因为这个原因,我在npm上创建了一个名为node-hg的模块。

这是一个围绕Command Server的包装,它通过stdin发出命令并解析stdout上的输出。

这里是它如何工作的例子:

var path = require("path"); 

var hg = require("hg"); 

// Clone into "../example-node-hg" 
var destPath = path.resolve(path.join(process.cwd(), "..", "my-node-hg")); 

hg.clone("http://bitbucket.org/jgable/node-hg", destPath, function(err, output) { 
    if(err) { 
     throw err; 
    } 

    output.forEach(function(line) { 
     console.log(line.body); 
    }); 

    // Add some files to the repo with fs.writeFile, omitted for brevity 

    hg.add(destPath, ["someFile1.txt", "someFile2.txt"], function(err, output) { 
     if(err) { 
      throw err; 
     } 

     output.forEach(function(line) { 
      console.log(line.body); 
     }); 

     var commitOpts = { 
      "-m": "Doing the needful" 
     }; 

     // Commit our new files 
     hg.commit(destPath, commitOpts, function(err, output) { 
      if(err) { 
       throw err; 
      } 

      output.forEach(function(line) { 
       console.log(line.body); 
      }); 
     }); 
    }); 
}); 
相关问题