Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/frontend-config / commands / commandHelper.js
Size: Mime:
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.');
    }
  },
};