@accessors-hosts/node 中文文档教程
$Id: README.txt 1887 2017-06-20 21:54:51Z cxh $
此目录包含 Node.js swarmlet 主机的实现。
要启动 Node.js 主机的交互式版本,请调用:
node nodeHostShell.js
,它应该显示:
欢迎使用 Node swarmlet 主机 (nsh)。 键入 exit 退出,help 寻求帮助。 nsh>
在提示符 (nsh>) 处,您可以输入 JavaScript 语句或表达式。
要实例化并运行测试访问器,请执行以下操作:
nsh>; var a = instantiate('myAccessorName', 'test/TestAccessor');
下面是一个完整会话的示例,让您了解可以做什么:
----------------------start
node nodeHostShell.js 欢迎使用 Node swarmlet 主机 (nsh)。 键入 exit 退出,help 寻求帮助。
nsh> var a = instantiate('myAccessorName', 'test/TestAccessor'); 读取访问器:/ptII/org/terraswarm/accessor/accessors/web/test/TestAccessor.js 具有类 test/TestAccessor 的实例化访问器 myAccessorName 未定义
nsh> a.初始化(); 未定义
nsh> a.输入列表 [ 'untyped', 'numeric', 'boolean' ]
nsh>; a.provideInput('untyped', 'hello world'); 未定义
nsh> a.反应(); 调用 TestAccessor.fire()。
nsh> a.输出列表 [ 'typeOfUntyped', 'jsonOfUntyped', 'numericPlusP', 'negation']
nsh>; a.latestOutput('typeOfUntyped'); 字符串
nsh> a.latestOutput('jsonOfUntyped'); 无类型输入的 JSON:"hello world"
nsh>; 辞职 出口 ----------------------结束
运行一个简单的测试,假设你在这个测试目录中:
node ../nodeHost.js < testNodeHost.js
testNodeHost.js 文件仅包含收集到文件中的上述命令。 您将看到以下输出:
欢迎使用 Node swarmlet 主机 (nsh)。 键入 exit 退出,help 寻求帮助。 nsh> // 这只是对 Node.js 主机的简单冒烟测试。 不明确的 nsh> // 要使用它,请运行节点主机并将以下内容复制并粘贴到其中。 不明确的 nsh> var a = instantiate('TestComposite', 'test/TestComposite'); 读取访问器:/ptII/org/terraswarm/accessor/accessors/web/test/TestComposite.js 读取访问器:/ptII/org/terraswarm/accessor/accessors/web/test/TestGain.js 读取访问器:/ptII/org/terraswarm/accessor/accessors/web/test/TestAdder.js 具有类 test/TestComposite 的实例化访问器 TestComposite 不明确的 nsh> a.初始化(); 不明确的 nsh> a.provideInput('输入', 10); 不明确的 nsh> a.反应(); 不明确的 nsh> a.latestOutput('输出'); // 应该返回 50 50 nsh> a.总结(); 不明确的 nsh> 辞职; 退出
Install the npm @accessors-hosts/node package on the npm server.
(这是供此节点模块的维护者使用的。)
我们正在使用一个名为 npmjs 上的 'terraswarm' 用于管理 @accessors-hosts/node 包的存储库。
要在 npmjs 上更新 @accessors-hosts/node 包:
更新 package.json 中的补丁号
登录到 npm npm 登录
Username: terraswarm Password: See ~terra/.npmpass on terra Email: terraswarm-software@terraswarm.org
发布: npm 发布 --access public
$Id: README.txt 1887 2017-06-20 21:54:51Z cxh $
This directory contains an implementation of a Node.js swarmlet host.
To start the interactive version of the Node.js host, invoke:
node nodeHostShell.js
which should display:
Welcome to the Node swarmlet host (nsh). Type exit to exit, help for help. nsh>
At the prompt (nsh>), you can enter JavaScript statements or expressions.
To instantiate and run a test accessor, do this:
nsh> var a = instantiate('myAccessorName', 'test/TestAccessor');
Below is an example of a complete session, to give you an idea of what can be done:
---------------------start
node nodeHostShell.js Welcome to the Node swarmlet host (nsh). Type exit to exit, help for help.
nsh> var a = instantiate('myAccessorName', 'test/TestAccessor'); Reading accessor at: /ptII/org/terraswarm/accessor/accessors/web/test/TestAccessor.js Instantiated accessor myAccessorName with class test/TestAccessor undefined
nsh> a.initialize(); undefined
nsh> a.inputList [ 'untyped', 'numeric', 'boolean' ]
nsh> a.provideInput('untyped', 'hello world'); undefined
nsh> a.react(); TestAccessor.fire() invoked.
nsh> a.outputList [ 'typeOfUntyped', 'jsonOfUntyped', 'numericPlusP', 'negation' ]
nsh> a.latestOutput('typeOfUntyped'); string
nsh> a.latestOutput('jsonOfUntyped'); JSON for untyped input: "hello world"
nsh> quit exit -----------------------end
To run a simple test, assuming you are in this test directory:
node ../nodeHost.js < testNodeHost.js
The testNodeHost.js file just contains the above commands collected into a file. You will see the following output:
Welcome to the Node swarmlet host (nsh). Type exit to exit, help for help. nsh> // This is just a simple smoke test for the Node.js host. undefined nsh> // To use it, run the node host and copy and paste the following into it. undefined nsh> var a = instantiate('TestComposite', 'test/TestComposite'); Reading accessor at: /ptII/org/terraswarm/accessor/accessors/web/test/TestComposite.js Reading accessor at: /ptII/org/terraswarm/accessor/accessors/web/test/TestGain.js Reading accessor at: /ptII/org/terraswarm/accessor/accessors/web/test/TestAdder.js Instantiated accessor TestComposite with class test/TestComposite undefined nsh> a.initialize(); undefined nsh> a.provideInput('input', 10); undefined nsh> a.react(); undefined nsh> a.latestOutput('output'); // Should return 50 50 nsh> a.wrapup(); undefined nsh> quit; exit
Install the npm @accessors-hosts/node package on the npm server.
(This is for the use of maintainers of this node module.)
We are using an account named 'terraswarm' on the npmjs repository to manage the @accessors-hosts/node package.
To update the @accessors-hosts/node package on npmjs:
Update the patch number in package.json
Login to npm npm login
Username: terraswarm Password: See ~terra/.npmpass on terra Email: terraswarm-software@terraswarm.org
Publish: npm publish --access public