-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-process.js
More file actions
81 lines (74 loc) · 2.82 KB
/
post-process.js
File metadata and controls
81 lines (74 loc) · 2.82 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
75
76
77
78
79
80
81
import { exec } from 'child_process';
import winston from 'winston';
import fs from 'fs';
import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
// Configure Winston logger
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'post-process.log' })
]
});
const bugcheckCommands = {};
const processorsDir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'post-processors');
try {
const files = fs.readdirSync(processorsDir).filter(f => f.endsWith('.js'));
for (const file of files) {
const name = path.basename(file, '.js');
const filePath = path.join(processorsDir, file);
try {
// eslint-disable-next-line no-await-in-loop
const mod = await import(pathToFileURL(filePath).href);
bugcheckCommands[name] = mod.default;
logger.info(`Loaded post-processor: ${name} -> ${filePath}`);
} catch (err) {
logger.error(`Failed to load post-processor ${filePath}: ${err.stack || err}`);
}
}
} catch (err) {
logger.error(`Unable to read post-processors directory "${processorsDir}": ${err.stack || err}`);
}
// Function to execute a command and return a promise
const executeCommand = (command) => {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(error);
} else if (stderr) {
resolve(`Warnings: ${stderr}`);
} else {
resolve(stdout);
}
});
});
};
// Function to perform additional operations on the analysis results
const postProcessResults = async (results, parser) => {
for (const result of results) {
const commandGenerator = bugcheckCommands[String(result.bugcheck || '').toLowerCase()];
if (commandGenerator) {
// commandGenerator expected signature: (parser, dmp, args) => string
const command = commandGenerator(parser, result.dmp, result.args);
logger.info(`Executing command: ${command}`);
try {
const output = await executeCommand(command);
result.post = output;
logger.info('Post-process completed');
} catch (error) {
result.post = error;
logger.error(`An error occured while post-processing the file: ${error}`);
}
} else {
result.post = "No post processing configured for this bugcheck";
logger.info(`No command for bugcheck: ${result.bugcheck}`);
}
}
return results;
};
export default postProcessResults;