Skip to content

Commit

Permalink
Set up babel transpiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Clark committed May 14, 2015
1 parent e66978f commit 398f8d0
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Ignore object files.
*.o
build/*.js
build/
tags
bin/rippled
Debug/*.*
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
lib-cov
coverage.html
src
dist/bower
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
84 changes: 42 additions & 42 deletions Gulpfile.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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() {
Expand All @@ -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);
});

/**
Expand All @@ -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',
Expand Down
16 changes: 13 additions & 3 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/perf_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions scripts/publish
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]:ripple/bower-ripple.git dist
git clone [email protected]: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
Expand All @@ -40,4 +40,4 @@ exit_on_error
git push origin master
git push --tags origin master

cd ..
cd ..
8 changes: 4 additions & 4 deletions scripts/publish_rc
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]:ripple/bower-ripple.git dist
git clone [email protected]: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
Expand All @@ -40,4 +40,4 @@ exit_on_error
git push origin master
git push --tags origin master

cd ..
cd ..
8 changes: 4 additions & 4 deletions scripts/publish_to_bower
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
rm -rf dist
git clone [email protected]:ripple/bower-ripple.git dist
rm -rf dist/bower
git clone [email protected]: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
git commit -m "[TASK] add v$version"
git tag "v$version"
git push origin master
git push --tags origin master
cd ..
cd ..
4 changes: 2 additions & 2 deletions scripts/verify_ledger_json.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/amount-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion test/currency-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion test/ledger-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--reporter spec --timeout 10000 --slow 500
--reporter spec --timeout 10000 --slow 500 --compilers js:babel/register
Loading

0 comments on commit 398f8d0

Please sign in to comment.