Browse Source

Merge pull request #475 from mkroehnert/compiler

Add verbose flag to amberc
Nicolas Petton 11 years ago
parent
commit
549839bba3
3 changed files with 14 additions and 3 deletions
  1. 3 0
      bin/amberc
  2. 10 3
      bin/amberc.js
  3. 1 0
      grunt/tasks/grunt-amberc.js

+ 3 - 0
bin/amberc

@@ -74,6 +74,9 @@ function handle_options(optionsArray, amber_dir) {
 				defaults.loadsuffix = optionsArray.shift();
 				defaults.suffix_used = defaults.suffix;
 				break;
+			case '-v':
+				defaults.verbose = true;
+				break;
 			case '-h':
 			case '--help':
 			case '?':

+ 10 - 3
bin/amberc.js

@@ -119,6 +119,7 @@ var createDefaults = function(amber_dir, finished_callback){
 		'compiled_categories': [],
 		'compiled': [],
 		'program': undefined,
+		'verbose': false,
 		'finished_callback': finished_callback
 	};
 };
@@ -133,6 +134,11 @@ AmberC.prototype.main = function(configuration, finished_callback) {
 		configuration.finished_callback = finished_callback;
 	}
 
+	console.ambercLog = console.log;
+	if (false === configuration.verbose) {
+		console.log = function() {};
+	}
+
 	if (this.check_configuration_ok(configuration)) {
 		this.defaults = configuration;
 		this.defaults.smalltalk = {}; // the evaluated compiler will be stored in this variable (see create_compiler)
@@ -443,7 +449,7 @@ AmberC.prototype.compile = function() {
 	this.defaults.compile.forEach(function(stFile) {
 		var callback = imports.add();
 		if (/\.st/.test(stFile)) {
-			console.log('Importing: ' + stFile);
+			console.ambercLog('Importing: ' + stFile);
 			fs.readFile(stFile, 'utf8', function(err, data) {
 				if (!err)
 					callback(data);
@@ -532,12 +538,12 @@ AmberC.prototype.compose_js_files = function() {
 		program_files.push(defaults.init);
 	}
 
-	console.log('Writing program file: %s.js', defaults.program);
+	console.ambercLog('Writing program file: %s.js', defaults.program);
 
 	var fileStream = fs.createWriteStream(defaults.program + defaults.suffix_used + '.js');
 	fileStream.on('error', function(error) {
 		fileStream.end();
-		console.log(error);
+		console.ambercLog(error);
 	});
 
 	fileStream.on('close', function(){
@@ -576,6 +582,7 @@ AmberC.prototype.optimize = function() {
 	var defaults = this.defaults;
 	var self = this;
 	var optimization_done = new Combo(function() {
+		console.log = console.ambercLog;
 		console.timeEnd('Compile Time');
 		if (undefined !== defaults.finished_callback) {
 			defaults.finished_callback();

+ 1 - 0
grunt/tasks/grunt-amberc.js

@@ -23,6 +23,7 @@ module.exports = function(grunt) {
          deploy: true,                         // optional
          output_suffix: 'mySuffix',            // optional
          library_suffix: '-0.9',               // optional
+         verbose: true                         // optional
        },
      },