Skip to content

Commit

Permalink
Merge pull request #205 from ripple/core-build
Browse files Browse the repository at this point in the history
Add core build
  • Loading branch information
geertweening committed Nov 12, 2014
2 parents 3ee7998 + 3650858 commit df763b8
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 61 deletions.
111 changes: 73 additions & 38 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,61 @@ gulp.task('build', [ 'concat-sjcl' ], function(callback) {
}, callback);
});

gulp.task('build-min', [ 'build' ], function(callback) {
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
.pipe(uglify())
.pipe(rename([ 'ripple-', '-min.js' ].join(pkg.version)))
.pipe(gulp.dest('./build/'));
});

gulp.task('build-debug', [ 'concat-sjcl' ], function(callback) {
webpack({
cache: true,
entry: './src/js/ripple/index.js',
output: {
library: 'ripple',
path: './build/',
filename: [ 'ripple-', '-debug.js' ].join(pkg.version)
},
debug: true,
devtool: 'eval'
}, callback);
});

/**
* Generate a WebPack external for a given unavailable module which replaces
* that module's constructor with an error-thrower
*/

function buildUseError(cons) {
return 'var {<CONS>:function(){throw new Error("Class is unavailable in this build: <CONS>")}}'
.replace(new RegExp('<CONS>', 'g'), cons);
};

gulp.task('build-core', [ 'concat-sjcl' ], function(callback) {
webpack({
entry: [
'./src/js/ripple/remote.js'
],
externals: [
{
'./transaction': buildUseError('Transaction'),
'./orderbook': buildUseError('OrderBook'),
'./account': buildUseError('Account'),
'./serializedobject': buildUseError('SerializedObject')
}
],
output: {
library: 'ripple',
path: './build/',
filename: [ 'ripple-', '-core.js' ].join(pkg.version)
},
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
}, callback);
});

