-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.js
More file actions
59 lines (56 loc) · 1.49 KB
/
util.js
File metadata and controls
59 lines (56 loc) · 1.49 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { spawnSync } = require('child_process');
const rls = require('readline-sync');
let runtry = 0;
let calls = 0;
const runlimit = 100;
const fails = {};
function run(command, args, search) {
if (global.env !== undefined && args[0] !== '--environment') {
args = ['--environment', global.env, '--use-frame'].concat(args); // eslint-disable-line no-param-reassign
}
console.log(command, args);
const cmdline = [command].concat(args).join(' ');
const p = spawnSync(command, args);
calls += 1;
const so = p.stdout;
const lines = String.fromCharCode(...so).split('\n');
console.log(`${so}`);
if (p.status) {
console.log(p.status);
if (runtry < runlimit) {
const q = rls.question('Press ENTER to repeat, enter return value to continue: ');
if (q) {
return q;
}
if (cmdline in fails) {
fails[cmdline] += 1;
} else {
fails[cmdline] = 0;
}
runtry += 1;
console.log('Try:', runtry);
return run(command, args, search);
}
throw p.status;
} else {
runtry = 0;
}
const re = new RegExp(search);
let res = '';
for (let i = 0; i < lines.length; i += 1) {
const line = lines[i];
if (re.exec(line)) {
const re2 = /0x[A-Za-z0-9]+/;
const re2exec = re2.exec(line);
if (re2exec) {
[res] = re2exec;
return res;
}
}
}
return res;
}
module.exports.run = run;
module.exports.calls = () => calls;
module.exports.fails = fails;
// vim:ts=2:sts=2:sw=2:et: