1
0
Преглед на файлове

Merge pull request #733 from mkroehnert/cli

Amber CLI: JavaScript cleanup + enhanced error reporting for 'amber serve'
Nicolas Petton преди 11 години
родител
ревизия
0d0b221dfc
променени са 5 файла, в които са добавени 333 реда и са изтрити 370 реда
  1. 145 171
      cli/js/AmberCli.js
  2. 11 4
      cli/st/AmberCli.st
  3. 158 178
      cli/support/amber-cli.js
  4. 7 5
      cli/support/amberc-cli.js
  5. 12 12
      cli/support/amberc.js

Файловите разлики са ограничени, защото са твърде много
+ 145 - 171
cli/js/AmberCli.js


+ 11 - 4
cli/st/AmberCli.st

@@ -169,7 +169,9 @@ username: aUsername
 
 checkDirectoryLayout
 	(fs existsSync: self basePath, 'index.html') ifFalse: [
-		console warn: 'Warning: project directory does not contain index.html'].
+		console warn: 'Warning: project directory does not contain index.html.'.
+		console warn: '    You can specify the directory containing index.html with --base-path.'.].
+		console warn: '    You can also specify a custom error page with --fallback-page.'.
 	(fs existsSync: self basePath, 'st') ifFalse: [
 		console warn: 'Warning: project directory is missing an "st" directory'].
 	(fs existsSync: self basePath, 'js') ifFalse: [
@@ -309,7 +311,7 @@ respondFileNamed: aFilename to: aResponse
 		ex notNil 
 			ifTrue: [
 				console log: filename, ' does not exist'.
-				self respondInternalErrorTo: aResponse]
+				self respondNotFoundTo: aResponse]
 			ifFalse: [
 				type := self class mimeTypeFor: filename.
 				type = 'application/javascript'
@@ -337,8 +339,13 @@ respondNotCreatedTo: aResponse
 respondNotFoundTo: aResponse
 	self fallbackPage isNil ifFalse: [^self respondFileNamed: self fallbackPage to: aResponse].
 	aResponse 
-		writeHead: 404 options: #{'Content-Type' -> 'text/plain'};
-		write: '404 Not found';
+		writeHead: 404 options: #{'Content-Type' -> 'text/html'};
+		write: '<html><body><p>404 Not found</p>';
+		write: '<p>Did you forget to put an index.html file into the directory which is served by "bin/amber serve"? To solve this you can:<ul>';
+		write: '<li>create an index.html in the served directory.</li>';
+		write: '<li>can also specify the location of a page to display instead of this error page with the "--fallback-page" option.</li>';
+		write: '<li>change the directory to be served with the "--base-path" option.</li>';
+		write: '</ul></p></body></html>';
 		end
 !
 

Файловите разлики са ограничени, защото са твърде много
+ 158 - 178
cli/support/amber-cli.js


+ 7 - 5
cli/support/amberc-cli.js

@@ -86,8 +86,8 @@ function handle_options(optionsArray) {
 						// Will end up being the last non js/st argument
 						programName.push(currentItem);
 						break;
-				};
-		};
+				}
+		}
 		currentItem = optionsArray.shift();
 	}
 
@@ -97,7 +97,7 @@ function handle_options(optionsArray) {
 		defaults.program = programName[0];
 	}
 	return defaults;
-};
+}
 
 
 // print available flags
@@ -184,5 +184,7 @@ function print_usage() {
 		'',
 		'        amberc -M main.js myboot.js myKernel.js Cat1.st Cat2.st Program',
 	];
-	usage.forEach(function (line) { console.log(line); });
-};
+	usage.forEach(function (line) {
+        console.log(line);
+	});
+}

+ 12 - 12
cli/support/amberc.js

@@ -2,8 +2,10 @@
  * This is a "compiler" for Amber code.
  * Put the following code into compiler.js:
  *     var amberc = require('amberc');
