-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathparsePluginSlots.js
More file actions
58 lines (42 loc) · 1.66 KB
/
parsePluginSlots.js
File metadata and controls
58 lines (42 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const fs = require('fs')
const vm = require('vm')
const createVizorSandbox = require('./sandbox')
const browserPath = __dirname+'/../browser'
const pluginsPath = browserPath+'/plugins'
module.exports = function parsePluginSlots() {
var sandbox = createVizorSandbox()
var context = new vm.createContext(sandbox)
var engineSource = fs.readFileSync(browserPath+'/dist/engine.js')
engineSource += ';\nE2.core = new Core();\n'
engineSource += ';\nE2.app = { player: { core: E2.core }};\n'
engineSource += 'E2.core.root_graph = new Graph();\n'
var engineScript = new vm.Script(engineSource, { filename: 'engine.js' })
engineScript.runInContext(context)
var slotMap = {}
function seenSlot(pluginId, slotType) {
var key = pluginId + '.' + slotType
return function(slot) {
if (!slotMap[key])
slotMap[key] = []
slotMap[key].push(slot.name)
}
}
var plugins = JSON.parse(fs.readFileSync(pluginsPath + '/plugins.json'))
var pluginCats = Object.keys(plugins)
pluginCats.map(function(cat) {
var pluginNames = Object.keys(plugins[cat])
pluginNames.map(function(pluginName) {
var pluginId = plugins[cat][pluginName]
var pluginSourcePath = pluginsPath+'/'+pluginId+'.plugin.js'
var pluginSource = fs.readFileSync(pluginSourcePath)
pluginSource += ';\n'
pluginSource += 'var fakeNode = new Node(E2.core.root_graph, "'+pluginId+'");\n'
pluginSource += 'var plugin = new E2.plugins.'+pluginId+'(E2.core, fakeNode);\n'
script = new vm.Script(pluginSource, { filename: pluginId })
script.runInContext(context)
sandbox.plugin.input_slots.map(seenSlot(pluginId, 0))
sandbox.plugin.output_slots.map(seenSlot(pluginId, 1))
})
})
return slotMap
}