-
Notifications
You must be signed in to change notification settings - Fork 9
/
make.js
86 lines (68 loc) · 1.97 KB
/
make.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
86
const { spawn } = require('child_process');
const fs = require('fs');
const args = process.argv.slice(2);
if (args.length === 0) args.push("all");
let _ = tasks();
if (args[0] === "?") _.help();
else {
(async () => {
for (arg of args) await _[arg]();
})();
}
function tasks() {
let _ = {};
_.help = async function() {
console.log(Object.keys(_));
}
_.test = async function() {
await _.node("all.js");
}
_.all = async function() {
await _.files();
await _.build(false);
await _.timeit(_.test);
}
_.ex1 = async function() {
await _.files();
await _.build(true);
await _.timeit(_.test);
}
_.build = async function(ex1) {
const files = ['files.js', 'i8080.js', 'i8080_disasm.js', 'i8080_trace.js', 'i8080_test.js'];
files.push(ex1 ? "main_ex1.js" : "main.js");
let contents = [];
console.log(files);
files.forEach((name) => {
contents.push(fs.readFileSync(name));
console.log(name, contents[contents.length - 1].length);
});
const raw = Buffer.concat(contents);
console.log("all.js", raw.length);
fs.writeFileSync("all.js", raw);
}
_.files = async function() {
await _.node('rkdump >files.js');
}
// -------------------------------------
_.timeit = async function(cb) {
const { performance } = require('perf_hooks');
const started = performance.now();
await cb();
const duration = (performance.now() - started) / 1000;
console.log(`${duration.toFixed(2)}(s) ${(duration / 60).toFixed(2)}(m)`)
}
_.run = async function(cmd) {
console.log(cmd);
const exe = await spawn(cmd, [], { shell: true });
exe.on("error", (code) => { console.log("error", code) });
exe.on("exit", (code) => { console.log("exited", code); });
exe.stderr.on("data", (data) => { console.log("ERROR", data.toString())});
for await (line of exe.stdout) {
process.stdout.write(line.toString());
}
}
_.node = async function(cmd) {
await _.run(`node ${cmd}`);
}
return _;
}