Repository URL to install this package:
|
Version:
3.6.0-rc.0 ▾
|
require('dotenv').config();
const { spawn } = require('child_process');
module.exports = {
/**
* Executes a command. It reads the environment variables from the .env file in the
* folder where this command is run. You can optionally pass additional environment
* variables as second parameter. These additional environment variables will override
* the definitions present in the .env file.
* @param {string} command The command to execute
* @param {object<string,string>=} env The additional environment variables
*/
run: (command, env = {}) => {
const commandParts = command.split(' ');
if (commandParts.length > 0) {
const childProcess = spawn(commandParts[0], commandParts.slice(1), {
env: {
...process.env,
...env,
},
});
childProcess.stdout.on('data', data => console.log(data.toString()));
childProcess.stderr.on('data', data => console.error(data.toString()));
childProcess.on('close', code => console.log(`Exited with code ${code.toString()}`));
} else {
throw new Error('Cannot execute command: command not specified.');
}
},
};