-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (32 loc) · 1.05 KB
/
index.js
File metadata and controls
37 lines (32 loc) · 1.05 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
'use strict';
const agendaExamples = require('./agenda-examples');
const counterExample = require('./counter-example');
const fibonacciExample = require('./fibonacci-example');
const helloWorldExample = require('./hello-world-example')
const validatorExample = require('./validator-example');
const examples = {
agenda: agendaExamples,
'counter-example': counterExample,
fibonacci: fibonacciExample,
'hello-world': helloWorldExample,
'validator-example': validatorExample,
};
function runExample(group, example) {
const args = [...arguments].slice(1);
if (!(group in examples)) {
throw new Error(`Unknown example ${group} ${args.join(' ')}`);
}
let runner = examples[group];
if (!runner.run) {
runner = runner[args.shift()];
}
if (!runner.run) {
throw new Error(`Unknown example ${group} ${args.join(' ')}`);
}
return runner.run(...args)
.then(null, (err) => {
console.error(err.stack);
process.exit(1);
});
}
runExample(...process.argv.slice(2));