Permalink
Browse files

Adds CEF library downloader.

Installer script downloads cef binary dist according to user's
platform and architecture.
  • Loading branch information...
1 parent b23866e commit c0598e1e79e4832a112ebf170c422053c660f908 @milani milani committed Apr 30, 2012
Showing with 228 additions and 8 deletions.
  1. +1 −1 .gitignore
  2. +4 −0 .npmignore
  3. +103 −0 bin/installer
  4. +2 −1 binding.gyp
  5. +110 −0 cli/util.js
  6. +8 −6 package.json
View
@@ -1,4 +1,4 @@
build/
node_modules/
appjs.sublime*
-
+deps/*
View
@@ -0,0 +1,4 @@
+build/
+node_modules/
+appjs.sublime*
+deps/cef
View
@@ -0,0 +1,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');
View
@@ -23,7 +23,7 @@
'cflags': [
'-fPIC',
'-Wall',
- '-std=c++0x',
+ '-std=c++0x'
],
'conditions': [
['OS=="mac"', {
@@ -44,6 +44,7 @@
'link_settings': {
'ldflags': [
'<!@(pkg-config --libs-only-L --libs-only-other gtk+-2.0 gthread-2.0)',
+ '-Wl,-R,<(module_root_dir)/deps/cef/Release/lib.target/'
],
'libraries': [
'<!@(pkg-config --libs-only-l gtk+-2.0 gthread-2.0)',
View
@@ -0,0 +1,110 @@
+/**
+ * (The MIT License)
+ *
+ * Copyright (c) 2012 Morteza Milani <mrtz.milani@gmail.com> and other
+ * AppJS contributors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * 'Software'), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ **/
+
+var inherits = require('util').inherits;
+
+function MyError(msg) {
+ this.name = 'Appjs Error';
+ this.message = msg;
+ Error.call(this, msg);
+ Error.captureStackTrace(this, arguments.callee);
+}
+
+inherits(MyError, Error);
+
+var l = 1, COLOR = [], LEVEL = {
+ verbose : l++,
+ info: l++,
+ warn: l++,
+ error: l++,
+ success: l++
+};
+
+COLOR[LEVEL.verbose] = 34;
+COLOR[LEVEL.info] = 32;
+COLOR[LEVEL.warn] = 33;
+COLOR[LEVEL.error] = 31;
+COLOR[LEVEL.success] = 32;
+
+function colorize (msg, color) {
+ if(!color) color = COLOR[LEVEL.info];
+ return msg ? "\033["+color+"m"+msg+"\033[0m" : "";
+}
+
+var logLevel = LEVEL['info'];
+
+var log = function(msg,level){
+
+ if(!level || !LEVEL[level]){
+ level = 'info';
+ }
+
+ if (msg instanceof MyError) {
+
+ msg = msg.toString();
+ level = 'error';
+
+ } else if (msg instanceof Error){
+
+ msg = msg.stack || msg.toString();
+ level = 'error';
+
+ }else {
+
+ msg = level + ': ' + msg;
+
+ }
+
+ if(LEVEL[level] < logLevel) return;
+
+ console.log(colorize(msg,COLOR[LEVEL[level]]));
+
+}
+
+log.LEVELS = LEVEL;
+
+log.setLevel = function(level){
+ logLevel = LEVEL[level];
+}
+
+Object.keys(LEVEL).forEach(function (l) {
+ log[l] = l;
+});
+
+exports.abort = function(error){
+ if(error instanceof Error){
+ throw error;
+ } else {
+ throw new MyError(error);
+ }
+}
+
+exports.errorHandler = function(e){
+ //msg = msg.toString();
+ log(e);
+}
+
+exports.log = log;
View
@@ -1,7 +1,7 @@
{
"name": "appjs",
"description": "AppJS is a SDK on top of nodejs to develop desktop applications using HTML/CSS/JS",
- "version": "0.0.1",
+ "version": "0.0.2",
"keywords": [
"app",
"webkit",
@@ -27,20 +27,22 @@
"doc": "./doc",
"lib": "./lib",
"bin": "./bin",
- "test": "./test"
- },
- "bin": {
- "appjs": "./bin/appjs"
+ "test": "./tests"
},
"main": "./index.js",
"engines": {
"node": "0.6 || 0.7 || 0.8"
},
"dependencies": {
- "mime":"1.2.5"
+ "mime":"1.2.5",
+ "request":"2.9.x",
+ "tar":">= 0.1.13"
},
"devDependencies": {},
"optionalDependencies": {},
+ "scripts": {
+ "preinstall": "./bin/installer || true; node-gyp rebuild"
+ },
"licenses": [
{
"type": "MIT",

0 comments on commit c0598e1

Please sign in to comment.