browserify workaround to avoid changing code. see #158.
This commit is contained in:
parent
58a6b6c242
commit
fa080e6546
|
@ -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);
|
||||
};
|
|
@ -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"]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue