mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 12:45:39 +01:00
Improve query parsing
This commit is contained in:
parent
e76aa16381
commit
346cb83091
1 changed files with 31 additions and 15 deletions
|
|
@ -1,5 +1,29 @@
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
function parseLoaderOptions() {
|
||||||
|
function parseQueryString() {
|
||||||
|
var str = window.location.search;
|
||||||
|
str = str.replace(/^\?/, '');
|
||||||
|
var pieces = str.split(/&/);
|
||||||
|
var result = {};
|
||||||
|
pieces.forEach(function(piece) {
|
||||||
|
var config = piece.split(/=/);
|
||||||
|
result[config[0]] = config[1];
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
var overwrites = parseQueryString();
|
||||||
|
var result = {};
|
||||||
|
result['editor'] = overwrites['editor'] || 'npm';
|
||||||
|
METADATA.PLUGINS.map(function(plugin) {
|
||||||
|
result[plugin.name] = overwrites[plugin.name] || 'npm';
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
var LOADER_OPTS = parseLoaderOptions();
|
||||||
|
|
||||||
|
// console.log(JSON.stringify(LOADER_OPTS, null, '\t'));
|
||||||
|
|
||||||
self.loadDevEditor = function() {
|
self.loadDevEditor = function() {
|
||||||
return (getQueryStringValue('editor') === 'dev');
|
return (getQueryStringValue('editor') === 'dev');
|
||||||
}
|
}
|
||||||
|
|
@ -8,29 +32,21 @@
|
||||||
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
|
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveCorePath(core) {
|
|
||||||
if (loadDevEditor()) {
|
|
||||||
return core.paths.dev;
|
|
||||||
} else {
|
|
||||||
return '/monaco-editor/' + core.paths.npm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolvePluginPath(plugin) {
|
function resolvePath(paths, selectedPath) {
|
||||||
if (plugin.paths.dev && getQueryStringValue(plugin.name) === 'dev') {
|
if (selectedPath === 'npm') {
|
||||||
return plugin.paths.dev;
|
return '/monaco-editor/' + paths[selectedPath];
|
||||||
} else {
|
} else {
|
||||||
return '/monaco-editor/' + plugin.paths.npm;
|
return paths[selectedPath];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.RESOLVED_CORE_PATH = resolvePath(METADATA.CORE.paths, LOADER_OPTS['editor']);
|
||||||
self.RESOLVED_CORE_PATH = resolveCorePath(METADATA.CORE);
|
|
||||||
var RESOLVED_PLUGINS = METADATA.PLUGINS.map(function(plugin) {
|
var RESOLVED_PLUGINS = METADATA.PLUGINS.map(function(plugin) {
|
||||||
return {
|
return {
|
||||||
name: plugin.name,
|
name: plugin.name,
|
||||||
contrib: plugin.contrib,
|
contrib: plugin.contrib,
|
||||||
modulePrefix: plugin.modulePrefix,
|
modulePrefix: plugin.modulePrefix,
|
||||||
path: resolvePluginPath(plugin)
|
path: resolvePath(plugin.paths, LOADER_OPTS[plugin.name])
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
self.METADATA = null;
|
self.METADATA = null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue