1
0

command_runner.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. var exec = Npm.require('child_process').exec,
  2. execSync = function(cmd, options, stdoutHandler, stderrHandler) {
  3. exec(cmd,
  4. options,
  5. Meteor.bindEnvironment(
  6. function(error, stdout, stderr) {
  7. if( stdout != '' ) {
  8. stdoutHandler(stdout);
  9. }
  10. if( stderr != '' ) {
  11. stderrHandler(stderr);
  12. }
  13. }
  14. )
  15. );
  16. };
  17. var CommandRunner = {
  18. run: function( script, deployment, stdout, stderr, counter, callback ) {
  19. var command = script[command].cmd.replace('%ROOT_CWD%', DEPLOYMENT_FOLDER).replace('%CWD%', deployment._id),
  20. options = script[command].options;
  21. options.cwd.replace('%ROOT_CWD%', DEPLOYMENT_FOLDER).replace('%CWD%', deployment._id);
  22. execSync(command, options, stdout, stderr, function() {
  23. counter++;
  24. if( counter > script.length ) {
  25. if( callback ) {
  26. callback();
  27. }
  28. } else {
  29. CommandRunner.run(script, deployment, stdout, stderr, counter, callback);
  30. }
  31. });
  32. }
  33. }