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 app = express();
const languages = require('./languages');
const { spawn, execFileSync } = require('child_process');
const { spawn } = require('child_process');
const versions = execFileSync(__dirname + '/../../lxc/versions')
.toString()
.toLowerCase()
.split('---')
.map(section => section.trim().split('\n'))
.filter(section => section.length >= 2);
(function setVersions() {
let output = '';
function getVersion(language) {
return versions.find(section => section[0] === language?.name)?.slice(1).join('\n');
const process = spawn(__dirname + '/../../lxc/versions');
process.stdout.setEncoding('utf-8');
process.stderr.setEncoding('utf-8');
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) {
// TODO: Add custom handlers for some languages
language.version = getVersion(language);
language.version = versions[language.name];
}
});
})();
app.use(express.json());