How to develop a javascript library from an already existing npm module (codius)

时间:2015-06-30 13:34:58

标签: javascript node.js npm

never done this before.

I'm using https://github.com/codius/codius-host. Codiu§ development has been abandoned, but I want to salvage part of it to use for my own project. I really need to be able to run codius commands from browser, so I need to develop a library or what you call it.

var codius = require('codius')

codius.upload({host: http://contract.host}

codius-host comes packed with command-line integration,

$ CODIUS_HOST=https://codius.host codius upload

How do I make a .js script do what the command-line command does ?

also posted on https://stackoverflow.com/questions/31126511/if-i-have-a-npm-tool-that-uses-comman-line-commands-how-can-i-create-a-javascri hard time asking this questions since don't know where to start. help.

1 个答案:

答案 0 :(得分:2)

假设您可以访问codius-host源代码,您应该找到管理命令行参数的代码段。我确信他们确实从入口模块/函数处理命令和命令行参数,然后将实际作业委托给不同的模块/函数。您需要做的是为使用命令行参数处理命令行参数调用的函数/模块的函数提供正确的参数。

除此之外,还有一些nodejs库可能模仿程序本身的命令行调用。其中一个我知道的是shelljs:

https://www.npmjs.com/package/shelljs

您可能也想查看此信息。有了这个没有烦恼的源代码,你可能会模仿命令行行为。