plugin_loader.ts 3.0 KB

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