Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
add build scripts to programmatically create files ace editor can con…
Browse files Browse the repository at this point in the history
…sume
  • Loading branch information
chmontgomery committed Mar 31, 2015
1 parent fdf36c5 commit dc2750b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions javascript/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ acceptance/
.compared
node_modules/
lib/gherkin/dialects.json
dist/
63 changes: 63 additions & 0 deletions javascript/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
var gulp = require('gulp');
var wrap = require('gulp-wrap-amd');
var through = require('through2');
var path = require('path');
var fs = require('fs');

function replaceAll(str, find, replace) {
return str.split(find).join(replace);
}

gulp.task('wrap:gherkin', function () {
gulp.src('./lib/**/*.js')
.pipe(through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}

var fileName = path.basename(file.path);
var newFileContents = replaceAll(file.contents.toString(), "require('tea-error')", "require('./tea/error')");

if (fileName === 'token_matcher.js') {
// token_matcher.js requires a json file. To make the file browser compatible, we need to paste the
// contents of the json file into the js file
return fs.readFile(path.join(__dirname, 'lib/gherkin/dialects.json'), 'utf8', function (err, data) {
if (err) throw err;
file.contents = new Buffer(replaceAll(newFileContents, "require('./dialects.json')", data.trim()));
cb(null, file);
});
}

file.contents = new Buffer(newFileContents);
cb(null, file);
}))
.pipe(wrap({
exports: 'module.exports'
}))
.pipe(gulp.dest('./dist/'))
});

gulp.task('wrap:node_modules', function () {
gulp.src([
'./node_modules/tea-error/lib/error.js',
'./node_modules/tea-error/node_modules/tea-extend/lib/extend.js'
])
.pipe(through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}

var newFileContents = replaceAll(file.contents.toString(), "require('tea-extend')", "require('./extend')");
file.contents = new Buffer(newFileContents);

cb(null, file);
}))
.pipe(wrap({
exports: 'module.exports'
}))
.pipe(gulp.dest('./dist/gherkin/tea'))
});

gulp.task('default', ['wrap:gherkin', 'wrap:node_modules']);
5 changes: 4 additions & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
},
"homepage": "https://github.com/cucumber/gherkin3",
"devDependencies": {
"mocha": "^2.1.0"
"gulp": "^3.8.11",
"gulp-wrap-amd": "^0.5.0",
"mocha": "^2.1.0",
"through2": "^0.6.3"
},
"dependencies": {
"tea-error": "^0.1.0"
Expand Down

0 comments on commit dc2750b

Please sign in to comment.