lib/meteor/build.js
function BuildPromise(options) {
  "use strict";

  options = options || {};

  var pathToApp = options.pathToApp || path.resolve('.');
  var mongoUrl  = options.mongoUrl  || "http://localhost:27017";
  var timeout   = options.timeout   || 120000;
  var verbose   = options.verbose !== undefined ? !!options.verbose : false;

  var pathToMain  = path.join(pathToApp, '.gagarin', 'local', 'bundle', 'main.js');
  var pathToLocal = path.join(pathToApp, '.gagarin', 'local');

  var env = Object.create(process.env);

  return tools.getReleaseVersion(pathToApp).then(function (version) { return new Promise(function (resolve, reject) {

    var args;

    logs.system("detected METEOR@" + version);

    if (version >= '1.0.0') {
      args = [ 'build', '--debug', '--directory', pathToLocal ];
    } else {
      args = [ 'bundle', '--debug', '--directory', path.join(pathToLocal, 'bundle') ];
    }

    logs.system("spawning meteor process with the following args");
    logs.system(JSON.stringify(args));

    var buildTimeout = null;

    var meteorBinary = tools.getMeteorBinary();
    //make sure that platforms file contains only server and browser
    //and cache this file under platforms.gagarin.backup
    var platformsFilePath = path.join(pathToApp,'.meteor','platforms');
    var platformsBackupPath = path.join(pathToApp,'.meteor','platforms.gagarin.backup');

    fs.rename(platformsFilePath,platformsBackupPath,function(err,data){
      fs.writeFile(platformsFilePath,'server\nbrowser\n',function(){
        spawnMeteorProcess();
      });
    });

    var output = "";

    var meteor = null;

    var spawnMeteorProcess = function(){

      meteor = spawn(meteorBinary, args, {
        cwd: pathToApp, env: env, stdio: verbose ? 'inherit' : 'ignore'
      });

      meteor.on('exit', function onExit (code) {
        //switch back to initial content of platforms file
        fs.rename(platformsBackupPath,platformsFilePath);
        if (code) {
          return reject(new Error('meteor build exited with code ' + code));
        }

        /*
        var err = parseBuildErrors(output);

        if (err) {
          return reject(err);
        }
        */

        logs.system('linking node_modules');

        linkNodeModules(pathToApp).then(function () {

          logs.system('everything is fine');

          resolve(pathToMain);
        }).catch(reject);


        buildTimeout = setTimeout(function () {
          meteor.once('exit', function () {
            reject(new Error('Timeout while waiting for meteor build to finish.'));
          });
          meteor.kill('SIGINT')
        }, timeout);

        clearTimeout(buildTimeout);

      });
    }


    //-----------------------------------------------
    /*
    meteor.stdout.on('data', function onData (data) {

      output += data.toString();

      if (data.toString().match(/WARNING: The output directory is under your source tree./)) {
        logMeteorOutput('  creating your test build in ' + path.join(pathToLocal, 'bundle') + '\n');
        return;
      }
      logMeteorOutput(data);
    });

    meteor.stdout.on('error', function onError (data) {
      console.log(chalk.red(data.toString()));
      clearTimeout(buildTimeout);
    });
    */


  }); });

  function logMeteorOutput(data) {
    if (!verbose) {
      return;
    }
    process.stdout.write(chalk.gray(stripAnsi(data)));
  }

}
function BuildPromise(options) {
  "use strict";

  options = options || {};

  var pathToApp = options.pathToApp || path.resolve('.');
  var mongoUrl  = options.mongoUrl  || "http://localhost:27017";
  var timeout   = options.timeout   || 120000;
  var verbose   = options.verbose !== undefined ? !!options.verbose : false;

  var pathToMain  = path.join(pathToApp, '.gagarin', 'local', 'bundle', 'main.js');
  var pathToLocal = path.join(pathToApp, '.gagarin', 'local');

  var env = Object.create(process.env);

  return tools.getReleaseVersion(pathToApp).then(function (version) { return new Promise(function (resolve, reject) {

    var args;

    logs.system("detected METEOR@" + version);

    if (version >= '1.0.0') {
      args = [ 'build', '--debug', '--directory', pathToLocal ];
    } else {
      args = [ 'bundle', '--debug', '--directory', path.join(pathToLocal, 'bundle') ];
    }

    logs.system("spawning meteor process with the following args");
    logs.system(JSON.stringify(args));

    var buildTimeout = null;

    var meteorBinary = tools.getMeteorBinary();
    //make sure that platforms file contains only server and browser
    //and cache this file under platforms.gagarin.backup
    var platformsFilePath = path.join(pathToApp,'.meteor','platforms');
    var platformsBackupPath = path.join(pathToApp,'.meteor','platforms.gagarin.backup');

    fs.rename(platformsFilePath,platformsBackupPath,function(err,data){
      fs.writeFile(platformsFilePath,'server\nbrowser\n',function(){
        spawnMeteorProcess();
      });
    });

    var output = "";

    var meteor = null;

    var spawnMeteorProcess = function(){

      meteor = spawn(meteorBinary, args, {
        cwd: pathToApp, env: env, stdio: verbose ? 'inherit' : 'ignore'
      });

      meteor.on('exit', function onExit (code) {
        //switch back to initial content of platforms file
        fs.rename(platformsBackupPath,platformsFilePath);
        if (code) {
          return reject(new Error('meteor build exited with code ' + code));
        }

        /*
        var err = parseBuildErrors(output);

        if (err) {
          return reject(err);
        }
        */

        logs.system('linking node_modules');

        linkNodeModules(pathToApp).then(function () {

          logs.system('everything is fine');

          resolve(pathToMain);
        }).catch(reject);


        buildTimeout = setTimeout(function () {
          meteor.once('exit', function () {
            reject(new Error('Timeout while waiting for meteor build to finish.'));
          });
          meteor.kill('SIGINT')
        }, timeout);

        clearTimeout(buildTimeout);

      });
    }


    //-----------------------------------------------
    /*
    meteor.stdout.on('data', function onData (data) {

      output += data.toString();

      if (data.toString().match(/WARNING: The output directory is under your source tree./)) {
        logMeteorOutput('  creating your test build in ' + path.join(pathToLocal, 'bundle') + '\n');
        return;
      }
      logMeteorOutput(data);
    });

    meteor.stdout.on('error', function onError (data) {
      console.log(chalk.red(data.toString()));
      clearTimeout(buildTimeout);
    });
    */


  }); });

  function logMeteorOutput(data) {
    if (!verbose) {
      return;
    }
    process.stdout.write(chalk.gray(stripAnsi(data)));
  }

}
function BuildPromise ( options ) { "use strict" ; options = options || { } ; var pathToApp = options . pathToApp || path . resolve ( '.' ) ; var mongoUrl = options . mongoUrl || "http://localhost:27017" ; var timeout = options . timeout || 120000 ; var verbose = options . verbose !== undefined ? ! ! options . verbose : false ; var pathToMain = path . join ( pathToApp , '.gagarin' , 'local' , 'bundle' , 'main.js' ) ; var pathToLocal = path . join ( pathToApp , '.gagarin' , 'local' ) ; var env = Object . create ( process . env ) ; return tools . getReleaseVersion ( pathToApp ) . then ( function ( version ) { return new Promise ( function ( resolve , reject ) { var args ; logs . system ( "detected METEOR@" + version ) ; if ( version >= '1.0.0' ) { args = [ 'build' , '--debug' , '--directory' , pathToLocal ] ; } else { args = [ 'bundle' , '--debug' , '--directory' , path . join ( pathToLocal , 'bundle' ) ] ; } logs . system ( "spawning meteor process with the following args" ) ; logs . system ( JSON . stringify ( args ) ) ; var buildTimeout = null ; var meteorBinary = tools . getMeteorBinary ( ) ; //make sure that platforms file contains only server and browser //and cache this file under platforms.gagarin.backup var platformsFilePath = path . join ( pathToApp , '.meteor' , 'platforms' ) ; var platformsBackupPath = path . join ( pathToApp , '.meteor' , 'platforms.gagarin.backup' ) ; fs . rename ( platformsFilePath , platformsBackupPath , function ( err , data ) { fs . writeFile ( platformsFilePath , 'server\nbrowser\n' , function ( ) { spawnMeteorProcess ( ) ; } ) ; } ) ; var output = "" ; var meteor = null ; var spawnMeteorProcess = function ( ) { meteor = spawn ( meteorBinary , args , { cwd : pathToApp , env : env , stdio : verbose ? 'inherit' : 'ignore' } ) ; meteor . on ( 'exit' , function onExit ( code ) { //switch back to initial content of platforms file fs . rename ( platformsBackupPath , platformsFilePath ) ; if ( code ) { return reject ( new Error ( 'meteor build exited with code ' + code ) ) ; } /*
        var err = parseBuildErrors(output);

        if (err) {
          return reject(err);
        }
        */ logs . system ( 'linking node_modules' ) ; linkNodeModules ( pathToApp ) . then ( function ( ) { logs . system ( 'everything is fine' ) ; resolve ( pathToMain ) ; } ) . catch ( reject ) ; buildTimeout = setTimeout ( function ( ) { meteor . once ( 'exit' , function ( ) { reject ( new Error ( 'Timeout while waiting for meteor build to finish.' ) ) ; } ) ; meteor . kill ( 'SIGINT' ) } , timeout ) ; clearTimeout ( buildTimeout ) ; } ) ; } //----------------------------------------------- /*
    meteor.stdout.on('data', function onData (data) {

      output += data.toString();

      if (data.toString().match(/WARNING: The output directory is under your source tree./)) {
        logMeteorOutput('  creating your test build in ' + path.join(pathToLocal, 'bundle') + '\n');
        return;
      }
      logMeteorOutput(data);
    });

    meteor.stdout.on('error', function onError (data) {
      console.log(chalk.red(data.toString()));
      clearTimeout(buildTimeout);
    });
    */ } ) ; } ) ; function logMeteorOutput ( data ) { if ( ! verbose ) { return ; } process . stdout . write ( chalk . gray ( stripAnsi ( data ) ) ) ; } }
PRIVATE BUILD PROMISE IMPLEMENTATION
PRIVATE BUILD PROMISE IMPLEMENTATION