Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #11 from jenius/master

Add callback to precompile function, make sure console.log only happens when verbose
  • Loading branch information...
commit 20e49594858a141e8388f1772c66d24de8ef4b73 2 parents 4de1363 + 83a783e
Tauren Mills authored
4 bin/tmpl-precompile
... ... @@ -1,5 +1,7 @@
  1 +// Generated by CoffeeScript 1.4.0
1 2 #!/usr/bin/env node
2 3 ;
  4 +
3 5 var colors, cwd, fs, jsondir, jsonfile, match, precompile, settings;
4 6
5 7 jsonfile = process.argv[2] || 'tmpl-precompile.json';
@@ -28,7 +30,7 @@ if (settings !== {}) {
28 30 }
29 31 if (jsonfile.indexOf('/' > 0)) {
30 32 match = jsonfile.split(/\//);
31   - jsondir = match.slice(0, (match.length - 1)).join('/');
  33 + jsondir = match.slice(0, match.length - 1).join('/');
32 34 cwd += '/' + jsondir;
33 35 }
34 36 console.log('\n\n' + 'tmpl-precompile'.bold.underline + '\n');
4 bin/tmpl-precompile.js
... ... @@ -1,5 +1,7 @@
  1 +// Generated by CoffeeScript 1.4.0
1 2 #!/usr/bin/env node
2 3 ;
  4 +
3 5 var colors, cwd, fs, jsondir, jsonfile, match, precompile, settings;
4 6
5 7 jsonfile = process.argv[2] || 'tmpl-precompile.json';
@@ -28,7 +30,7 @@ if (settings !== {}) {
28 30 }
29 31 if (jsonfile.indexOf('/' > 0)) {
30 32 match = jsonfile.split(/\//);
31   - jsondir = match.slice(0, (match.length - 1)).join('/');
  33 + jsondir = match.slice(0, match.length - 1).join('/');
32 34 cwd += '/' + jsondir;
33 35 }
34 36 console.log('\n\n' + 'tmpl-precompile'.bold.underline + '\n');
2  index.js
... ... @@ -1,4 +1,4 @@
1   -// Generated by CoffeeScript 1.3.3
  1 +// Generated by CoffeeScript 1.4.0
2 2 (function() {
3 3
4 4 module.exports = require('./lib/tmpl-precompile');
2  lib/helpers.js
... ... @@ -1,4 +1,4 @@
1   -// Generated by CoffeeScript 1.3.3
  1 +// Generated by CoffeeScript 1.4.0
2 2
3 3 /*
4 4 extend(main, sub)
2  lib/namespace.js
... ... @@ -1,4 +1,4 @@
1   -// Generated by CoffeeScript 1.3.3
  1 +// Generated by CoffeeScript 1.4.0
2 2 (function() {
3 3 var Namespacer, async;
4 4
2  lib/optimize.js
... ... @@ -1,4 +1,4 @@
1   -// Generated by CoffeeScript 1.3.3
  1 +// Generated by CoffeeScript 1.4.0
2 2 (function() {
3 3 var extractFunction, jsp, optimizeOutput;
4 4
16 lib/tmpl-precompile.js
... ... @@ -1,4 +1,4 @@
1   -// Generated by CoffeeScript 1.3.3
  1 +// Generated by CoffeeScript 1.4.0
2 2 (function() {
3 3 var Namespacer, Precompiler, async, colors, extend, extractFunction, fs, globalSettings, jade, jsp, optimizeOutput, path, pro, util, version, _ref;
4 4
@@ -121,7 +121,9 @@
121 121 }
122 122 if (output != null) {
123 123 fs.writeFileSync(this.settings.output, buf);
124   - console.log(('Saving ' + (uglify !== false ? 'and Uglifying ' : '')).bold + ':' + output);
  124 + if (this.settings.verbose) {
  125 + console.log(('Saving ' + (uglify !== false ? 'and Uglifying ' : '')).bold + ':' + output);
  126 + }
125 127 }
126 128 if (this.callback != null) {
127 129 return this.callback(null, buf);
@@ -198,10 +200,11 @@
198 200 "verbose": Boolean(default:false), if should output compile info on console
199 201 "relative": Boolean(default:true), if paths to each template is relative to settings file
200 202 dir(string): Main execution directory
  203 + cb(function): callback to run when finished
201 204 */
202 205
203 206
204   - module.exports.precompile = function(settings, dir) {
  207 + module.exports.precompile = function(settings, dir, cb) {
205 208 extend(globalSettings, settings);
206 209 globalSettings.dir = dir;
207 210 return async.forEach(settings.groups, function(groupSetting, callback) {
@@ -212,7 +215,12 @@
212 215 if (err != null) {
213 216 return console.log(err);
214 217 } else {
215   - return console.log("\n\n\n...Done.\n\n");
  218 + if (cb != null) {
  219 + cb();
  220 + }
  221 + if (this.settings.verbose) {
  222 + return console.log("\n\n\n...Done.\n\n");
  223 + }
216 224 }
217 225 });
218 226 };
12 src/lib/tmpl-precompile.coffee
@@ -101,7 +101,7 @@ class Precompiler
101 101
102 102 if output?
103 103 fs.writeFileSync @settings.output, buf
104   - console.log ('Saving ' + (if uglify isnt false then 'and Uglifying ' else '' )).bold + ':' + output
  104 + console.log ('Saving ' + (if uglify isnt false then 'and Uglifying ' else '' )).bold + ':' + output if @settings.verbose
105 105
106 106 if @callback? then @callback(null, buf)
107 107
@@ -174,9 +174,10 @@ Params:
174 174 "verbose": Boolean(default:false), if should output compile info on console
175 175 "relative": Boolean(default:true), if paths to each template is relative to settings file
176 176 dir(string): Main execution directory
  177 + cb(function): callback to run when finished
177 178 ###
178 179
179   -module.exports.precompile = (settings,dir) ->
  180 +module.exports.precompile = (settings,dir,cb) ->
180 181 extend(globalSettings, settings)
181 182 globalSettings.dir = dir
182 183
@@ -185,7 +186,10 @@ module.exports.precompile = (settings,dir) ->
185 186 precompiler = new Precompiler(groupSetting, callback)
186 187 precompiler.compile()
187 188 , (err, res) ->
188   - if err? then console.log err
189   - else console.log "\n\n\n...Done.\n\n"
  189 + if err?
  190 + console.log err
  191 + else
  192 + if cb? then cb()
  193 + console.log "\n\n\n...Done.\n\n" if @settings.verbose
190 194
191 195 module.exports.Precompiler = Precompiler
2  test/mock/precompiler.mock.js
... ... @@ -1,4 +1,4 @@
1   -// Generated by CoffeeScript 1.3.3
  1 +// Generated by CoffeeScript 1.4.0
2 2 (function() {
3 3 var async, fs, mockData, path, setupStubs, teardownStubs, tmpl1, tmpl2;
4 4
2  test/namespace.test.js
... ... @@ -1,4 +1,4 @@
1   -// Generated by CoffeeScript 1.3.3
  1 +// Generated by CoffeeScript 1.4.0
2 2 (function() {
3 3 var assert, longGroupNamespace, longTemplateAndGroupNames, longTemplateNames, namespace, namespaceTest, noNamespaceError, noTemplatesError, singleNamespace, vows;
4 4
2  test/precompiler.test.js
... ... @@ -1,4 +1,4 @@
1   -// Generated by CoffeeScript 1.3.3
  1 +// Generated by CoffeeScript 1.4.0
2 2 (function() {
3 3 var Precompiler, assert, compileDebug, defaultSettings, fs, inlineRuntime, jsp, mockData, noHelpers, noUglify, outputFile, precompilerTest, pro, setup, setupPrecompiler, setupStubs, teardown, teardownStubs, vows, _ref;
4 4

3 comments on commit 20e4959

Jeff Escalante

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.

Grey
Collaborator

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

Jeff Escalante

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.
Something went wrong with that request. Please try again.