Capture stderr when setting versions
This commit is contained in:
parent
218fe8f023
commit
c15f9a9942
|
@ -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');
|
|
||||||
|
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) {
|
for (const language of languages) {
|
||||||
// TODO: Add custom handlers for some languages
|
language.version = versions[language.name];
|
||||||
|
|
||||||
language.version = getVersion(language);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue