const cmd = require('child_process');

var Updater = function () {
  //
};

module.exports = Updater;

Updater.prototype.update = function(cb) {
  let rootDir = global.rootDir.replace(/\//g, "\\");
  let npmCmdPath = rootDir+"/npm.cmd";
  cmd.exec(npmCmdPath+' update taskbuilder-renderer --save', 
    { cwd: rootDir }, 
    function (error, stdout, stderr) {
    let err = null;
    if(error) {
      global.logger.log(`exec error: ${error}`);
      err = error;
    }
    if(stderr) {
      global.logger.log(`stderr: ${stderr}`);
      err = stderr;
    }
    if(stdout) global.logger.log(`stdout: ${stdout}`);
    if (cb) cb(err);
  });
};