1
0
Эх сурвалжийг харах

Reduce reliance on METADATA

Alex Dima 9 жил өмнө
parent
commit
a7179b0bef

+ 1 - 1
test/cross-origin-broken.html

@@ -14,7 +14,7 @@
 
 <script src="../metadata.js"></script>
 <script src="dev-setup.js"></script>
-<script>document.write('<script src="http://localhost:8088' + METADATA.CORE.path + '/loader.js"><'+'/script>');</script>
+<script>document.write('<script src="http://localhost:8088' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
 <script>
 	loadEditor(function() {
 		monaco.editor.create(document.getElementById('container'), {

+ 1 - 1
test/cross-origin-good.html

@@ -21,7 +21,7 @@
 		}
 	};
 </script>
-<script>document.write('<script src="http://localhost:8088' + METADATA.CORE.path + '/loader.js"><'+'/script>');</script>
+<script>document.write('<script src="http://localhost:8088' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
 <script>
 	loadEditor(function() {
 		monaco.editor.create(document.getElementById('container'), {

+ 49 - 37
test/dev-setup.js

@@ -1,50 +1,62 @@
+(function() {
 
-function loadDevEditor() {
-	return (getQueryStringValue('editor') === 'dev');
-}
+	self.loadDevEditor = function() {
+		return (getQueryStringValue('editor') === 'dev');
+	}
 
-function getQueryStringValue (key) {
-	return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
-}
+	function getQueryStringValue (key) {
+		return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
+	}
 
-(function() {
-	// Resolve paths
-	// should run the editor and/or plugins from source? (or from the node module)
-	if (loadDevEditor()) {
-		METADATA.CORE.path = METADATA.CORE.srcPath;
-	} else {
-		METADATA.CORE.path = '/monaco-editor/' + METADATA.CORE.path;
+	function resolveCorePath(core) {
+		if (loadDevEditor()) {
+			return core.srcPath;
+		} else {
+			return '/monaco-editor/' + core.path;
+		}
 	}
-	METADATA.PLUGINS.forEach(function(plugin) {
-		// should run the editor plugins from source? (or from node modules)
+
+	function resolvePluginPath(plugin) {
 		if (plugin.srcPath && getQueryStringValue(plugin.name) === 'dev') {
-			plugin.path = plugin.srcPath;
+			return plugin.srcPath;
 		} else {
-			plugin.path = '/monaco-editor/' + plugin.path;
+			return '/monaco-editor/' + plugin.path;
 		}
-	});
-})();
+	}
 
-function loadEditor(callback, PATH_PREFIX) {
-	PATH_PREFIX = PATH_PREFIX || '';
-	var pathsConfig = {};
-	METADATA.PLUGINS.forEach(function(plugin) {
-		pathsConfig[plugin.modulePrefix] = PATH_PREFIX + plugin.path;
+	self.RESOLVED_CORE_PATH = resolveCorePath(METADATA.CORE);
+	var RESOLVED_PLUGINS = METADATA.PLUGINS.map(function(plugin) {
+		return {
+			name: plugin.name,
+			contrib: plugin.contrib,
+			modulePrefix: plugin.modulePrefix,
+			path: resolvePluginPath(plugin)
+		};
 	});
-	pathsConfig['vs'] = PATH_PREFIX + METADATA.CORE.path;
+	self.METADATA = null;
 
-	// console.log(JSON.stringify(pathsConfig, null, '\t'));
+	self.loadEditor = function(callback, PATH_PREFIX) {
+		PATH_PREFIX = PATH_PREFIX || '';
+		var pathsConfig = {};
+		RESOLVED_PLUGINS.forEach(function(plugin) {
+			pathsConfig[plugin.modulePrefix] = PATH_PREFIX + plugin.path;
+		});
+		pathsConfig['vs'] = PATH_PREFIX + RESOLVED_CORE_PATH;
 
-	require.config({
-		paths: pathsConfig
-	});
+		console.log('LOADER PATH CONFIGURATION: ');
+		console.log(JSON.stringify(pathsConfig, null, '\t'));
 
-	require(['vs/editor/editor.main'], function() {
-		// At this point we've loaded the monaco-editor-core
-		require(METADATA.PLUGINS.map(function(plugin) { return plugin.contrib; }), function() {
-			// At this point we've loaded all the plugins
-			callback();
-			// require(['./index'], function() {});
+		require.config({
+			paths: pathsConfig
 		});
-	});
-}
+
+		require(['vs/editor/editor.main'], function() {
+			// At this point we've loaded the monaco-editor-core
+			require(RESOLVED_PLUGINS.map(function(plugin) { return plugin.contrib; }), function() {
+				// At this point we've loaded all the plugins
+				callback();
+				// require(['./index'], function() {});
+			});
+		});
+	}
+})();

+ 1 - 1
test/index.html

@@ -34,7 +34,7 @@
 
 <script src="../metadata.js"></script>
 <script src="dev-setup.js"></script>
-<script>document.write('<script src="' + METADATA.CORE.path + '/loader.js"><'+'/script>');</script>
+<script>document.write('<script src="' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
 <script>
 	loadEditor(function() {
 		require(['./index'], function() {});

+ 1 - 1
test/mouse-fixed.html

@@ -12,7 +12,7 @@
 
 <script src="../metadata.js"></script>
 <script src="dev-setup.js"></script>
-<script>document.write('<script src="' + METADATA.CORE.path + '/loader.js"><'+'/script>');</script>
+<script>document.write('<script src="' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
 <script>
 	loadEditor(function() {
 		monaco.editor.create(document.getElementById('Editor'), {

+ 1 - 1
test/mouse-scrollable-body.html

@@ -171,7 +171,7 @@
 
 <script src="../metadata.js"></script>
 <script src="dev-setup.js"></script>
-<script>document.write('<script src="' + METADATA.CORE.path + '/loader.js"><'+'/script>');</script>
+<script>document.write('<script src="' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
 <script>
 	loadEditor(function() {
 		monaco.editor.create(document.getElementById('editor'), {

+ 1 - 1
test/mouse-scrollable-element.html

@@ -123,7 +123,7 @@
 
 <script src="../metadata.js"></script>
 <script src="dev-setup.js"></script>
-<script>document.write('<script src="' + METADATA.CORE.path + '/loader.js"><'+'/script>');</script>
+<script>document.write('<script src="' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
 <script>
 	loadEditor(function() {
 		monaco.editor.create(document.getElementById('editor'), {