-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite bundling system (close #186)
Browserify has been updated and the whole bundling process was revisited. Cucumber is now a global function (window.Cucumber) as well as CucumberHTML. It's also uglified. Also, all Gherkin lexers are now available in the browser.
- Loading branch information
Showing
9 changed files
with
447 additions
and
9,186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
window.CucumberHTML = require('cucumber-html'); | ||
module.exports = require('./lib/cucumber'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,76 @@ | ||
var fs = require('fs'); | ||
var through = require('through'); | ||
var browserify = require('browserify'); | ||
|
||
var Bundler = function () { | ||
var requires = [ | ||
__dirname + '/node_modules/cucumber-html' | ||
]; | ||
function Bundler() { | ||
var source; | ||
|
||
var self = browserify({ | ||
mount: '/cucumber.js', | ||
require: requires, | ||
ignore: ['./cucumber/cli', 'connect'] | ||
}); | ||
var self = { | ||
middleware: function (req, res, next) { | ||
function serveBundle(res) { | ||
console.log("/cucumber.js 200", source.length); | ||
res.setHeader('Content-Type', 'application/javascript'); | ||
res.write(source); | ||
res.end(); | ||
}; | ||
|
||
self.addEntry('underscore.js', {dirname: __dirname+"/node_modules/underscore", target: "/node_modules/underscore"}); | ||
self.addEntry('lib/gherkin.js', {dirname: __dirname+"/node_modules/gherkin", target: "/node_modules/gherkin"}); | ||
self.addEntry('lib/cucumber.js', {dirname: __dirname, target: "/cucumber"}); | ||
self.addEntry('lib/gherkin/lexer/en.js', {dirname: __dirname+"/node_modules/gherkin", target: "/node_modules/gherkin/lexer/en"}); | ||
if (req.originalUrl === '/cucumber.js') { | ||
if (!source) { | ||
self.bundle(function (err) { | ||
if (err) return next(err); | ||
serveBundle(res); | ||
}); | ||
} else { | ||
serveBundle(res); | ||
} | ||
} else { | ||
next(); | ||
} | ||
}, | ||
|
||
self.prepend('(function(context) {'); | ||
if (process.env.DEBUG_LEVEL) | ||
self.append("context.cucumberRequire = require;\n"); | ||
self.append("context.Cucumber = require('/cucumber');\ncontext.CucumberHTML = require('cucumber-html/src/main/resources/cucumber/formatter/formatter');\n})(window);"); | ||
bundle: function (callback) { | ||
var bundler = browserify({debug: true, standalone: 'Cucumber'}); | ||
bundler.transform({global: true}, function (file) { | ||
var data = ''; | ||
return through(write, end); | ||
function write (buf) { data += buf } | ||
function end () { | ||
var path = __dirname + '/node_modules/gherkin/lib'; | ||
var lexersPath = path + '/gherkin/lexer'; | ||
if (file === path + '/gherkin.js') { | ||
// Patch gherkin so that all lexers are available statically: | ||
var bufferPrefix = ''; | ||
var dirFiles = fs.readdirSync(lexersPath); | ||
dirFiles.forEach(function (dirFile) { | ||
var matches = dirFile.match(/^(.*)\.js$/); | ||
if (matches && !dirFile.match(/\.min\.js$/)) { | ||
bufferPrefix += "require('./gherkin/lexer/" + matches[1] + "');\n"; | ||
} | ||
}); | ||
data = bufferPrefix + data; | ||
} | ||
var ignoredFiles = [ | ||
__dirname + '/lib/cucumber/cli.js' | ||
]; | ||
if (ignoredFiles.indexOf(file) > -1) { | ||
data = ''; | ||
} | ||
this.queue(data); | ||
this.queue(null); | ||
} | ||
}); | ||
bundler.transform({global:true}, 'uglifyify'); | ||
bundler.exclude('./lib/cucumber/cli'); // TODO: doesn't work, fix this | ||
bundler.require('./bundle-main', { expose: 'cucumber' }); | ||
bundler.bundle(function (err, _source, map) { | ||
if (err) return callback(err); | ||
source = _source; | ||
callback(null, source); | ||
}); | ||
} | ||
}; | ||
|
||
return self; | ||
}; | ||
} | ||
|
||
module.exports = Bundler; | ||
module.exports = Bundler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.