-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhar-utils.js
More file actions
74 lines (65 loc) · 2.49 KB
/
har-utils.js
File metadata and controls
74 lines (65 loc) · 2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env node
/**
* @file har-utils.js
* @summary Menu/launcher for the HAR toolchain.
* @description Presents C/G/R/Q options, spawns the respective script with inherited stdio, and loops until Quit.
*/
const { spawn } = require('child_process');
/** Readline helpers for menu input and prompts with defaults. */
const { rlCreate, askWithDefault } = require('./build-har-common');
/**
* Run a Node.js script once as a child process and return its exit code.
* @param {string} script Path to the script to execute with the current Node binary.
* @returns {Promise<number>} Child exit code (0 on normal completion).
*/
async function runOnce(script) {
return new Promise((resolve) => {
const child = spawn(process.execPath, [script], { stdio: 'inherit' });
child.on('exit', (code) => resolve(code ?? 0));
child.on('error', (err) => {
console.error('Failed to launch', script, err);
resolve(1);
});
});
}
/** Main loop: render menu, read choice, launch tool, repeat until Quit. */
(async () => {
while (true) {
const rl = rlCreate();
console.log("\n");
console.log("\n");
console.log('\n=== HAR Utilities Suite ===\n');
console.log('Available tools:');
console.log(' (C) Config Builder — scan SQL + HAR to define API↔SQL mappings.');
console.log(' (G) HAR Generator — generate synthetic HAR traffic from config.');
console.log(' (R) HAR Runner — execute HARs, measure API performance.');
console.log(' (X) eXit.\n');
const mode = (await askWithDefault(rl, 'Enter mode (C/G/R/X)', 'R')).trim().toUpperCase();
rl.close();
if (mode === 'X') {
console.log('Goodbye.');
process.exit(0);
}
let script;
switch (mode) {
case 'C':
script = 'build-har-config.js';
break;
case 'G':
script = 'build-har-generator.js';
break;
case 'R':
script = 'har-runner.js';
break;
default:
console.log('Unknown choice. Please enter C, G, R, or Q.');
continue;
}
const label =
mode === 'C' ? 'Config Builder (C mode)' :
mode === 'G' ? 'HAR Generator (G mode)' :
'HAR Runner (R mode)';
console.log(`\nLaunching ${label}...\n`);
await runOnce(script);
}
})();