plugin_loader.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 appEvents from 'app/core/app_events';
  12. import {Observable} from 'rxjs/Observable';
  13. import {Subject} from 'rxjs/Subject';
  14. import * as datemath from 'app/core/utils/datemath';
  15. import builtInPlugins from './buit_in_plugins';
  16. System.config({
  17. baseURL: 'public',
  18. defaultExtension: 'js',
  19. packages: {
  20. 'plugins': {
  21. defaultExtension: 'js'
  22. }
  23. },
  24. map: {
  25. text: 'vendor/plugin-text/text.js',
  26. css: 'vendor/plugin-css/css.js'
  27. },
  28. });
  29. // add cache busting
  30. var systemLocate = System.locate;
  31. System.cacheBust = '?bust=' + Date.now();
  32. System.locate = function(load) {
  33. var System = this;
  34. return Promise.resolve(systemLocate.call(this, load)).then(function(address) {
  35. return address + System.cacheBust;
  36. });
  37. };
  38. function exposeToPlugin(name: string, component: any) {
  39. System.registerDynamic(name, [], true, function(require, exports, module) {
  40. module.exports = component;
  41. });
  42. }
  43. exposeToPlugin('lodash', _);
  44. exposeToPlugin('moment', moment);
  45. exposeToPlugin('jquery', jquery);
  46. exposeToPlugin('angular', angular);
  47. exposeToPlugin('rxjs/Subject', Subject);
  48. exposeToPlugin('rxjs/Observable', Observable);
  49. exposeToPlugin('app/plugins/sdk', sdk);
  50. exposeToPlugin('app/core/utils/datemath', datemath);
  51. exposeToPlugin('app/core/utils/kbn', kbn);
  52. exposeToPlugin('app/core/config', config);
  53. exposeToPlugin('app/core/time_series', TimeSeries);
  54. exposeToPlugin('app/core/time_series2', TimeSeries);
  55. exposeToPlugin('app/core/table_model', TableModel);
  56. exposeToPlugin('app/core/app_events', appEvents);
  57. import 'vendor/flot/jquery.flot';
  58. import 'vendor/flot/jquery.flot.selection';
  59. import 'vendor/flot/jquery.flot.time';
  60. import 'vendor/flot/jquery.flot.stack';
  61. import 'vendor/flot/jquery.flot.pie';
  62. import 'vendor/flot/jquery.flot.stackpercent';
  63. import 'vendor/flot/jquery.flot.fillbelow';
  64. import 'vendor/flot/jquery.flot.crosshair';
  65. import 'vendor/flot/jquery.flot.dashes';
  66. for (let flotDep of ['jquery.flot', 'jquery.flot.pie', 'jquery.flot.time']) {
  67. exposeToPlugin(flotDep, {fakeDep: 1});
  68. }
  69. export function importPluginModule(path: string): Promise<any> {
  70. let builtIn = builtInPlugins[path];
  71. if (builtIn) {
  72. return Promise.resolve(builtIn);
  73. }
  74. return System.import(path);
  75. }
  76. export function loadPluginCss(options) {
  77. if (config.bootData.user.lightTheme) {
  78. System.import(options.light + '!css');
  79. } else {
  80. System.import(options.dark + '!css');
  81. }
  82. }