lib/gyp.js
function rebuild (dir, _callback) {
  var cwd     = process.cwd()
    , gypInst = gyp()

  var callback = function (err) {
    _callback(err)
  }

  gypInst.parseArgv([ null, null, 'rebuild', '--loglevel', 'silent' ])
  process.chdir(dir)
  gypInst.commands.clean([], function (err) {
    if (err)
      return callback(new Error('node-gyp clean: ' + err.message))
    gypInst.commands.configure([], function (err) {
      if (err)
        return callback(new Error('node-gyp configure: ' + err.message))
      gypInst.commands.build([], function (err) {
        if (err)
          return callback(new Error('node-gyp build: ' + err.message))

        process.chdir(cwd)
        return callback()
      })
    })
  })
}
function rebuild (dir, _callback) {
  var cwd     = process.cwd()
    , gypInst = gyp()

  var callback = function (err) {
    _callback(err)
  }

  gypInst.parseArgv([ null, null, 'rebuild', '--loglevel', 'silent' ])
  process.chdir(dir)
  gypInst.commands.clean([], function (err) {
    if (err)
      return callback(new Error('node-gyp clean: ' + err.message))
    gypInst.commands.configure([], function (err) {
      if (err)
        return callback(new Error('node-gyp configure: ' + err.message))
      gypInst.commands.build([], function (err) {
        if (err)
          return callback(new Error('node-gyp build: ' + err.message))

        process.chdir(cwd)
        return callback()
      })
    })
  })
}
function rebuild ( dir , _callback ) { var cwd = process . cwd ( ) , gypInst = gyp ( ) var callback = function ( err ) { _callback ( err ) } gypInst . parseArgv ( [ null , null , 'rebuild' , '--loglevel' , 'silent' ] ) process . chdir ( dir ) gypInst . commands . clean ( [ ] , function ( err ) { if ( err ) return callback ( new Error ( 'node-gyp clean: ' + err . message ) ) gypInst . commands . configure ( [ ] , function ( err ) { if ( err ) return callback ( new Error ( 'node-gyp configure: ' + err . message ) ) gypInst . commands . build ( [ ] , function ( err ) { if ( err ) return callback ( new Error ( 'node-gyp build: ' + err . message ) ) process . chdir ( cwd ) return callback ( ) } ) } ) } ) }
invoke `node-gyp rebuild` programatically, runs clean;configure;build
invoke node - gyp rebuild programatically runs clean ; configure ; build