Skip to content

Instantly share code, notes, and snippets.

@ensonic
Last active August 29, 2015 14:19
Show Gist options
  • Save ensonic/47bfd8dfb325be43ff38 to your computer and use it in GitHub Desktop.
Save ensonic/47bfd8dfb325be43ff38 to your computer and use it in GitHub Desktop.
runtime
#!/usr/bin/env node
program = require 'commander'
http = require 'http'
noflo = require 'noflo'
runtime = require 'noflo-runtime-websocket'
querystring = require 'querystring'
program
.option('--host <hostname>', 'Hostname or IP for the runtime.', '127.0.0.1')
.option('--port <port>', 'Port for the runtime', parseInt, '3569')
.option('--capture-output [true/false]', 'Catch writes to stdout and send to the FBP protocol client (default = false)', false)
.option('--catch-exceptions [true/false]', 'Catch exceptions and report to the FBP protocol client (default = true)', true)
.parse process.argv
startServer = (program, graph) ->
server = http.createServer ->
rt = runtime server,
defaultGraph: graph
baseDir: graph.baseDir
captureOutput: program.captureOutput
catchExceptions: program.catchExceptions
defaultPermissions: [
'protocol:graph'
'protocol:component'
'protocol:network'
'protocol:runtime'
'component:setsource'
'component:getsource'
]
server.listen program.port, ->
address = 'ws://' + program.host + ':' + program.port
params = 'protocol=websocket&address=' + address
console.log 'NoFlo runtime listening at ' + address
console.log 'Live IDE URL: <noflo-ui>#runtime/endpoint?' + querystring.escape(params)
return
return
createGraph = () ->
graph = noflo.graph.createGraph "linecount"
graph.baseDir = process.env.PROJECT_HOME or process.cwd()
graph.addNode "Read File", "filesystem/ReadFile"
graph.addNode "Split by Lines", "strings/SplitStr"
graph.addNode "Count Lines", "packets/Counter"
graph.addNode "Display", "core/Output"
graph.addEdge "Read File", "out", "Split by Lines", "in"
graph.addEdge "Split by Lines", "out", "Count Lines", "in"
graph.addEdge "Count Lines", "count", "Display", "in"
# Kick the process off by sending filename to fileReader
# graph.addInitial "package.json", "Read File", "in"
console.log 'Created the graph'
# this will start the graph
#noflo.createNetwork graph
graph
# create graph and start server
startServer program, createGraph()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment