-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathlively-runtime.js
85 lines (77 loc) · 2.87 KB
/
lively-runtime.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
lively.require("lively.lang.Runtime").toRun(function() {
var r = lively.lang.Runtime;
r.Registry.addProject(r.Registry.default(), {
name: "paredit-js",
rootDir: "/Users/robert/Lively/paredit-js",
reloadAll: function(project, thenDo) {
// var project = r.Registry.default().projects["paredit-js"];
// project.reloadAll(project, function(err) { err ? show(err.stack || String(err)) : alertOK("reloaded!"); })
var files = ["./index.js",
'./lib/util.js',
"./lib/reader.js",
"./lib/navigator.js",
"./lib/editor.js",
"./tests/reader-test.js",
"./tests/navigator-test.js",
"./tests/editor-test.js"
];
lively.lang.fun.composeAsync(
function livelyDeps(n) {
require("lively.MochaTests").toRun(function() {
project.state = {window: {chai: window.chai}};
n();
});
},
function readFiles(n) {
lively.lang.arr.mapAsyncSeries(files,
function(fn,_,n) {
lively.shell.cat(fn, {cwd: project.rootDir},
function(err, c) { n(err, {name: fn, content: c}); });
}, n);
},
function(fileContents, next) {
lively.lang.arr.mapAsyncSeries(fileContents,
function(ea,_,n) { r.Project.processChange(project, ea.name, ea.content, n); },
next);
},
function(results, n) {
window.paredit = project.state.paredit;
n(null, results);
}
)(thenDo);
},
resources: {
"code": {
matches: /(lib\/.*|index)\.js$/,
changeHandler: function(change, project, resource, whenHandled) {
var state = project.state;
evalCode(change.newSource, state, change.resourceId);
whenHandled();
}
},
"tests": {
matches: /tests\/.*\.js$/,
changeHandler: function(change, project, resource, whenHandled) {
if (!project.state) {
var msg = "cannot update runtime state for " + change.resourceId + "\n because the lib code wasn't loaded."
show(msg); whenHandled(new Error(msg)); return;
}
lively.requires("lively.MochaTests").toRun(function() {
evalCode(change.newSource, project.state, change.resourceId);
// lively.MochaTests.runAll();
whenHandled();
});
}
}
}
});
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function evalCode(code, state, resourceName) {
lively.lang.VM.runEval(code,
{topLevelVarRecorder: state, context: state, sourceURL: resourceName},
function(err, _result) {
err && show("error when updating the runtime for " + resourceName + "\n" + (err.stack || err));
!err && alertOK("updated");
});
}
});