- *     var compiler = new amberc.Compiler('path/to/amber', ['/optional/path/to/compiler.jar]);
- *     compiler.main();
+ *     var compiler = new amberc.Compiler('path/to/amber');
+ *     var options = amberc.createDefaults();
+ *     // edit options entries
+ *     compiler.main(options);
  *
  * Execute 'node compiler.js' without arguments or with -h / --help for help.
  */
@@ -109,10 +111,10 @@ Combo.prototype = {
 			self.check(id, arguments);
 		};
 	},
-	check: function (id, arguments) {
-		this.results[id] = Array.prototype.slice.call(arguments);
+	check: function (id, theArguments) {
+		this.results[id] = Array.prototype.slice.call(theArguments);
 		this.items--;
-		if (this.items == 0) {
+		if (this.items === 0) {
 			this.callback.apply(this, this.results);
 		}
 	}
@@ -180,7 +182,7 @@ AmberC.prototype.main = function(configuration, finished_callback) {
 		configuration.finished_callback = finished_callback;
 	}
 
-	if (configuration.amd_namespace.length == 0) {
+	if (configuration.amd_namespace.length === 0) {
 		configuration.amd_namespace = 'amber_core';
 	}
 
@@ -210,7 +212,7 @@ AmberC.prototype.check_configuration_ok = function(configuration) {
 		throw new Error('AmberC.check_configuration_ok(): missing configuration object');
 	}
 
-	if (0 === configuration.jsFiles.length && 0 === configuration.stFiles.lenght) {
+	if (0 === configuration.jsFiles.length && 0 === configuration.stFiles.length) {
 		throw new Error('AmberC.check_configuration_ok(): no files to compile/link specified in configuration object');
 	}
 	return true;
@@ -387,7 +389,7 @@ AmberC.prototype.resolve_compiler = function(callback) {
 		});
 		callback(compilerFiles);
 	});
-	var self = this
+	var self = this;
 	compiler_files.forEach(function(file) {
 		self.resolve_js(file, compiler_resolved.add());
 	});
@@ -424,7 +426,7 @@ AmberC.prototype.create_compiler = function(compilerFilesArray) {
 		console.log('Compiler loaded');
 		self.defaults.smalltalk.ErrorHandler._setCurrent_(self.defaults.smalltalk.RethrowErrorHandler._new());
 
-		if(0 != self.defaults.jsGlobals.length) {
+		if(0 !== self.defaults.jsGlobals.length) {
 			var jsGlobalVariables = self.defaults.smalltalk.globalJsVariables;
 			jsGlobalVariables.push.apply(jsGlobalVariables, self.defaults.jsGlobals);
 		}
@@ -444,7 +446,7 @@ AmberC.prototype.create_compiler = function(compilerFilesArray) {
  * Followed by category_export().
  */
 AmberC.prototype.compile = function() {
-	console.log('Compiling collected .st files')
+	console.log('Compiling collected .st files');
 	// import .st files
 	var self = this;
 	var imports = new Combo(function() {
@@ -491,7 +493,6 @@ AmberC.prototype.category_export = function() {
 		jsFile = path.join(jsFilePath, jsFile);
 		defaults.compiled.push(jsFile);
 		var smalltalk = defaults.smalltalk;
-		var pluggableExporter = smalltalk.PluggableExporter;
 		var packageObject = smalltalk.Package._named_(category);
 		packageObject._transport()._namespace_(defaults.amd_namespace);
 		fs.writeFile(jsFile, smalltalk.String._streamContents_(function (stream) {
@@ -535,7 +536,6 @@ AmberC.prototype.verify = function() {
  */
 AmberC.prototype.compose_js_files = function() {
 	var defaults = this.defaults;
-	var self = this;
 	var programFile = defaults.program;
 	if (undefined === programFile) {
 		return;

Някои файлове не бяха показани, защото твърде много файлове са промени