gulp.task('bower-build', [ 'build' ], function(callback) {
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
.pipe(rename('ripple.js'))
Expand All @@ -88,45 +143,11 @@ gulp.task('bower-build-debug', [ 'build-debug' ], function(callback) {

gulp.task('bower-version', function() {
gulp.src('./dist/bower.json')
.pipe(bump({version: pkg.version}))
.pipe(bump({ version: pkg.version }))
.pipe(gulp.dest('./dist/'));
});

gulp.task('version-bump', function() {
if (!argv.type) {
throw new Error("No type found, pass it in using the --type argument");
}
gulp.src('./package.json')
.pipe(bump({type:argv.type}))
.pipe(gulp.dest('./'));
});

gulp.task('version-beta', function() {
gulp.src('./package.json')
.pipe(bump({version: pkg.version+'-beta'}))
.pipe(gulp.dest('./'));
});

gulp.task('build-min', [ 'build' ], function(callback) {
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
.pipe(uglify())
.pipe(rename([ 'ripple-', '-min.js' ].join(pkg.version)))
.pipe(gulp.dest('./build/'));
});

gulp.task('build-debug', [ 'concat-sjcl' ], function(callback) {
webpack({
cache: true,
entry: './src/js/ripple/index.js',
output: {
library: 'ripple',
path: './build/',
filename: [ 'ripple-', '-debug.js' ].join(pkg.version)
},
debug: true,
devtool: 'eval'
}, callback);
});
gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug', 'bower-version']);

gulp.task('lint', function() {
gulp.src('src/js/ripple/*.js')
Expand Down Expand Up @@ -158,6 +179,20 @@ gulp.task('watch', function() {
gulp.watch('src/js/ripple/*', [ 'build-debug' ]);
});

gulp.task('default', [ 'concat-sjcl', 'build', 'build-debug', 'build-min' ]);
gulp.task('version-bump', function() {
if (!argv.type) {
throw new Error("No type found, pass it in using the --type argument");
}

gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug', 'bower-version']);
gulp.src('./package.json')
.pipe(bump({ type: argv.type }))
.pipe(gulp.dest('./'));
});

gulp.task('version-beta', function() {
gulp.src('./package.json')
.pipe(bump({ version: pkg.version + '-beta' }))
.pipe(gulp.dest('./'));
});

gulp.task('default', [ 'concat-sjcl', 'build', 'build-debug', 'build-min' ]);
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A JavaScript API for interacting with Ripple in Node.js and the browser
###In this file

1. [Installation](README.md#installation)
2. [Quickstart](README.md#quickstart)
2. [Quick start](README.md#quick+start)
3. [Running tests](https://github.com/ripple/ripple-lib#running-tests)

###Additional documentation
Expand Down Expand Up @@ -47,17 +47,23 @@ A JavaScript API for interacting with Ripple in Node.js and the browser
See the [bower-ripple repo](https://github.com/ripple/bower-ripple) for additional bower instructions


**Building ripple-lib from github**
**Building ripple-lib for browser environments**

ripple-lib uses Gulp to generate browser builds. These steps will generate minified and non-minified builds of ripple-lib in the `build/` directory.

```
$ git clone https://github.com/ripple/ripple-lib
$ npm install
$ npm run build
```

Then use the minified `build/ripple-*-min.js`
**Restricted browser builds**

You may generate browser builds that contain a subset of features. To do this, run `./node_modules/.bin/gulp build-<name>`

+ `build-core` Contains the functionality to make requests and listen for events such as `ledgerClose`. Only `ripple.Remote` is currently exposed. Advanced features like transaction submission and orderbook tracking are excluded from this build.

##Quickstart
##Quick start

`Remote.js` ([remote.js](https://github.com/ripple/ripple-lib/blob/develop/src/js/ripple/remote.js)) is the point of entry for interacting with rippled

Expand Down
15 changes: 4 additions & 11 deletions src/js/ripple/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var util = require('util');
var url = require('url');
var EventEmitter = require('events').EventEmitter;
var Amount = require('./amount').Amount;
var Transaction = require('./transaction').Transaction;
var log = require('./log').internal.sub('server');

/**
Expand Down Expand Up @@ -760,22 +759,16 @@ Server.prototype._isConnected = function() {
* Calculate transaction fee
*
* @param {Transaction|Number} Fee units for a provided transaction
* @return {Number} Final fee in XRP for specified number of fee units
* @return {String} Final fee in XRP for specified number of fee units
* @api private
*/

Server.prototype._computeFee = function(transaction) {
var units;

if (transaction instanceof Transaction) {
units = transaction._getFeeUnits();
} else if (typeof transaction === 'number') {
units = transaction;
} else {
Server.prototype._computeFee = function(feeUnits) {
if (isNaN(feeUnits)) {
throw new Error('Invalid argument');
}

return this._feeTx(units).to_json();
return this._feeTx(Number(feeUnits)).to_json();
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/js/ripple/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Transaction.prototype._computeFee = function() {
for (var i=0; i<servers.length; i++) {
var server = servers[i];
if (server._connected) {
fees.push(Number(server._computeFee(this)));
fees.push(Number(server._computeFee(this._getFeeUnits())));
}
}

Expand Down
8 changes: 1 addition & 7 deletions test/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,12 +1006,6 @@ describe('Server', function() {
assert(server._isConnected());
});

it('Compute fee - transaction', function() {
var server = new Server(new Remote(), 'ws://localhost:5748');
var transaction = new Transaction();
assert.strictEqual(server._computeFee(transaction), '12');
});

it('Compute fee - fee units', function() {
var server = new Server(new Remote(), 'ws://localhost:5748');
var transaction = new Transaction();
Expand All @@ -1033,7 +1027,7 @@ describe('Server', function() {
server._load_factor = 256 * 4;

var transaction = new Transaction();
assert.strictEqual(server._computeFee(transaction), '48');
assert.strictEqual(server._computeFee(10), '48');
});

it('Compute reserve', function() {
Expand Down

0 comments on commit df763b8

Please sign in to comment.