Refactoring

Removed browser fixes
Updated gulp to bypass native browser objects
Added source map for dist
This commit is contained in:
Marian Oancea 2014-11-06 22:51:37 +02:00
parent bd14b4d23e
commit 3270b432bc
13 changed files with 98 additions and 827 deletions

@ -2,5 +2,8 @@ example/js
node_modules
test
.gitignore
.editorconfig
.travis.yml
.npmignore
component.json
testling.html

@ -7,13 +7,13 @@ which implements the [Generic JSON RPC](https://github.com/ethereum/wiki/wiki/Ge
[![browser support](https://ci.testling.com/cubedro/ethereum.js.png)](https://ci.testling.com/cubedro/ethereum.js)
### Installation
## Installation
## Node.js
### Node.js
npm install ethereum.js
## For browser
### For browser
Bower
bower install ethereum.js
@ -25,7 +25,7 @@ Component
* Include `ethereum.min.js` in your html file.
* Include [es6-promise](https://github.com/jakearchibald/es6-promise) or another ES6-Shim if your browser doesn't support ECMAScript 6.
### Usage
## Usage
Require the library:
var web3 = require('web3');
@ -50,7 +50,7 @@ web3.eth.coinbase.then(function(result){
For another example see `example/index.html`.
### Building
## Building
* `gulp build`

@ -1,7 +1,7 @@
{
"name": "ethereum.js",
"namespace": "ethereum",
"version": "0.0.1",
"version": "0.0.2",
"description": "Ethereum Compatible JavaScript API",
"main": ["./dist/ethereum.js", "./dist/ethereum.min.js"],
"dependencies": {

761
dist/ethereum.js vendored

File diff suppressed because one or more lines are too long

23
dist/ethereum.js.map vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -9,6 +9,7 @@
if (window.Promise === undefined) {
window.Promise = ES6Promise.Promise;
}
var web3 = require('web3');
//web3.setProvider(new web3.providers.QtProvider());

@ -2,14 +2,21 @@
'use strict';
var path = require('path');
var del = require('del');
var gulp = require('gulp');
var browserify = require('gulp-browserify-thin');
var browserify = require('browserify');
var jshint = require('gulp-jshint');
var uglify = require("gulp-uglify");
var rename = require("gulp-rename");
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var envify = require('envify/custom');
var unreach = require('unreachable-branch-transform');
var source = require('vinyl-source-stream');
var exorcist = require('exorcist');
var bower = require('bower');
var DEST = './dist/';
gulp.task('bower', function(cb){
@ -30,27 +37,46 @@ gulp.task('clean', ['lint'], function(cb) {
});
gulp.task('build', ['clean'], function () {
return browserify()
.require('./index.js', { expose: 'web3'})
.bundle('ethereum.js')
.on('error', function(err)
{
console.error(err.toString());
process.exit(1);
return browserify({
debug: true,
insert_global_vars: false,
detectGlobals: false,
bundleExternal: false
})
.add('./')
.require('./index.js', {expose: 'web3'})
.transform('envify', {
NODE_ENV: 'build'
})
.transform('unreachable-branch-transform')
.transform('uglifyify', {
mangle: false,
compress: {
dead_code: false,
conditionals: true,
unused: false,
hoist_funs: true,
hoist_vars: true,
negate_iife: false
},
beautify: false,
warnings: true,
})
.bundle()
.pipe(exorcist(path.join( DEST, 'ethereum.js.map')))
.pipe(source('ethereum.js'))
.pipe(gulp.dest( DEST ));
});
gulp.task('minify', ['build'], function(){
gulp.task('uglify', ['build'], function(){
return gulp.src( DEST + 'ethereum.js')
.pipe(gulp.dest( DEST ))
.pipe(uglify())
.pipe(rename('ethereum.min.js'))
.pipe(gulp.dest( DEST ));
});
gulp.task('watch', function() {
gulp.watch(['./lib/*.js'], ['lint', 'build', 'minify']);
gulp.watch(['./lib/*.js'], ['lint', 'build', 'uglify']);
});
gulp.task('default', ['bower', 'lint', 'build', 'minify']);
gulp.task('default', ['bower', 'lint', 'build', 'uglify']);

@ -1,35 +0,0 @@
/**
* Module dependencies.
*/
var global = (function() { return this; })(); // jshint ignore:line
/**
* XMLHttpRequest constructor.
*/
var XMLHttpRequest = window.XMLHttpRequest; // jshint ignore:line
/**
* Module exports.
*/
module.exports.XMLHttpRequest = XMLHttpRequest ? xhr : null;
/**
* XMLHttpRequest constructor.
*
* @param {Object) opts (optional)
* @api public
*/
function xhr(obj) {
var instance;
instance = new XMLHttpRequest(obj);
return instance;
}
if (XMLHttpRequest) xhr.prototype = XMLHttpRequest.prototype;

@ -21,8 +21,9 @@
* @date 2014
*/
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
if(process.env.NODE_ENV !== "build") {
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
}
var HttpRpcProvider = function (host) {

@ -1,6 +0,0 @@
var web3 = require('./main');
web3.providers.WebSocketProvider = require('./websocket');
web3.providers.HttpRpcProvider = require('./httprpc');
web3.providers.QtProvider = require('./qt');
module.exports = web3;

@ -21,8 +21,9 @@
* @date 2014
*/
var WebSocket = require('ws'); // jshint ignore:line
if(process.env.NODE_ENV !== "build") {
var WebSocket = require('ws'); // jshint ignore:line
}
var WebSocketProvider = function(host) {
// onmessage handlers

@ -1,12 +1,11 @@
{
"name": "ethereum.js",
"namespace": "ethereum",
"version": "0.0.1",
"version": "0.0.2",
"description": "Ethereum Compatible JavaScript API",
"main": "./index.js",
"directories": {
"lib": "lib",
"example": "example"
"lib": "./lib"
},
"dependencies": {
"es6-promise": "*",
@ -17,21 +16,22 @@
"bower": ">=1.3.0",
"browserify": ">=6.0",
"del": ">=0.1.1",
"envify": "^3.0.0",
"exorcist": "^0.1.6",
"gulp": ">=3.4.0",
"gulp-browserify-thin": ">=0.1.0",
"gulp-jshint": ">=1.5.0",
"gulp-rename": ">=1.2.0",
"gulp-uglify": ">=1.0.0",
"jshint": ">=2.5.0"
"jshint": ">=2.5.0",
"uglifyify": "^2.6.0",
"unreachable-branch-transform": "^0.1.0",
"vinyl-source-stream": "^1.0.0"
},
"scripts": {
"build": "gulp",
"watch": "gulp watch",
"lint": "gulp lint"
},
"browser": {
"xmlhttprequest": "./lib/browser_fix/xhr.js"
},
"repository": {
"type": "git",
"url": "https://github.com/cubedro/ethereum.js.git"