1
0

dev-setup.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function loadDevEditor() {
  2. return (getQueryStringValue('editor') === 'dev');
  3. }
  4. function getQueryStringValue (key) {
  5. return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
  6. }
  7. (function() {
  8. // Resolve paths
  9. // should run the editor and/or plugins from source? (or from the node module)
  10. if (loadDevEditor()) {
  11. METADATA.CORE.path = METADATA.CORE.srcPath;
  12. } else {
  13. METADATA.CORE.path = '/monaco-editor/' + METADATA.CORE.path;
  14. }
  15. METADATA.PLUGINS.forEach(function(plugin) {
  16. // should run the editor plugins from source? (or from node modules)
  17. if (plugin.srcPath && getQueryStringValue(plugin.name) === 'dev') {
  18. plugin.path = plugin.srcPath;
  19. } else {
  20. plugin.path = '/monaco-editor/' + plugin.path;
  21. }
  22. });
  23. })();
  24. function loadEditor(callback, PATH_PREFIX) {
  25. PATH_PREFIX = PATH_PREFIX || '';
  26. var pathsConfig = {};
  27. METADATA.PLUGINS.forEach(function(plugin) {
  28. pathsConfig[plugin.modulePrefix] = PATH_PREFIX + plugin.path;
  29. });
  30. pathsConfig['vs'] = PATH_PREFIX + METADATA.CORE.path;
  31. // console.log(JSON.stringify(pathsConfig, null, '\t'));
  32. require.config({
  33. paths: pathsConfig
  34. });
  35. require(['vs/editor/editor.main'], function() {
  36. // At this point we've loaded the monaco-editor-core
  37. require(METADATA.PLUGINS.map(function(plugin) { return plugin.contrib; }), function() {
  38. // At this point we've loaded all the plugins
  39. callback();
  40. // require(['./index'], function() {});
  41. });
  42. });
  43. }