Capture stderr when setting versions

This commit is contained in:
Vrganj 2021-01-14 21:06:26 +01:00
parent 218fe8f023
commit c15f9a9942
1 changed files with 33 additions and 14 deletions

View File

@ -2,24 +2,43 @@ const { writeFile } = require('fs/promises');
const express = require('express'); const express = require('express');
const app = express(); const app = express();
const languages = require('./languages'); const languages = require('./languages');
const { spawn, execFileSync } = require('child_process'); const { spawn } = require('child_process');
const versions = execFileSync(__dirname + '/../../lxc/versions') (function setVersions() {
.toString() let output = '';
.toLowerCase()
.split('---')
.map(section => section.trim().split('\n'))
.filter(section => section.length >= 2);
function getVersion(language) { const process = spawn(__dirname + '/../../lxc/versions');
return versions.find(section => section[0] === language?.name)?.slice(1).join('\n');
}
for (const language of languages) { process.stdout.setEncoding('utf-8');
// TODO: Add custom handlers for some languages process.stderr.setEncoding('utf-8');
language.version = getVersion(language); process.stdout.addListener('data', chunk => {
} output += chunk;
});
process.stderr.addListener('data', chunk => {
output += chunk;
});
process.on('exit', () => {
const sections = output.toLowerCase().split('---');
const versions = {};
for (let section of sections) {
section = section.trim().split('\n');
if (section.length >= 2) {
const language = section[0];
versions[language] = /\d.\d.\d/.exec(section.slice(1).join('\n'))?.[0];
}
}
for (const language of languages) {
language.version = versions[language.name];
}
});
})();
app.use(express.json()); app.use(express.json());