plugin_loader.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 * as datemath from 'app/core/utils/datemath';
  11. import * as graphitePlugin from 'app/plugins/datasource/graphite/module';
  12. import * as cloudwatchPlugin from 'app/plugins/datasource/cloudwatch/module';
  13. import * as elasticsearchPlugin from 'app/plugins/datasource/elasticsearch/module';
  14. import * as opentsdbPlugin from 'app/plugins/datasource/opentsdb/module';
  15. import * as grafanaPlugin from 'app/plugins/datasource/grafana/module';
  16. import * as influxdbPlugin from 'app/plugins/datasource/influxdb/module';
  17. import * as mixedPlugin from 'app/plugins/datasource/mixed/module';
  18. import * as mysqlPlugin from 'app/plugins/datasource/mysql/module';
  19. import * as prometheusPlugin from 'app/plugins/datasource/prometheus/module';
  20. import * as textPanel from 'app/plugins/panel/text/module';
  21. import * as graphPanel from 'app/plugins/panel/graph/module';
  22. import * as dashListPanel from 'app/plugins/panel/dashlist/module';
  23. import * as pluginsListPanel from 'app/plugins/panel/pluginlist/module';
  24. import * as alertListPanel from 'app/plugins/panel/alertlist/module';
  25. import * as heatmapPanel from 'app/plugins/panel/heatmap/module';
  26. import * as tablePanel from 'app/plugins/panel/table/module';
  27. import * as singlestatPanel from 'app/plugins/panel/singlestat/module';
  28. import * as gettingStartedPanel from 'app/plugins/panel/gettingstarted/module';
  29. import * as testDataAppPlugin from 'app/plugins/app/testdata/module';
  30. import * as testDataDSPlugin from 'app/plugins/app/testdata/datasource/module';
  31. let builtInPlugins = {
  32. "app/plugins/datasource/graphite/module": graphitePlugin,
  33. "app/plugins/datasource/cloudwatch/module": cloudwatchPlugin,
  34. "app/plugins/datasource/elasticsearch/module": elasticsearchPlugin,
  35. "app/plugins/datasource/opentsdb/module": opentsdbPlugin,
  36. "app/plugins/datasource/grafana/module": grafanaPlugin,
  37. "app/plugins/datasource/influxdb/module": influxdbPlugin,
  38. "app/plugins/datasource/mixed/module": mixedPlugin,
  39. "app/plugins/datasource/mysql/module": mysqlPlugin,
  40. "app/plugins/datasource/prometheus/module": prometheusPlugin,
  41. "app/plugins/app/testdata/module": testDataAppPlugin,
  42. "app/plugins/app/testdata/datasource/module": testDataDSPlugin,
  43. "app/plugins/panel/text/module": textPanel,
  44. "app/plugins/panel/graph/module": graphPanel,
  45. "app/plugins/panel/dashlist/module": dashListPanel,
  46. "app/plugins/panel/pluginlist/module": pluginsListPanel,
  47. "app/plugins/panel/alertlist/module": alertListPanel,
  48. "app/plugins/panel/heatmap/module": heatmapPanel,
  49. "app/plugins/panel/table/module": tablePanel,
  50. "app/plugins/panel/singlestat/module": singlestatPanel,
  51. "app/plugins/panel/gettingstarted/module": gettingStartedPanel,
  52. };
  53. System.config({
  54. baseURL: 'public',
  55. defaultExtension: 'js',
  56. packages: {
  57. 'plugins': {
  58. defaultExtension: 'js'
  59. }
  60. },
  61. map: {
  62. text: 'vendor/plugin-text/text.js',
  63. css: 'vendor/plugin-css/css.js'
  64. },
  65. });
  66. // add cache busting
  67. var systemLocate = System.locate;
  68. System.cacheBust = '?bust=' + Date.now();
  69. System.locate = function(load) {
  70. var System = this;
  71. return Promise.resolve(systemLocate.call(this, load)).then(function(address) {
  72. return address + System.cacheBust;
  73. });
  74. };
  75. function exposeToPlugin(name: string, component: any) {
  76. System.registerDynamic(name, [], true, function(require, exports, module) {
  77. module.exports = component;
  78. });
  79. }
  80. exposeToPlugin('lodash', _);
  81. exposeToPlugin('moment', moment);
  82. exposeToPlugin('jquery', jquery);
  83. exposeToPlugin('angular', angular);
  84. exposeToPlugin('app/plugins/sdk', sdk);
  85. exposeToPlugin('app/core/utils/datemath', datemath);
  86. exposeToPlugin('app/core/utils/kbn', kbn);
  87. exposeToPlugin('app/core/config', config);
  88. exposeToPlugin('app/core/time_series', TimeSeries);
  89. exposeToPlugin('app/core/time_series2', TimeSeries);
  90. import 'vendor/flot/jquery.flot';
  91. import 'vendor/flot/jquery.flot.selection';
  92. import 'vendor/flot/jquery.flot.time';
  93. import 'vendor/flot/jquery.flot.stack';
  94. import 'vendor/flot/jquery.flot.pie';
  95. import 'vendor/flot/jquery.flot.stackpercent';
  96. import 'vendor/flot/jquery.flot.fillbelow';
  97. import 'vendor/flot/jquery.flot.crosshair';
  98. import 'vendor/flot/jquery.flot.dashes';
  99. for (let flotDep of ['jquery.flot', 'jquery.flot.pie', 'jquery.flot.time']) {
  100. System.registerDynamic(flotDep, [], true, function(require, exports, module) { module.exports = {fakeDep: 1}; });
  101. }
  102. export function importPluginModule(path: string): Promise<any> {
  103. let builtIn = builtInPlugins[path];
  104. if (builtIn) {
  105. return Promise.resolve(builtIn);
  106. }
  107. return System.import(path);
  108. }
  109. export function loadPluginCss(options) {
  110. if (config.bootData.user.lightTheme) {
  111. System.import(options.light + '!css');
  112. } else {
  113. System.import(options.dark + '!css');
  114. }
  115. }