dev-setup.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (function() {
  2. function parseLoaderOptions() {
  3. function parseQueryString() {
  4. var str = window.location.search;
  5. str = str.replace(/^\?/, '');
  6. var pieces = str.split(/&/);
  7. var result = {};
  8. pieces.forEach(function(piece) {
  9. var config = piece.split(/=/);
  10. result[config[0]] = config[1];
  11. });
  12. return result;
  13. }
  14. var overwrites = parseQueryString();
  15. var result = {};
  16. result['editor'] = overwrites['editor'] || 'npm';
  17. METADATA.PLUGINS.map(function(plugin) {
  18. result[plugin.name] = overwrites[plugin.name] || 'npm';
  19. });
  20. return result;
  21. }
  22. var LOADER_OPTS = parseLoaderOptions();
  23. // console.log(JSON.stringify(LOADER_OPTS, null, '\t'));
  24. self.loadDevEditor = function() {
  25. return (getQueryStringValue('editor') === 'dev');
  26. }
  27. function getQueryStringValue (key) {
  28. return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
  29. }
  30. function resolvePath(paths, selectedPath) {
  31. if (selectedPath === 'npm') {
  32. return '/monaco-editor/' + paths[selectedPath];
  33. } else {
  34. return paths[selectedPath];
  35. }
  36. }
  37. self.RESOLVED_CORE_PATH = resolvePath(METADATA.CORE.paths, LOADER_OPTS['editor']);
  38. var RESOLVED_PLUGINS = METADATA.PLUGINS.map(function(plugin) {
  39. return {
  40. name: plugin.name,
  41. contrib: plugin.contrib,
  42. modulePrefix: plugin.modulePrefix,
  43. path: resolvePath(plugin.paths, LOADER_OPTS[plugin.name])
  44. };
  45. });
  46. self.METADATA = null;
  47. self.loadEditor = function(callback, PATH_PREFIX) {
  48. PATH_PREFIX = PATH_PREFIX || '';
  49. var pathsConfig = {};
  50. RESOLVED_PLUGINS.forEach(function(plugin) {
  51. pathsConfig[plugin.modulePrefix] = PATH_PREFIX + plugin.path;
  52. });
  53. pathsConfig['vs'] = PATH_PREFIX + RESOLVED_CORE_PATH;
  54. var loaderInfo = document.createElement('div');
  55. loaderInfo.style.position = 'fixed';
  56. loaderInfo.style.top = 0;
  57. loaderInfo.style.right = 0;
  58. loaderInfo.innerHTML = 'LOADER PATH CONFIGURATION: ' + '<br/><pre>' + JSON.stringify(pathsConfig, null, '\t') + '</pre>';
  59. document.body.appendChild(loaderInfo);
  60. require.config({
  61. paths: pathsConfig
  62. });
  63. require(['vs/editor/editor.main'], function() {
  64. // At this point we've loaded the monaco-editor-core
  65. require(RESOLVED_PLUGINS.map(function(plugin) { return plugin.contrib; }), function() {
  66. // At this point we've loaded all the plugins
  67. callback();
  68. // require(['./index'], function() {});
  69. });
  70. });
  71. }
  72. })();