Skip to content

Commit

Permalink
Read browser components from the component.json file, refs noflo#63
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Apr 25, 2013
1 parent 304dc95 commit 7968861
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
17 changes: 0 additions & 17 deletions components.js

This file was deleted.

4 changes: 2 additions & 2 deletions spec/ComponentLoader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ if typeof process is 'object' and process.title is 'node'
root = path.resolve __dirname, '../'
else
loader = require 'noflo/lib/ComponentLoader.js'
root = '/noflo/'
root = 'noflo'

describe 'Component Loader with no external packages installed', ->
describe 'ComponentLoader with no external packages installed', ->
l = new loader.ComponentLoader root

it 'should initially know of no components', ->
Expand Down
2 changes: 1 addition & 1 deletion spec/Network.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if typeof process is 'object' and process.title is 'node'
root = path.resolve __dirname, '../'
else
noflo = require 'noflo/lib/NoFlo.js'
root = '/noflo/'
root = 'noflo'

describe 'Network with an empty graph', ->
g = new noflo.Graph
Expand Down
27 changes: 22 additions & 5 deletions src/lib/ComponentLoader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,34 @@ class ComponentLoader

getModulePrefix: (name) ->
return '' unless name
return '' if name is 'noflo'
name.replace 'noflo-', ''

getModuleComponents: (moduleName) ->
return unless @checked.indexOf(moduleName) is -1
@checked.push moduleName

try
definition = require "/#{moduleName}/component.json"
catch e
return

for dependency of definition.dependencies
@getModuleComponents dependency

return unless definition.noflo

prefix = @getModulePrefix definition.name
if definition.noflo.components
for name, cPath of definition.noflo.components
@registerComponent prefix, name, "/#{definition.name}/#{cPath}"

listComponents: (callback) ->
return callback @components unless @components is null

# Interim solution for loading registered components
# until component/builder.js#62 is fixed
@components = {}
registration = require "#{@baseDir}components.js"
registration.register @

@getModuleComponents @baseDir

callback @components

Expand All @@ -30,7 +48,6 @@ class ComponentLoader
@listComponents (components) =>
@load name, callback
return

unless @components[name]
throw new Error "Component #{name} not available"
return
Expand Down

0 comments on commit 7968861

Please sign in to comment.