Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introducing auto-compile on file change. Next up is supporting other …

…file extensions.
  • Loading branch information...
commit 6f37371a827add4623f3b94501d5cdbd795791ed 1 parent efac2fe
@jwietelmann jwietelmann authored
Showing with 31 additions and 6 deletions.
  1. +1 −1  .gitignore
  2. +28 −0 handlebars-precompiler.js
  3. +2 −5 test.js
View
2  .gitignore
@@ -1,2 +1,2 @@
node_modules
-test_ouput.js
+test_output.js
View
28 handlebars-precompiler.js
@@ -104,4 +104,32 @@ exports.do = function(opts) {
} else {
return output;
}
+}
+
+exports.watchDir = function(dir, outfile) {
+ var fs = require('fs')
+ , file = require('file');
+
+ var viewDir = __dirname + '/test_views'
+ , outfile = 'test_output.js'
+
+ var compileOnChange = function(event, filename) {
+ console.log('[' + event + '] detected in ' + (filename ? filename : '[filename not supported]'));
+ console.log('[compiling] ' + outfile);
+ exports.do({
+ templates: [viewDir],
+ output: outfile,
+ min: true
+ });
+ }
+
+ file.walk(viewDir, function(_, dirPath, dirs, files) {
+ for(var i = 0; i < files.length; i++) {
+ var file = files[i];
+ if(/\.handlebars$/.test(file)) {
+ fs.watch(file, compileOnChange);
+ console.log('[watching] ' + file);
+ }
+ }
+ });
}
View
7 test.js
@@ -1,5 +1,2 @@
-var compiler = require('./handlebars-precompiler');
-var output = compiler.do({
- templates: [__dirname + '/test_views'],
- output: 'test_output.js'
-});
+c.watchDir(__dirname + '/test_views', 'test_output.js');
Please sign in to comment.
Something went wrong with that request. Please try again.