Quellcode durchsuchen

Merge remote-tracking branch 'upstream/requirejs' into requirejs-with-folder-restructure

Herbert Vojčík vor 10 Jahren
Ursprung
Commit
579c75c31b
4 geänderte Dateien mit 27 neuen und 41 gelöschten Zeilen
  1. 7 6
      bin/amberc
  2. 9 24
      bin/amberc.js
  3. 10 10
      grunt/tasks/grunt-amberc.js
  4. 1 1
      package.json

+ 7 - 6
bin/amberc

@@ -44,15 +44,15 @@ function handle_options(optionsArray, amber_dir) {
 			case '-g':
 				defaults.jsGlobals.push.apply(defaults.jsGlobals, optionsArray.shift().split(','));
 				break;
-			case '-i':
-				defaults.init = optionsArray.shift();
-				break;
 			case '-m':
 				defaults.main = optionsArray.shift();
 				break;
 			case '-M':
 				defaults.mainfile = optionsArray.shift();
 				break;
+			case '-n':
+				defaults.amd_namespace = optionsArray.shift();
+				break;
 			case '-o':
 				defaults.closure = true;
 				defaults.closure_parts = true;
@@ -146,15 +146,16 @@ function print_usage() {
 	console.log('     Comma separated list of JS global variable names.');
 	console.log('     The names are added to a list containing "window", "document" and others.');
 	console.log('');
-	console.log('  -i init_file');
-	console.log('     Add library initializer <init_file> instead of default $AMBER/js/init.js ');
-	console.log('');
 	console.log('  -m main_class');
 	console.log('     Add a call to the class method main_class>>main at the end of <Program>.');
 	console.log('');
 	console.log('  -M main_file');
 	console.log('     Add <main_file> at the end of <Program.js> acting as #main.');
 	console.log('');
+	console.log('  -n amd_namespace');
+	console.log('     Export packages with <amd_namespace> as the require.js namespace.');
+	console.log('     Default value is "amber".');
+	console.log('');
 	console.log('  -o');
 	console.log('     Optimize each .js file using the Google closure compiler.');
 	console.log('     Using Closure compiler found at ~/compiler.jar');

+ 9 - 24
bin/amberc.js

@@ -57,27 +57,6 @@ function always_resolve(callback) {
  * // which can either be stored in a file or interpreted with eval().
  */
 function createConcatenator () {
-	var defineAmdDefine = function () {
-		var path = require('path');
-		return ($AMDEFINE_SRC$)();
-	};
-
-	// The createAmdefineString is hack to help injecting amdefine into the concatenated output.
-	//
-	// Usually, the line 'var define = require('amdefine')(module), requirejs = define.require;'
-	// is needed when using amdefine with node and npm installed.
-	// var f = require('amdefine') itself returns one big self-sufficient function which must be called
-	// as f(module) to get the define you can use.
-	//
-	// However, amdefine needs the definition of the 'path' variable (node's internal 'path' module).
-	// To create this dependency the defineAmdDefine() function is used which defines
-	// the path variable first and adds a placeholder for the amdefine function/sourcecode.
-	// The defineAmdDefine() function is then converted to its string representation
-	// and the placeholder is replaced with the actual sourcecode of the amdefine function.
-	var createAmdefineString = function() {
-		return ('' + defineAmdDefine).replace('$AMDEFINE_SRC$', '' + require('amdefine'));
-	}
-
 	return {
 		elements: [],
 		ids: [],
@@ -92,7 +71,7 @@ function createConcatenator () {
 		},
 		start: function () {
 			this.add(
-				'var define = (' + createAmdefineString() + ')(), requirejs = define.require;',
+				'var define = (' + require('amdefine') + ')(), requirejs = define.require;',
 				'define("amber_vm/browser-compatibility", [], {});'
 			);
 		},
@@ -101,7 +80,8 @@ function createConcatenator () {
 				'define("amber_vm/_init", ["amber_vm/smalltalk","' + this.ids.join('","') + '"], function (smalltalk) {',
 				'smalltalk.initialize();',
 				realWork,
-				'});', 'requirejs("amber_vm/_init");'
+				'});',
+				'requirejs("amber_vm/_init");'
 			);
 		},
 		toString: function () {
@@ -174,6 +154,7 @@ var createDefaults = function(amber_dir, finished_callback){
 		'stFiles': [],
 		'jsFiles': [],
 		'jsGlobals': [],
+		'amd_namespace': 'amber',
 		'closure': false,
 		'closure_parts': false,
 		'closure_full': false,
@@ -209,6 +190,10 @@ AmberC.prototype.main = function(configuration, finished_callback) {
 		configuration.deploy = true;
 	}
 
+	if (configuration.amd_namespace.length == 0) {
+		configuration.amd_namespace = 'amber';
+	}
+
 	console.ambercLog = console.log;
 	if (false === configuration.verbose) {
 		console.log = function() {};
@@ -559,7 +544,7 @@ AmberC.prototype.category_export = function() {
 		var smalltalk = defaults.smalltalk;
 		var pluggableExporter = smalltalk.PluggableExporter;
 		var packageObject = smalltalk.Package._named_(category);
-        packageObject._amdNamespace_("amber");
+		packageObject._amdNamespace_(defaults.amd_namespace);
 		fs.writeFile(jsFile, smalltalk.String._streamContents_(function (stream) {
 			pluggableExporter._newUsing_(smalltalk.Exporter._amdRecipe())._exportPackage_on_(packageObject, stream); }), function(err) {
 			if (defaults.deploy) {

+ 10 - 10
grunt/tasks/grunt-amberc.js

@@ -18,12 +18,12 @@ module.exports = function(grunt) {
          libraries: 'Canvas',                   // optional
          jsGlobals: ['global1', 'global2'],     // optional
          main_class: 'HelloWorld',              // optional
-         output_name: 'helloWorld',            // optional
-         init: 'myInit',                       // optional
-         main_file: 'myMain.js',               // optional
-         deploy: true,                         // optional
-         output_suffix: 'mySuffix',            // optional
-         library_suffix: '-0.9'                // optional
+         output_name: 'helloWorld',             // optional
+         amd_namespace: 'MyNamespace',          // optional (default: 'amber')
+         main_file: 'myMain.js',                // optional
+         deploy: true,                          // optional
+         output_suffix: 'mySuffix',             // optional
+         library_suffix: '-0.9'                 // optional
        },
      },
 
@@ -66,10 +66,6 @@ module.exports = function(grunt) {
     if (undefined !== libraries) {
       configuration.load = libraries;
     }
-    var initFile = data.init;
-    if (undefined !== initFile) {
-      configuration.init = initFile;
-    }
     var mainClass = data.main_class;
     if (undefined !== mainClass) {
       configuration.main = mainClass;
@@ -109,6 +105,10 @@ module.exports = function(grunt) {
     if (undefined !== outputName) {
       configuration.program = outputName;
     }
+    var amdNamespace = data.amd_namespace;
+    if (undefined !== amdNamespace) {
+      configuration.amd_namespace = amdNamespace;
+    }
     if (undefined !== data.output_dir) {
       configuration.output_dir = data.output_dir;
     }

+ 1 - 1
package.json

@@ -39,6 +39,6 @@
     "grunt-contrib-jshint": "~0.3.0",
     "grunt-image-embed": "~0.1.3",
     "grunt-contrib-mincss": "~0.3.2",
-    "amdefine": "0.0.6"
+    "amdefine": "0.0.8"
   }
 }