Permalink
Browse files

Merge pull request #11 from jenius/master

Add callback to precompile function, make sure console.log only happens when verbose
  • Loading branch information...
2 parents 4de1363 + 83a783e commit 20e49594858a141e8388f1772c66d24de8ef4b73 @tauren committed Feb 15, 2013
View
4 bin/tmpl-precompile
@@ -1,5 +1,7 @@
+// Generated by CoffeeScript 1.4.0
#!/usr/bin/env node
;
+
var colors, cwd, fs, jsondir, jsonfile, match, precompile, settings;
jsonfile = process.argv[2] || 'tmpl-precompile.json';
@@ -28,7 +30,7 @@ if (settings !== {}) {
}
if (jsonfile.indexOf('/' > 0)) {
match = jsonfile.split(/\//);
- jsondir = match.slice(0, (match.length - 1)).join('/');
+ jsondir = match.slice(0, match.length - 1).join('/');
cwd += '/' + jsondir;
}
console.log('\n\n' + 'tmpl-precompile'.bold.underline + '\n');
View
4 bin/tmpl-precompile.js
@@ -1,5 +1,7 @@
+// Generated by CoffeeScript 1.4.0
#!/usr/bin/env node
;
+
var colors, cwd, fs, jsondir, jsonfile, match, precompile, settings;
jsonfile = process.argv[2] || 'tmpl-precompile.json';
@@ -28,7 +30,7 @@ if (settings !== {}) {
}
if (jsonfile.indexOf('/' > 0)) {
match = jsonfile.split(/\//);
- jsondir = match.slice(0, (match.length - 1)).join('/');
+ jsondir = match.slice(0, match.length - 1).join('/');
cwd += '/' + jsondir;
}
console.log('\n\n' + 'tmpl-precompile'.bold.underline + '\n');
View
2 index.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.4.0
(function() {
module.exports = require('./lib/tmpl-precompile');
View
2 lib/helpers.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.4.0
/*
extend(main, sub)
View
2 lib/namespace.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.4.0
(function() {
var Namespacer, async;
View
2 lib/optimize.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.4.0
(function() {
var extractFunction, jsp, optimizeOutput;
View
16 lib/tmpl-precompile.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.4.0
(function() {
var Namespacer, Precompiler, async, colors, extend, extractFunction, fs, globalSettings, jade, jsp, optimizeOutput, path, pro, util, version, _ref;
@@ -121,7 +121,9 @@
}
if (output != null) {
fs.writeFileSync(this.settings.output, buf);
- console.log(('Saving ' + (uglify !== false ? 'and Uglifying ' : '')).bold + ':' + output);
+ if (this.settings.verbose) {
+ console.log(('Saving ' + (uglify !== false ? 'and Uglifying ' : '')).bold + ':' + output);
+ }
}
if (this.callback != null) {
return this.callback(null, buf);
@@ -198,10 +200,11 @@
"verbose": Boolean(default:false), if should output compile info on console
"relative": Boolean(default:true), if paths to each template is relative to settings file
dir(string): Main execution directory
+ cb(function): callback to run when finished
*/
- module.exports.precompile = function(settings, dir) {
+ module.exports.precompile = function(settings, dir, cb) {
extend(globalSettings, settings);
globalSettings.dir = dir;
return async.forEach(settings.groups, function(groupSetting, callback) {
@@ -212,7 +215,12 @@
if (err != null) {
return console.log(err);
} else {
- return console.log("\n\n\n...Done.\n\n");
+ if (cb != null) {
+ cb();
+ }
+ if (this.settings.verbose) {
+ return console.log("\n\n\n...Done.\n\n");
+ }
}
});
};
View
12 src/lib/tmpl-precompile.coffee
@@ -101,7 +101,7 @@ class Precompiler
if output?
fs.writeFileSync @settings.output, buf
- console.log ('Saving ' + (if uglify isnt false then 'and Uglifying ' else '' )).bold + ':' + output
+ console.log ('Saving ' + (if uglify isnt false then 'and Uglifying ' else '' )).bold + ':' + output if @settings.verbose
if @callback? then @callback(null, buf)
@@ -174,9 +174,10 @@ Params:
"verbose": Boolean(default:false), if should output compile info on console
"relative": Boolean(default:true), if paths to each template is relative to settings file
dir(string): Main execution directory
+ cb(function): callback to run when finished
###
-module.exports.precompile = (settings,dir) ->
+module.exports.precompile = (settings,dir,cb) ->
extend(globalSettings, settings)
globalSettings.dir = dir
@@ -185,7 +186,10 @@ module.exports.precompile = (settings,dir) ->
precompiler = new Precompiler(groupSetting, callback)
precompiler.compile()
, (err, res) ->
- if err? then console.log err
- else console.log "\n\n\n...Done.\n\n"
+ if err?
+ console.log err
+ else
+ if cb? then cb()
+ console.log "\n\n\n...Done.\n\n" if @settings.verbose
module.exports.Precompiler = Precompiler
View
2 test/mock/precompiler.mock.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.4.0
(function() {
var async, fs, mockData, path, setupStubs, teardownStubs, tmpl1, tmpl2;
View
2 test/namespace.test.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.4.0
(function() {
var assert, longGroupNamespace, longTemplateAndGroupNames, longTemplateNames, namespace, namespaceTest, noNamespaceError, noTemplatesError, singleNamespace, vows;
View
2 test/precompiler.test.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.4.0
(function() {
var Precompiler, assert, compileDebug, defaultSettings, fs, inlineRuntime, jsp, mockData, noHelpers, noUglify, outputFile, precompilerTest, pro, setup, setupPrecompiler, setupStubs, teardown, teardownStubs, vows, _ref;

3 comments on commit 20e4959

@jescalan

Hey, so I introduced a major bug here, which apparently nobody has noticed yet. It throws a breaking error when the precompile function is used, which for some reason isn't thrown consistently and it wasn't thrown on the computer I was testing on so I missed it. I'm going to PR a fix for this tonight, really sorry if it caused any devious bugs, but I think it was just my fork since it doesn't look like you've shipped yet.

@conancat
Collaborator

Hey man, seems like you've fixed it right? I guess we can close this now. :D

@jescalan

Yep, it's fixed. Do you want me to remove the comment? I can't close this since it's not an issue...

Please sign in to comment.