jackmellis / require-extension-hooks

Add hooks for js extension types
17 stars 2 forks source link

Manually trigger another hook #1

Closed jackmellis closed 7 years ago

jackmellis commented 7 years ago

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});
});
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}