-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrun.js
84 lines (73 loc) · 2.2 KB
/
run.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
var exec = require('child_process').exec, child;
/**
* Execute simple shell command (async wrapper).
* @param {String} cmd
* @return {Object} { stdout: String, stderr: String }
*/
async function sh(cmd) {
return new Promise(function (resolve, reject) {
exec(cmd, (err, stdout, stderr) => {
if (err) {
reject(err);
} else {
resolve({ stdout, stderr });
}
});
});
}
async function runTaikoExamples() {
var examples = await getExamples();
var failed = 0;
await asyncForEach(examples, async el => {
if(await runExample(el) == "failed") failed++;
});
var count = examples.length;
console.log(`${count} examples finished. ${failed} failed.`);
if(failed > 0) process.exit(-1);
}
async function runExample(el) {
console.log("Running example " + el + ":");
doLog(await sh(`spago -x examples.dhall bundle-app -m Examples.${el} --to examples/build/${el}.js`));
try {
doLog(await sh(`taiko ./taiko/test-${el}.js --observe`));
} catch (error) {
console.error(`Example ${el} failed!: ${error}`)
return "failed";
}
return "success";
}
async function buildExamples() {
await asyncForEach(await getExamples(), async el => {
console.log("Building example " + el + ":");
doLog(await sh(`spago bundle-app -x examples.dhall -m Examples.${el} --to examples/build/${el}.js`));
});
console.log("build finished");
}
function doLog(res) {
console.log(res.stdout);
console.error(res.stderr);
}
async function getExamples() {
var files = (await sh('ls examples/*.purs')).stdout.split('\n');
var res = [];
files.forEach(element => {
var m = element.match(/examples\/(.+)\.purs/i);
if(m !== null) {
res.push(m[1]);
}
});
return res;
}
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
var args = process.argv.slice(2);
if(args.length > 0) {
var cmd = args[0];
if(cmd === "test") runTaikoExamples();
if(cmd === "build") buildExamples();
} else {
runExample("Radialbarchart");
}