Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Stan Angeloff authored

Showing 1 changed file with 17 additions and 10 deletions. Show diff stats Hide diff stats

  1. +17 10 lib/lotte.js
27 lib/lotte.js
@@ -188,17 +188,24 @@ function processOne(file, template, options, resume) {
188 188 if (e) {
189 189 return resume(e);
190 190 }
191   - var compiled = substitute(template, file, code, options);
192   - try {
193   - require('vm').createScript(compiled, file);
194   - } catch (e) {
195   - return resume(new Error("Could not process '" + file + "', " + e));
196   - }
197   - fs.writeFile(temporary, compiled, 'utf8', function(e) {
198   - if (e) {
199   - return resume(e);
  191 + var args = {
  192 + file: file,
  193 + template: template,
  194 + code: code
  195 + };
  196 + events.message('compile', [args, options], function() {
  197 + var compiled = substitute(args.template, file, args.code, options);
  198 + try {
  199 + require('vm').createScript(compiled, file);
  200 + } catch (e) {
  201 + return resume(new Error("Could not process '" + file + "', " + e));
200 202 }
201   - launch(temporary, options, resume);
  203 + fs.writeFile(temporary, compiled, 'utf8', function(e) {
  204 + if (e) {
  205 + return resume(e);
  206 + }
  207 + launch(temporary, options, resume);
  208 + });
202 209 });
203 210 });
204 211 });

0 comments on commit 4c9d441

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