tune-basic-toolset
Version:
Basic toolset for tune
32 lines (27 loc) • 704 B
JavaScript
const { execSync, spawnSync } = require('child_process');
const shp = async (node, args, ctx) => ({
type: 'text',
read: async () => {
let input = null;
if (node && node.type === 'text') {
input = await node.read();
}
let result;
try {
if (input !== null) {
const res = spawnSync(args.trim() || "sh", {
input,
encoding: 'utf8',
shell: true
});
result = (res.stdout || '') + (res.stderr || '');
} else {
result = execSync(args.trim(), { encoding: 'utf8' });
}
} catch (e) {
result = e.stderr + e.stdout;
}
return result.replaceAll('@', '\\@');
}
});
module.exports = shp;