plugin_loader.ts 2.6 KB

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