Skip to content
This repository
tree: c0598e1e79
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 103 lines (79 sloc) 2.303 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#!/usr/bin/env node

/**
* Set the title.
*/

process.title = 'appjs-installer'

/**
* Necessary modules and variables
*/

var util = require('../cli/util')
  , fs = require('fs')
  , path = require('path')
  , platform = require('os').platform()
  , arch = require('os').arch()
  , depsDir = path.join(__dirname,'../deps')
  , env = process.env.NODE_ENV || 'Debug';

/**
* Starts installing CEF libraries
*/

function install(cef_version) {

  downloadCef(cef_version,function(err){

    if(err) {
      throw err;
    }

    util.log('Done!');
  });

}

/**
* Downloads CEF binary package according to
* developer's platform and extracts it to
* deps/cef
*/

function downloadCef(version,cb){

    var zlib = require('zlib')
      , tar = require('tar')
      , distUrl = 'https://github.com/downloads/milani/appjs'
      , version = version
      , fileName = 'cef_binary_' + version + '_' + platform + '_' + arch + '.tar.gz';

    var tarballUrl = distUrl + '/' + fileName
      , gunzip = zlib.createGunzip()
      , extracter = tar.Extract({ path: depsDir });

    var errorHandler = function(err,res){
        if ( err || res.statusCode != 200 ) {
            cb(err || new Error(res.statusCode + ' status code downloading tarball'));
        }
    }

    gunzip.on('error', errorHandler)
    extracter.on('error', errorHandler)
    extracter.on('end', function(){
        fs.unlinkSync( path.join(depsDir,'cef') );
        fs.symlink( path.join(depsDir,fileName.replace('.tar.gz','')), path.join(depsDir,'cef') ,cb);
    })

    download(tarballUrl,errorHandler)
      .pipe(gunzip)
      .pipe(extracter);
}

/**
* Returns a Request object
*/

function download(url,onError) {
    var request = require('request');

    util.log('Downloading cef tarball...');

    var requestOpts = {
        uri: url,
        onResponse: true
    }

    // basic support for a proxy server
    var proxyUrl = process.env.http_proxy
                || process.env.HTTP_PROXY
                || process.env.npm_config_proxy
    if (proxyUrl) {
      util.log('using proxy: ' + proxyUrl,'verbose');
      requestOpts.proxy = proxyUrl
    }
    return request(requestOpts).on('error',onError);
}

/**
* Start installing CEF version 1.1092.585
*/
 
install('1.1099.611');
Something went wrong with that request. Please try again.