browserify workaround to avoid changing code. see #158.

This commit is contained in:
Christopher Jeffrey 2015-07-26 13:35:39 -07:00
parent 58a6b6c242
commit fa080e6546
2 changed files with 42 additions and 1 deletions

38
browser/transform.js Normal file
View File

@ -0,0 +1,38 @@
var Transform = require('stream').Transform;
function transform(target) {
var data = '';
var tr = new Transform;
tr._transform = function(chunk, encoding, callback) {
if (!target) {
return callback(null, chunk);
}
data += chunk;
return callback(null, chunk);
};
tr._flush = function(callback) {
if (!target) {
return callback();
}
tr.push(compile(data));
return callback();
};
return tr;
}
function compile(data) {
var out = '';
var names = /widget\.classes = (\[[^\]]+\]);/.exec(data)[1];
names = JSON.parse(names.replace(/'/g, '"')).forEach(function(name) {
name = name.toLowerCase();
out += '\nrequire(\'./widgets/' + name + '\');';
});
return out;
}
module.exports = function(file) {
if (!~file.indexOf('widget.js')) {
return transform();
}
return transform(true);
};

View File

@ -10,5 +10,8 @@
"homepage": "https://github.com/chjj/blessed",
"bugs": { "url": "http://github.com/chjj/blessed/issues" },
"keywords": ["curses", "tui", "tput", "terminfo", "termcap"],
"tags": ["curses", "tui", "tput", "terminfo", "termcap"]
"tags": ["curses", "tui", "tput", "terminfo", "termcap"],
"browserify": {
"transform": ["./browser/transform.js"]
}
}