Set up babel transpiler

This commit is contained in:
Chris Clark
2015-05-13 14:38:21 -07:00
parent e66978fb48
commit 398f8d001f
17 changed files with 94 additions and 75 deletions

2
.gitignore vendored
View File

@@ -17,7 +17,7 @@
# Ignore object files.
*.o
build/*.js
build/
tags
bin/rippled
Debug/*.*

View File

@@ -1,2 +1,4 @@
lib-cov
coverage.html
src
dist/bower

View File

@@ -1,9 +1,9 @@
language: node_js
node_js:
- "0.10"
- "0.12"
before_script:
- npm install -g eslint
- curl 'https://raw.githubusercontent.com/ripple/javascript-style-guide/master/eslintrc' > ./eslintrc
- curl 'https://raw.githubusercontent.com/ripple/javascript-style-guide/es6/eslintrc' > ./eslintrc
- eslint --reset -c ./eslintrc $(git --no-pager diff --name-only -M100% --diff-filter=AM --relative $(git merge-base FETCH_HEAD origin/HEAD) FETCH_HEAD | grep "\.js$")
script: MOCHA_REPORTER=tap npm test --coverage
after_success:

View File

@@ -1,4 +1,7 @@
/* eslint-disable no-var, no-param-reassign */
/* these eslint rules are disabled because gulp does not support babel yet */
'use strict';
var _ = require('lodash');
var gulp = require('gulp');
var gutil = require('gulp-util');
var watch = require('gulp-watch');
@@ -15,20 +18,33 @@ var argv = require('yargs').argv;
var pkg = require('./package.json');
function logPluginError(error) {
gutil.log(error.toString());
}
gulp.task('build', function(callback) {
webpack({
function webpackConfig(extension, overrides) {
overrides = overrides || {};
var defaults = {
cache: true,
entry: './src/index.js',
output: {
library: 'ripple',
path: './build/',
filename: ['ripple-', '.js'].join(pkg.version)
filename: ['ripple-', extension].join(pkg.version)
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader?optional=runtime'
}]
}
}, callback);
};
return _.assign({}, defaults, overrides);
}
function logPluginError(error) {
gutil.log(error.toString());
}
gulp.task('build', function(callback) {
webpack(webpackConfig('.js'), callback);
});
gulp.task('build-min', ['build'], function() {
@@ -39,17 +55,8 @@ gulp.task('build-min', ['build'], function() {
});
gulp.task('build-debug', function(callback) {
webpack({
cache: true,
entry: './src/index.js',
output: {
library: 'ripple',
path: './build/',
filename: ['ripple-', '-debug.js'].join(pkg.version)
},
debug: true,
devtool: 'eval'
}, callback);
var configOverrides = {debug: true, devtool: 'eval'};
webpack(webpackConfig('-debug.js', configOverrides), callback);
});
/**
@@ -64,51 +71,44 @@ function buildUseError(cons) {
}
gulp.task('build-core', function(callback) {
webpack({
entry: [
'./src/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)
},
var configOverrides = {
cache: false,
entry: './src/remote.js',
externals: [{
'./transaction': buildUseError('Transaction'),
'./orderbook': buildUseError('OrderBook'),
'./account': buildUseError('Account'),
'./serializedobject': buildUseError('SerializedObject')
}],
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
}, callback);
};
webpack(webpackConfig('-core.js', configOverrides), callback);
});
gulp.task('bower-build', ['build'], function() {
return gulp.src(['./build/ripple-', '.js'].join(pkg.version))
.pipe(rename('ripple.js'))
.pipe(gulp.dest('./dist/'));
.pipe(gulp.dest('./dist/bower'));
});
gulp.task('bower-build-min', ['build-min'], function() {
return gulp.src(['./build/ripple-', '-min.js'].join(pkg.version))
.pipe(rename('ripple-min.js'))
.pipe(gulp.dest('./dist/'));
.pipe(gulp.dest('./dist/bower'));
});
gulp.task('bower-build-debug', ['build-debug'], function() {
return gulp.src(['./build/ripple-', '-debug.js'].join(pkg.version))
.pipe(rename('ripple-debug.js'))
.pipe(gulp.dest('./dist/'));
.pipe(gulp.dest('./dist/bower'));
});
gulp.task('bower-version', function() {
gulp.src('./dist/bower.json')
gulp.src('./dist/bower/bower.json')
.pipe(bump({version: pkg.version}))
.pipe(gulp.dest('./dist/'));
.pipe(gulp.dest('./dist/bower'));
});
gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug',

16
npm-shrinkwrap.json generated
View File

@@ -2,12 +2,22 @@
"name": "ripple-lib",
"version": "0.12.5-rc2",
"npm-shrinkwrap-version": "5.4.0",
"node-version": "v0.10.38",
"node-version": "v0.12.3",
"dependencies": {
"async": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/async/-/async-0.9.0.tgz"
},
"babel-runtime": {
"version": "5.3.3",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-5.3.3.tgz",
"dependencies": {
"core-js": {
"version": "0.9.9",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-0.9.9.tgz"
}
}
},
"bignumber.js": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-2.0.7.tgz"
@@ -17,8 +27,8 @@
"resolved": "https://registry.npmjs.org/extend/-/extend-1.2.1.tgz"
},
"lodash": {
"version": "3.7.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-3.7.0.tgz"
"version": "3.8.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-3.8.0.tgz"
},
"lru-cache": {
"version": "2.5.2",

View File

@@ -3,19 +3,19 @@
"version": "0.12.5-rc2",
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
"files": [
"src/js/*",
"dist/npm/*",
"bin/*",
"build/*",
"test/*",
"Makefile",
"Gulpfile.js"
],
"main": "src/",
"main": "dist/npm/",
"directories": {
"test": "test"
},
"dependencies": {
"async": "~0.9.0",
"babel-runtime": "^5.3.2",
"bignumber.js": "^2.0.3",
"extend": "~1.2.1",
"lodash": "^3.1.0",
@@ -26,6 +26,9 @@
},
"devDependencies": {
"assert-diff": "^1.0.1",
"babel": "^5.3.3",
"babel-core": "^5.3.2",
"babel-loader": "^5.0.0",
"coveralls": "~2.10.0",
"eslint": "^0.18.0",
"gulp": "~3.8.10",
@@ -48,10 +51,12 @@
},
"scripts": {
"build": "gulp",
"compile": "babel --optional runtime -d dist/npm/ src/",
"prepublish": "npm run compile",
"postinstall": "cd node_modules/sjcl; ./configure --with-all --compress=none; make",
"test": "istanbul test _mocha",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/ripple/javascript-style-guide/master/eslintrc'; fi; eslint --reset -c eslintrc src/*.js",
"lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/ripple/javascript-style-guide/es6/eslintrc'; fi; eslint --reset -c eslintrc src/*.js",
"perf": "./scripts/perf_test.sh"
},
"repository": {

View File

@@ -8,4 +8,4 @@ then
mkdir -p "$DIR/cache"
curl -L "$URL" > "$DEST"
fi
time node "$DIR/verify_ledger_json.js" "$DEST"
npm run compile && time node "$DIR/verify_ledger_json.js" "$DEST"

View File

@@ -17,15 +17,15 @@ echo "publish to npm"
npm publish
exit_on_error
rm -rf dist
rm -rf dist/bower
echo ""
echo "publish to bower"
git clone git@github.com:ripple/bower-ripple.git dist
git clone git@github.com:ripple/bower-ripple.git dist/bower
gulp bower
exit_on_error
cd dist
cd dist/bower
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
echo "version: $version"
git add ripple.js ripple-debug.js ripple-min.js bower.json
@@ -40,4 +40,4 @@ exit_on_error
git push origin master
git push --tags origin master
cd ..
cd ..

View File

@@ -17,15 +17,15 @@ echo "publish rc to npm"
npm publish --tag beta
exit_on_error
rm -rf dist
rm -rf dist/bower
echo ""
echo "publish to bower"
git clone git@github.com:ripple/bower-ripple.git dist
git clone git@github.com:ripple/bower-ripple.git dist/bower
gulp bower
exit_on_error
cd dist
cd dist/bower
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
echo "version: $version"
git add ripple.js ripple-debug.js ripple-min.js bower.json
@@ -40,4 +40,4 @@ exit_on_error
git push origin master
git push --tags origin master
cd ..
cd ..

View File

@@ -1,7 +1,7 @@
rm -rf dist
git clone git@github.com:ripple/bower-ripple.git dist
rm -rf dist/bower
git clone git@github.com:ripple/bower-ripple.git dist/bower
gulp bower
cd dist
cd dist/bower
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
echo "version: $version"
git add ripple.js ripple-debug.js ripple-min.js bower.json
@@ -9,4 +9,4 @@ git commit -m "[TASK] add v$version"
git tag "v$version"
git push origin master
git push --tags origin master
cd ..
cd ..

View File

@@ -1,8 +1,8 @@
'use strict';
var fs = require('fs');
var Amount = require('../src/js/ripple').Amount;
var Ledger = require('../src/js/ripple/ledger').Ledger;
var Amount = require('../dist/npm').Amount;
var Ledger = require('../dist/npm/ledger').Ledger;
function parse_options(from, flags) {
var argv = from.slice(),

View File

@@ -542,7 +542,7 @@ Request.prototype.addStream = function(stream, values) {
break;
}
} else if (arguments.length > 1) {
for (arg in arguments) {
for (var arg in arguments) {
this.addStream(arguments[arg]);
}
return;

View File

@@ -1150,7 +1150,7 @@ describe('Amount', function() {
var demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_text_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
demAmount = demAmount.applyInterest(459990264);
assert.strictEqual(demAmount.to_text_full(), '9.294949401870435/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_text_full(), '9.294949401870436/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('from_json apply interest XAU', function() {
@@ -1168,7 +1168,7 @@ describe('Amount', function() {
var demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_human_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
demAmount = demAmount.applyInterest(459990264);
assert.strictEqual(demAmount.to_human_full(), '9.294949401870435/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_human_full(), '9.294949401870436/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('from_json apply interest XAU human', function() {

View File

@@ -272,7 +272,9 @@ describe('Currency', function() {
assert.equal(0.995, precision(cur.get_interest_at(new Date(timeUtil.fromRipple(443845330 + 31536000))), 14));
// After one demurrage period, 1/e should have occurred
assert.equal(1/Math.E, cur.get_interest_at(443845330 + 6291418827.05));
var epsilon = 1e-14;
assert(Math.abs(
1/Math.E - cur.get_interest_at(443845330 + 6291418827.05)) < epsilon);
// One year before start, it should be (roughly) 0.5% higher.
assert.equal(1.005, precision(cur.get_interest_at(443845330 - 31536000), 4));

View File

@@ -7,7 +7,7 @@ var Ledger = require('ripple-lib').Ledger;
* @param ledger_index {Number}
* Expects a corresponding ledger dump in $repo/test/fixtures/ folder
*/
create_ledger_test = function (ledger_index) {
var create_ledger_test = function (ledger_index) {
describe(String(ledger_index), function() {
var path = __dirname + '/fixtures/ledger-full-'+ledger_index+'.json';

View File

@@ -1 +1 @@
--reporter spec --timeout 10000 --slow 500
--reporter spec --timeout 10000 --slow 500 --compilers js:babel/register

View File

@@ -510,7 +510,7 @@ describe('Request', function() {
it('Timeout', function(done) {
var server = makeServer('wss://localhost:5006');
var successEmited = false;
var successEmitted = false;
server._request = function(req) {
assert(req instanceof Request);
@@ -542,7 +542,7 @@ describe('Request', function() {
it('Timeout - satisfied', function(done) {
var server = makeServer('wss://localhost:5006');
var successEmited = false;
var successEmitted = false;
server._request = function(req) {
assert(req instanceof Request);