From dba679ecf8b90a2be87f38a412a89670122ce324 Mon Sep 17 00:00:00 2001 From: humanchimp Date: Thu, 12 Mar 2015 13:00:48 -0700 Subject: [PATCH 1/5] babel: initial commit; tests fail --- Gulpfile.js | 53 +++++++++++++++++++++++++++++--------------- package.json | 5 ++++- src/point.js | 6 ++--- test/algebraic.js | 3 --- test/board.js | 3 --- test/castling.js | 3 --- test/fen.js | 3 --- test/fischerandom.js | 3 --- test/line.js | 3 --- test/mobility.js | 3 --- test/pawn.js | 3 --- test/pgn.js | 3 --- test/point.js | 3 --- test/position.js | 3 --- test/promotion.js | 3 --- test/query.js | 3 --- test/util.js | 3 --- 17 files changed, 42 insertions(+), 64 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index ae4f84d..d421b3e 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -1,6 +1,5 @@ var path = require('path'); var gulp = require('gulp'); -var traceur = require('gulp-traceur'); var rename = require('gulp-rename'); var watch = require('gulp-watch'); var uglify = require('gulp-uglify'); @@ -8,12 +7,30 @@ var argv = require('minimist')(process.argv); var browserify = require('browserify'); var source = require('vinyl-source-stream'); +var prepend = require('gulp-insert').prepend; +var Promise = require('bluebird'); +var fs = Promise.promisifyAll(require('fs')); +var babel = require('gulp-babel'); +var sourcemaps = require('gulp-sourcemaps'); + gulp.task('default', ['core']); gulp.task('core', function () { return esify('./src/*.js'); }); +function esify(src) { + gulp.src(src). + pipe(sourcemaps.init()). + pipe(babel({ + modules: 'common', + optional: ['runtime'], + })). + pipe((sourcemaps.write("."))). + pipe(gulp.dest('lib')) + ; +} + gulp.task('browserify', ['default'], function () { return ( browserify(). @@ -35,22 +52,22 @@ gulp.task('uglify', ['browserify'], function () { ); }); -function esify(src) { - var p = path.normalize(path.dirname(src)).replace(/^src\/?/, '').replace('*', ''); - var stream = gulp.src(src); +// function esify(src) { +// var p = path.normalize(path.dirname(src)).replace(/^src\/?/, '').replace('*', ''); +// var stream = gulp.src(src); - if (argv.w || argv.watch) { - stream = stream.pipe(watch()); - } +// if (argv.w || argv.watch) { +// stream = stream.pipe(watch()); +// } - return stream. - pipe(traceur({ - experimental: true, - sourceMap: true - })). - pipe(rename({ - extname: '.js' - })). - pipe(gulp.dest(path.join('lib', p))) - ; -} +// return stream. +// pipe(traceur({ +// experimental: true, +// sourceMap: true +// })). +// pipe(rename({ +// extname: '.js' +// })). +// pipe(gulp.dest(path.join('lib', p))) +// ; +// } diff --git a/package.json b/package.json index 139a3d1..29ee00c 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A library for chess positions", "main": "./lib/index.js", "dependencies": { + "babel-runtime": "^4.7.8", "jsdice": "^1.1.0", "lodash.assign": "^2.4.1", "lodash.isnumber": "^2.4.1", @@ -15,13 +16,15 @@ "browserify": "^5.9.1", "coveralls": "^2.11.1", "gulp": "^3.8.7", + "gulp-babel": "^4.0.0", + "gulp-insert": "^0.4.0", "gulp-rename": "^1.2.0", + "gulp-sourcemaps": "^1.5.0", "gulp-traceur": "^0.11.0", "gulp-uglify": "^1.0.0", "gulp-watch": "^0.6.9", "istanbul": "^0.3.0", "lodash.times": "^2.4.1", - "longjohn": "^0.2.4", "minimist": "^0.2.0", "tape": "^2.14.0", "vinyl-source-stream": "^0.1.1" diff --git a/src/point.js b/src/point.js index c0d03cc..6465970 100644 --- a/src/point.js +++ b/src/point.js @@ -37,10 +37,10 @@ export class Point { return this.x >= x && this.y >= y; } - *to(to) { + *to(that) { const [[x0, x1],[y0, y1]] = [ - [Math.min(this.x, to.x), Math.max(this.x, to.x)], - [Math.min(this.y, to.y), Math.max(this.y, to.y)], + [Math.min(this.x, that.x), Math.max(this.x, that.x)], + [Math.min(this.y, that.y), Math.max(this.y, that.y)], ]; for(var i = y0; i < y1; i++) { for(var j = x0; j < x1; j++) { diff --git a/test/algebraic.js b/test/algebraic.js index d0ce744..b3bec91 100644 --- a/test/algebraic.js +++ b/test/algebraic.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var Algebraic = require('../lib/algebraic.js').Algebraic; var FEN = require('../lib/fen.js').FEN; diff --git a/test/board.js b/test/board.js index bfdc3e9..569b92c 100644 --- a/test/board.js +++ b/test/board.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var board = require('../lib/fen.js').standardPosition.board; diff --git a/test/castling.js b/test/castling.js index b9e7cfe..0867eb6 100644 --- a/test/castling.js +++ b/test/castling.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var FEN = require('../lib/fen.js').FEN; var Point = require('../lib/point.js').Point; diff --git a/test/fen.js b/test/fen.js index f47b1d5..61117ec 100644 --- a/test/fen.js +++ b/test/fen.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var fen = require('../lib/fen.js'); var FEN = fen.FEN; diff --git a/test/fischerandom.js b/test/fischerandom.js index 837f812..924ba3b 100644 --- a/test/fischerandom.js +++ b/test/fischerandom.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var times = require('lodash.times'); var FEN = require('../lib/fen').FEN; diff --git a/test/line.js b/test/line.js index 81eb96c..f87c5b7 100644 --- a/test/line.js +++ b/test/line.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var Line = require('../lib/line').Line; diff --git a/test/mobility.js b/test/mobility.js index e4c055a..63ccec0 100644 --- a/test/mobility.js +++ b/test/mobility.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var Mobility = require('../lib/mobility.js').Mobility; diff --git a/test/pawn.js b/test/pawn.js index e0a8f42..9d26eeb 100644 --- a/test/pawn.js +++ b/test/pawn.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var FEN = require('../lib/fen.js').FEN; var Point = require('../lib/point.js').Point; diff --git a/test/pgn.js b/test/pgn.js index 91c45e5..b98aa8e 100644 --- a/test/pgn.js +++ b/test/pgn.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var joinPath = require('path').join; var PGN = require('../lib/pgn.js').PGN; diff --git a/test/point.js b/test/point.js index 34631a8..d0a26ff 100644 --- a/test/point.js +++ b/test/point.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var Point = require('../lib/point.js').Point; diff --git a/test/position.js b/test/position.js index d2fd6ad..faa8738 100644 --- a/test/position.js +++ b/test/position.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var joinPath = require('path').join; var FEN = require('../lib/fen.js').FEN; diff --git a/test/promotion.js b/test/promotion.js index 33bfeea..5dd3b6c 100644 --- a/test/promotion.js +++ b/test/promotion.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var FEN = require('../lib/fen.js').FEN; diff --git a/test/query.js b/test/query.js index 1c8fad4..e0f4257 100644 --- a/test/query.js +++ b/test/query.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var FEN = require('../lib/fen.js').FEN; var brands = require('../lib/brands.js'); diff --git a/test/util.js b/test/util.js index db68c93..9504b31 100644 --- a/test/util.js +++ b/test/util.js @@ -1,6 +1,3 @@ -require('traceur/bin/traceur-runtime.js'); -require('longjohn'); - var test = require('tape'); var util = require('../lib/util.js'); var brands = require('../lib/brands.js'); From 54d770cee7b50e2b19fc3e32d7b6f49e8af2d1c9 Mon Sep 17 00:00:00 2001 From: humanchimp Date: Thu, 12 Mar 2015 15:43:39 -0700 Subject: [PATCH 2/5] babel: use loose mode for now --- Gulpfile.js | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index d421b3e..7c3ac9a 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -23,6 +23,7 @@ function esify(src) { gulp.src(src). pipe(sourcemaps.init()). pipe(babel({ + loose: 'all', modules: 'common', optional: ['runtime'], })). @@ -51,23 +52,3 @@ gulp.task('uglify', ['browserify'], function () { pipe(gulp.dest('browser')) ); }); - -// function esify(src) { -// var p = path.normalize(path.dirname(src)).replace(/^src\/?/, '').replace('*', ''); -// var stream = gulp.src(src); - -// if (argv.w || argv.watch) { -// stream = stream.pipe(watch()); -// } - -// return stream. -// pipe(traceur({ -// experimental: true, -// sourceMap: true -// })). -// pipe(rename({ -// extname: '.js' -// })). -// pipe(gulp.dest(path.join('lib', p))) -// ; -// } From 0c514a923f0f5359603516f08d31506903529916 Mon Sep 17 00:00:00 2001 From: humanchimp Date: Thu, 12 Mar 2015 16:22:06 -0700 Subject: [PATCH 3/5] babel: remove fs stuff --- Gulpfile.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index 7c3ac9a..7b8b9bf 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -8,8 +8,6 @@ var browserify = require('browserify'); var source = require('vinyl-source-stream'); var prepend = require('gulp-insert').prepend; -var Promise = require('bluebird'); -var fs = Promise.promisifyAll(require('fs')); var babel = require('gulp-babel'); var sourcemaps = require('gulp-sourcemaps'); From 7841e2ddc40e035b43074bf3f2a54e6116ca3323 Mon Sep 17 00:00:00 2001 From: humanchimp Date: Thu, 12 Mar 2015 16:22:57 -0700 Subject: [PATCH 4/5] babel: remove extra parens --- Gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gulpfile.js b/Gulpfile.js index 7b8b9bf..f6c08ba 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -25,7 +25,7 @@ function esify(src) { modules: 'common', optional: ['runtime'], })). - pipe((sourcemaps.write("."))). + pipe(sourcemaps.write(".")). pipe(gulp.dest('lib')) ; } From a7089c3b03fdbd0c9f7e042547d9215ff2800b89 Mon Sep 17 00:00:00 2001 From: humanchimp Date: Thu, 12 Mar 2015 16:24:09 -0700 Subject: [PATCH 5/5] gulpfile: return the stream --- Gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gulpfile.js b/Gulpfile.js index f6c08ba..2c2ce2f 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -18,7 +18,7 @@ gulp.task('core', function () { }); function esify(src) { - gulp.src(src). + return gulp.src(src). pipe(sourcemaps.init()). pipe(babel({ loose: 'all',