plugin_loader.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import System from 'systemjs/dist/system.js';
  2. import _ from 'lodash';
  3. import * as sdk from 'app/plugins/sdk';
  4. import kbn from 'app/core/utils/kbn';
  5. import moment from 'moment';
  6. import angular from 'angular';
  7. import jquery from 'jquery';
  8. import config from 'app/core/config';
  9. import TimeSeries from 'app/core/time_series2';
  10. import TableModel from 'app/core/table_model';
  11. import {coreModule, appEvents, contextSrv} from 'app/core/core';
  12. import {Observable} from 'rxjs/Observable';
  13. import {Subject} from 'rxjs/Subject';
  14. import * as datemath from 'app/core/utils/datemath';
  15. import * as fileExport from 'app/core/utils/file_export';
  16. import * as flatten from 'app/core/utils/flatten';
  17. import * as ticks from 'app/core/utils/ticks';
  18. import builtInPlugins from './buit_in_plugins';
  19. import d3 from 'vendor/d3/d3';
  20. System.config({
  21. baseURL: 'public',
  22. defaultExtension: 'js',
  23. packages: {
  24. 'plugins': {
  25. defaultExtension: 'js'
  26. }
  27. },
  28. map: {
  29. text: 'vendor/plugin-text/text.js',
  30. css: 'vendor/plugin-css/css.js'
  31. },
  32. });
  33. // add cache busting
  34. var systemLocate = System.locate;
  35. System.cacheBust = '?bust=' + Date.now();
  36. System.locate = function(load) {
  37. var System = this;
  38. return Promise.resolve(systemLocate.call(this, load)).then(function(address) {
  39. return address + System.cacheBust;
  40. });
  41. };
  42. function exposeToPlugin(name: string, component: any) {
  43. System.registerDynamic(name, [], true, function(require, exports, module) {
  44. module.exports = component;
  45. });
  46. }
  47. exposeToPlugin('lodash', _);
  48. exposeToPlugin('moment', moment);
  49. exposeToPlugin('jquery', jquery);
  50. exposeToPlugin('angular', angular);
  51. exposeToPlugin('rxjs/Subject', Subject);
  52. exposeToPlugin('rxjs/Observable', Observable);
  53. exposeToPlugin('d3', d3);
  54. exposeToPlugin('app/plugins/sdk', sdk);
  55. exposeToPlugin('app/core/utils/datemath', datemath);
  56. exposeToPlugin('app/core/utils/file_export', fileExport);
  57. exposeToPlugin('app/core/utils/flatten', flatten);
  58. exposeToPlugin('app/core/utils/kbn', kbn);
  59. exposeToPlugin('app/core/utils/ticks', ticks);
  60. exposeToPlugin('app/core/config', config);
  61. exposeToPlugin('app/core/time_series', TimeSeries);
  62. exposeToPlugin('app/core/time_series2', TimeSeries);
  63. exposeToPlugin('app/core/table_model', TableModel);
  64. exposeToPlugin('app/core/app_events', appEvents);
  65. exposeToPlugin('app/core/core_module', coreModule);
  66. exposeToPlugin('app/core/core', {
  67. coreModule: coreModule,
  68. appEvents: appEvents,
  69. contextSrv: contextSrv,
  70. __esModule: true
  71. });
  72. import 'vendor/flot/jquery.flot';
  73. import 'vendor/flot/jquery.flot.selection';
  74. import 'vendor/flot/jquery.flot.time';
  75. import 'vendor/flot/jquery.flot.stack';
  76. import 'vendor/flot/jquery.flot.pie';
  77. import 'vendor/flot/jquery.flot.stackpercent';
  78. import 'vendor/flot/jquery.flot.fillbelow';
  79. import 'vendor/flot/jquery.flot.crosshair';
  80. import 'vendor/flot/jquery.flot.dashes';
  81. const flotDeps = [
  82. 'jquery.flot', 'jquery.flot.pie', 'jquery.flot.time', 'jquery.flot.fillbelow', 'jquery.flot.crosshair',
  83. 'jquery.flot.stack', 'jquery.flot.selection', 'jquery.flot.stackpercent', 'jquery.flot.events'
  84. ];
  85. for (let flotDep of flotDeps) {
  86. exposeToPlugin(flotDep, {fakeDep: 1});
  87. }
  88. export function importPluginModule(path: string): Promise<any> {
  89. let builtIn = builtInPlugins[path];
  90. if (builtIn) {
  91. return Promise.resolve(builtIn);
  92. }
  93. return System.import(path);
  94. }
  95. export function loadPluginCss(options) {
  96. if (config.bootData.user.lightTheme) {
  97. System.import(options.light + '!css');
  98. } else {
  99. System.import(options.dark + '!css');
  100. }
  101. }