Skip to content

Commit df763b8

Browse files
committed
Merge pull request #205 from ripple/core-build
Add core build
2 parents 3ee7998 + 3650858 commit df763b8

File tree

5 files changed

+89
-61
lines changed

5 files changed

+89
-61
lines changed

Gulpfile.js

+73-38
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,61 @@ gulp.task('build', [ 'concat-sjcl' ], function(callback) {
6868
}, callback);
6969
});
7070

71+
gulp.task('build-min', [ 'build' ], function(callback) {
72+
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
73+
.pipe(uglify())
74+
.pipe(rename([ 'ripple-', '-min.js' ].join(pkg.version)))
75+
.pipe(gulp.dest('./build/'));
76+
});
77+
78+
gulp.task('build-debug', [ 'concat-sjcl' ], function(callback) {
79+
webpack({
80+
cache: true,
81+
entry: './src/js/ripple/index.js',
82+
output: {
83+
library: 'ripple',
84+
path: './build/',
85+
filename: [ 'ripple-', '-debug.js' ].join(pkg.version)
86+
},
87+
debug: true,
88+
devtool: 'eval'
89+
}, callback);
90+
});
91+
92+
/**
93+
* Generate a WebPack external for a given unavailable module which replaces
94+
* that module's constructor with an error-thrower
95+
*/
96+
97+
function buildUseError(cons) {
98+
return 'var {<CONS>:function(){throw new Error("Class is unavailable in this build: <CONS>")}}'
99+
.replace(new RegExp('<CONS>', 'g'), cons);
100+
};
101+
102+
gulp.task('build-core', [ 'concat-sjcl' ], function(callback) {
103+
webpack({
104+
entry: [
105+
'./src/js/ripple/remote.js'
106+
],
107+
externals: [
108+
{
109+
'./transaction': buildUseError('Transaction'),
110+
'./orderbook': buildUseError('OrderBook'),
111+
'./account': buildUseError('Account'),
112+
'./serializedobject': buildUseError('SerializedObject')
113+
}
114+
],
115+
output: {
116+
library: 'ripple',
117+
path: './build/',
118+
filename: [ 'ripple-', '-core.js' ].join(pkg.version)
119+
},
120+
plugins: [
121+
new webpack.optimize.UglifyJsPlugin()
122+
]
123+
}, callback);
124+
});
125+
71126
gulp.task('bower-build', [ 'build' ], function(callback) {
72127
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
73128
.pipe(rename('ripple.js'))
@@ -88,45 +143,11 @@ gulp.task('bower-build-debug', [ 'build-debug' ], function(callback) {
88143

89144
gulp.task('bower-version', function() {
90145
gulp.src('./dist/bower.json')
91-
.pipe(bump({version: pkg.version}))
146+
.pipe(bump({ version: pkg.version }))
92147
.pipe(gulp.dest('./dist/'));
93148
});
94149

95-
gulp.task('version-bump', function() {
96-
if (!argv.type) {
97-
throw new Error("No type found, pass it in using the --type argument");
98-
}
99-
gulp.src('./package.json')
100-
.pipe(bump({type:argv.type}))
101-
.pipe(gulp.dest('./'));
102-
});
103-
104-
gulp.task('version-beta', function() {
105-
gulp.src('./package.json')
106-
.pipe(bump({version: pkg.version+'-beta'}))
107-
.pipe(gulp.dest('./'));
108-
});
109-
110-
gulp.task('build-min', [ 'build' ], function(callback) {
111-
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
112-
.pipe(uglify())
113-
.pipe(rename([ 'ripple-', '-min.js' ].join(pkg.version)))
114-
.pipe(gulp.dest('./build/'));
115-
});
116-
117-
gulp.task('build-debug', [ 'concat-sjcl' ], function(callback) {
118-
webpack({
119-
cache: true,
120-
entry: './src/js/ripple/index.js',
121-
output: {
122-
library: 'ripple',
123-
path: './build/',
124-
filename: [ 'ripple-', '-debug.js' ].join(pkg.version)
125-
},
126-
debug: true,
127-
devtool: 'eval'
128-
}, callback);
129-
});
150+
gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug', 'bower-version']);
130151

131152
gulp.task('lint', function() {
132153
gulp.src('src/js/ripple/*.js')
@@ -158,6 +179,20 @@ gulp.task('watch', function() {
158179
gulp.watch('src/js/ripple/*', [ 'build-debug' ]);
159180
});
160181

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

163-
gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug', 'bower-version']);
187+
gulp.src('./package.json')
188+
.pipe(bump({ type: argv.type }))
189+
.pipe(gulp.dest('./'));
190+
});
191+
192+
gulp.task('version-beta', function() {
193+
gulp.src('./package.json')
194+
.pipe(bump({ version: pkg.version + '-beta' }))
195+
.pipe(gulp.dest('./'));
196+
});
197+
198+
gulp.task('default', [ 'concat-sjcl', 'build', 'build-debug', 'build-min' ]);

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A JavaScript API for interacting with Ripple in Node.js and the browser
1616
###In this file
1717

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

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

4949

50-
**Building ripple-lib from github**
50+
**Building ripple-lib for browser environments**
51+
52+
ripple-lib uses Gulp to generate browser builds. These steps will generate minified and non-minified builds of ripple-lib in the `build/` directory.
5153

5254
```
5355
$ git clone https://github.com/ripple/ripple-lib
5456
$ npm install
5557
$ npm run build
5658
```
5759

58-
Then use the minified `build/ripple-*-min.js`
60+
**Restricted browser builds**
61+
62+
You may generate browser builds that contain a subset of features. To do this, run `./node_modules/.bin/gulp build-<name>`
63+
64+
+ `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.
5965

60-
##Quickstart
66+
##Quick start
6167

6268
`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
6369

src/js/ripple/server.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ var util = require('util');
22
var url = require('url');
33
var EventEmitter = require('events').EventEmitter;
44
var Amount = require('./amount').Amount;
5-
var Transaction = require('./transaction').Transaction;
65
var log = require('./log').internal.sub('server');
76

87
/**
@@ -760,22 +759,16 @@ Server.prototype._isConnected = function() {
760759
* Calculate transaction fee
761760
*
762761
* @param {Transaction|Number} Fee units for a provided transaction
763-
* @return {Number} Final fee in XRP for specified number of fee units
762+
* @return {String} Final fee in XRP for specified number of fee units
764763
* @api private
765764
*/
766765

767-
Server.prototype._computeFee = function(transaction) {
768-
var units;
769-
770-
if (transaction instanceof Transaction) {
771-
units = transaction._getFeeUnits();
772-
} else if (typeof transaction === 'number') {
773-
units = transaction;
774-
} else {
766+
Server.prototype._computeFee = function(feeUnits) {
767+
if (isNaN(feeUnits)) {
775768
throw new Error('Invalid argument');
776769
}
777770

778-
return this._feeTx(units).to_json();
771+
return this._feeTx(Number(feeUnits)).to_json();
779772
};
780773

781774
/**

src/js/ripple/transaction.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Transaction.prototype._computeFee = function() {
276276
for (var i=0; i<servers.length; i++) {
277277
var server = servers[i];
278278
if (server._connected) {
279-
fees.push(Number(server._computeFee(this)));
279+
fees.push(Number(server._computeFee(this._getFeeUnits())));
280280
}
281281
}
282282

test/server-test.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -1006,12 +1006,6 @@ describe('Server', function() {
10061006
assert(server._isConnected());
10071007
});
10081008

1009-
it('Compute fee - transaction', function() {
1010-
var server = new Server(new Remote(), 'ws://localhost:5748');
1011-
var transaction = new Transaction();
1012-
assert.strictEqual(server._computeFee(transaction), '12');
1013-
});
1014-
10151009
it('Compute fee - fee units', function() {
10161010
var server = new Server(new Remote(), 'ws://localhost:5748');
10171011
var transaction = new Transaction();
@@ -1033,7 +1027,7 @@ describe('Server', function() {
10331027
server._load_factor = 256 * 4;
10341028

10351029
var transaction = new Transaction();
1036-
assert.strictEqual(server._computeFee(transaction), '48');
1030+
assert.strictEqual(server._computeFee(10), '48');
10371031
});
10381032

10391033
it('Compute reserve', function() {

0 commit comments

Comments
 (0)