Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Emit 'compile' to allow hooks to modify the code before it's compiled.

This commit allows a hook to modify the contents of the file being
compiled. That can be used to process directives, such as custom
require's, etc.
  • Loading branch information...
commit 4c9d441b36dd27ee8387ed46bc77274bea2e4ed9 1 parent 3ebe243
@StanAngeloff authored
Showing with 17 additions and 10 deletions.
  1. +17 −10 lib/lotte.js
View
27 lib/lotte.js
@@ -188,17 +188,24 @@ function processOne(file, template, options, resume) {
if (e) {
return resume(e);
}
- var compiled = substitute(template, file, code, options);
- try {
- require('vm').createScript(compiled, file);
- } catch (e) {
- return resume(new Error("Could not process '" + file + "', " + e));
- }
- fs.writeFile(temporary, compiled, 'utf8', function(e) {
- if (e) {
- return resume(e);
+ var args = {
+ file: file,
+ template: template,
+ code: code
+ };
+ events.message('compile', [args, options], function() {
+ var compiled = substitute(args.template, file, args.code, options);
+ try {
+ require('vm').createScript(compiled, file);
+ } catch (e) {
+ return resume(new Error("Could not process '" + file + "', " + e));
}
- launch(temporary, options, resume);
+ fs.writeFile(temporary, compiled, 'utf8', function(e) {
+ if (e) {
+ return resume(e);
+ }
+ launch(temporary, options, resume);
+ });
});
});
});

0 comments on commit 4c9d441

Please sign in to comment.
Something went wrong with that request. Please try again.