For a file with multiple languages, you could split up the languages, then call the relevant hook.
hooks('.xxx').push(function({filename, content, hook}){
var tspart = // extract the typescript part of the content
var cspart = // extract the coffeescript part of the content
return hook('ts', {content : tspart}) + '\n' + hook('cs', {content : cspart});
});
The hook method would automatically bind the filename etc. to the related hook method.
It would require a change to the current hook.js which always just reads in the content. Would probably need to split it into 2 methods, one to read the file, and one to transpile it.
If no content is provided, the hook method would have to pass in the current content.
You could pass in a filename and it would read that file in and pass it to the next method.
How would it handle sourcemaps?
hook('ts'); // would pass in the file content in its current state (i.e. with any transpilation that has already happened
hook('ts', {content}); // would pass the provided content value with the current filename
hook('ts', {content, filename}); // allows you to pass content and specify a custom filename
hook('ts', {filename}); // would read the contents of filename
hook('ts', 'module.exports=foo'); // same as passing in {content}
For a file with multiple languages, you could split up the languages, then call the relevant hook.