moved command execution to own .js file

This commit is contained in:
Daniel Sommer 2022-02-11 01:20:53 +01:00
parent 0520d24e29
commit 3528e8e146
2 changed files with 27 additions and 1 deletions

26
libs/commands.js Normal file
View file

@ -0,0 +1,26 @@
const logger = require('./logger.js');
const { spawn } = require('child_process');
function execute(cmd, args) {
return new Promise(function (resolve, reject) {
var spawned = spawn(cmd, args);
spawned.stdout.on('data', function (data) {
logger.debug(data);
});
spawned.stderr.on('data', function (data) {
logger.error(data);
});
spawned.on('close', function (code) {
logger.debug('command \'' + cmd + '\' with args \'' + args + '\' finished with exit code ' + code);
resolve();
});
spawned.on('error', function (err) {
logger.error('command \'' + cmd + '\' with args \'' + args + '\' encountered an error >>> ' + err);
reject(err);
});
});
}
module.exports = {
execute
}

View file

@ -3,9 +3,9 @@ const util = require('./util.js');
const constants = require('./constants.js');
const logger = require('./logger.js');
const cache = require('./cache.js');
const commands = require('./commands.js');
const path = require('path');
const fs = require('fs');
const { spawn } = require('child_process');
const ttl2jsonld = require('@frogcat/ttl2jsonld').parse;
function reset() {