From 625dba4d85badebbd09cb6920e6980127df3a379 Mon Sep 17 00:00:00 2001 From: wltsmrz Date: Tue, 11 Nov 2014 05:30:21 -0800 Subject: [PATCH 1/4] Add build-core gulp task --- Gulpfile.js | 101 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 37 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index 6df2103197..f05214c32a 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -68,6 +68,53 @@ 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); +}); + +gulp.task('build-core', [ 'concat-sjcl' ], function(callback) { + const NONE = 'var {}'; + + webpack({ + entry: [ + './src/js/ripple/remote.js' + ], + externals: [ + { + './transaction': NONE, + './orderbook': NONE, + './account': NONE, + './serializedobject': NONE + } + ], + 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')) @@ -92,41 +139,7 @@ gulp.task('bower-version', function() { .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') @@ -158,6 +171,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' ]); From b0cac776eec524f8de560a17cb242675bf801fc7 Mon Sep 17 00:00:00 2001 From: wltsmrz Date: Tue, 11 Nov 2014 06:23:37 -0800 Subject: [PATCH 2/4] Throw an error when trying to use unavailable class in WebPack build --- Gulpfile.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index f05214c32a..a137368191 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -89,19 +89,27 @@ gulp.task('build-debug', [ 'concat-sjcl' ], function(callback) { }, callback); }); -gulp.task('build-core', [ 'concat-sjcl' ], function(callback) { - const NONE = 'var {}'; +/** + * Generate a WebPack external for a given unavailable module which replaces + * that module's constructor with an error-thrower + */ + +function buildUseError(cons) { + return 'var {:function(){throw new Error("Class is unavailable in this build: ")}}' + .replace(new RegExp('', 'g'), cons); +}; +gulp.task('build-core', [ 'concat-sjcl' ], function(callback) { webpack({ entry: [ './src/js/ripple/remote.js' ], externals: [ { - './transaction': NONE, - './orderbook': NONE, - './account': NONE, - './serializedobject': NONE + './transaction': buildUseError('Transaction'), + './orderbook': buildUseError('OrderBook'), + './account': buildUseError('Account'), + './serializedobject': buildUseError('SerializedObject') } ], output: { @@ -135,7 +143,7 @@ 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/')); }); From 8f17873da2e0ae0816d6e211bfc8c1ffa658aa9e Mon Sep 17 00:00:00 2001 From: wltsmrz Date: Tue, 11 Nov 2014 06:24:34 -0800 Subject: [PATCH 3/4] Remove server._computeFee(Transaction), require fee units argument --- src/js/ripple/server.js | 15 ++++----------- src/js/ripple/transaction.js | 2 +- test/server-test.js | 8 +------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/js/ripple/server.js b/src/js/ripple/server.js index 23ab705eac..ecd8f58a45 100644 --- a/src/js/ripple/server.js +++ b/src/js/ripple/server.js @@ -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'); /** @@ -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(); }; /** diff --git a/src/js/ripple/transaction.js b/src/js/ripple/transaction.js index b8a1eb5f78..5b2381ba77 100644 --- a/src/js/ripple/transaction.js +++ b/src/js/ripple/transaction.js @@ -276,7 +276,7 @@ Transaction.prototype._computeFee = function() { for (var i=0; i Date: Wed, 12 Nov 2014 03:04:51 -0800 Subject: [PATCH 4/4] Add note on restricted browser builds --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9f6b296d56..900287e4c3 100644 --- a/README.md +++ b/README.md @@ -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 @@ -47,7 +47,9 @@ 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 @@ -55,9 +57,13 @@ See the [bower-ripple repo](https://github.com/ripple/bower-ripple) for addition $ 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-` + ++ `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