/
main.js
executable file
·74 lines (61 loc) · 2.37 KB
/
main.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
module.declare(["nodejs/path", "nodejs/fs", "pinf/loader"], function(require, exports, module)
{
var PATH = require("nodejs/path"),
FS = require("nodejs/fs"),
PINF_LOADER = require("pinf/loader");
var exclude = [
"ACE",
"JetpackExtension",
"Narwhal",
"NPMPackage",
"PersevereExampleWiki",
"PostCommitProgramReload"
];
exports.main = function()
{
var basePath = PATH.dirname(PATH.dirname(PATH.dirname(module.id))) + "/demos";
FS.readdir(basePath, function(err, files)
{
var count = 0;
files.forEach(function(filename) {
var exists = true;
try {
FS.statSync(basePath + "/" + filename + "/program.json");
} catch(e) { exists = false; }
if (!exists || exclude.indexOf(filename) > -1)
{
module.print("Skipping demo: " + basePath + "/" + filename + " (you need to run manually for now)\n");
return;
}
module.print("Running demo: " + basePath + "/" + filename + "\n");
count++;
PINF_LOADER.runProgram({
"uri": basePath + "/" + filename,
"exec": true,
"options": [
"--terminate"
]
}, function(stdout, stderr) {
if (stderr)
{
throw new Error("Demo '" + basePath + "/" + filename + "' failed: " + stderr);
}
if (stdout)
{
var parts = stdout.split("\n"),
ending = new String(parts.slice(parts.length-2, parts.length).join("").replace(/\033.*?m/g, ""));
if (!/OK$/.test(ending))
throw new Error("Demo '"+basePath + "/" + filename+"' failed: " + stdout);
}
else
throw new Error("Demo '"+basePath + "/" + filename+"' failed. No stdout.");
count--;
if (count==0)
{
module.print("OK");
}
});
});
});
}
});