grafana/public/app/features/plugins/plugin_loader.ts

162 lines
4.5 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import System from 'systemjs/dist/system.js';
import _ from 'lodash';
import * as sdk from 'app/plugins/sdk';
import kbn from 'app/core/utils/kbn';
import moment from 'moment';
import angular from 'angular';
import jquery from 'jquery';
// Experimental module exports
import prismjs from 'prismjs';
import slate from 'slate';
import slateReact from 'slate-react';
import slatePlain from 'slate-plain-serializer';
import react from 'react';
import reactDom from 'react-dom';
2017-12-20 05:33:33 -06:00
import config from 'app/core/config';
import TimeSeries from 'app/core/time_series2';
import TableModel from 'app/core/table_model';
import { coreModule, appEvents, contextSrv } from 'app/core/core';
import * as datemath from 'app/core/utils/datemath';
import * as fileExport from 'app/core/utils/file_export';
import * as flatten from 'app/core/utils/flatten';
import * as ticks from 'app/core/utils/ticks';
import impressionSrv from 'app/core/services/impression_srv';
import builtInPlugins from './built_in_plugins';
import * as d3 from 'd3';
// rxjs
2017-12-20 05:33:33 -06:00
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
// these imports add functions to Observable
2017-12-20 05:33:33 -06:00
import 'rxjs/add/observable/empty';
import 'rxjs/add/observable/from';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/combineAll';
// add cache busting
const bust = `?_cache=${Date.now()}`;
function locate(load) {
return load.address + bust;
}
System.registry.set('plugin-loader', System.newModule({ locate: locate }));
System.config({
2017-12-20 05:33:33 -06:00
baseURL: 'public',
defaultExtension: 'js',
packages: {
plugins: {
2017-12-20 05:33:33 -06:00
defaultExtension: 'js',
},
},
map: {
2017-12-20 05:33:33 -06:00
text: 'vendor/plugin-text/text.js',
css: 'vendor/plugin-css/css.js',
},
meta: {
'/*': {
esModule: true,
2017-12-20 05:33:33 -06:00
authorization: true,
loader: 'plugin-loader',
2017-12-20 05:33:33 -06:00
},
},
});
function exposeToPlugin(name: string, component: any) {
System.registerDynamic(name, [], true, function(require, exports, module) {
module.exports = component;
});
}
2017-12-20 05:33:33 -06:00
exposeToPlugin('lodash', _);
exposeToPlugin('moment', moment);
exposeToPlugin('jquery', jquery);
exposeToPlugin('angular', angular);
exposeToPlugin('d3', d3);
exposeToPlugin('rxjs/Subject', Subject);
exposeToPlugin('rxjs/Observable', Observable);
// Experimental modules
exposeToPlugin('prismjs', prismjs);
exposeToPlugin('slate', slate);
exposeToPlugin('slate-react', slateReact);
exposeToPlugin('slate-plain-serializer', slatePlain);
exposeToPlugin('react', react);
exposeToPlugin('react-dom', reactDom);
// backward compatible path
2017-12-20 05:33:33 -06:00
exposeToPlugin('vendor/npm/rxjs/Rx', {
Subject: Subject,
2017-12-20 05:33:33 -06:00
Observable: Observable,
});
2017-10-03 04:02:40 -05:00
2017-12-20 05:33:33 -06:00
exposeToPlugin('app/features/dashboard/impression_store', {
2017-11-24 09:18:56 -06:00
impressions: impressionSrv,
2017-12-20 05:33:33 -06:00
__esModule: true,
});
2017-12-20 05:33:33 -06:00
exposeToPlugin('app/plugins/sdk', sdk);
exposeToPlugin('app/core/utils/datemath', datemath);
exposeToPlugin('app/core/utils/file_export', fileExport);
exposeToPlugin('app/core/utils/flatten', flatten);
exposeToPlugin('app/core/utils/kbn', kbn);
exposeToPlugin('app/core/utils/ticks', ticks);
2017-12-20 05:33:33 -06:00
exposeToPlugin('app/core/config', config);
exposeToPlugin('app/core/time_series', TimeSeries);
exposeToPlugin('app/core/time_series2', TimeSeries);
exposeToPlugin('app/core/table_model', TableModel);
exposeToPlugin('app/core/app_events', appEvents);
exposeToPlugin('app/core/core_module', coreModule);
exposeToPlugin('app/core/core', {
coreModule: coreModule,
appEvents: appEvents,
contextSrv: contextSrv,
2017-12-20 05:33:33 -06:00
__esModule: true,
});
2017-12-20 05:33:33 -06:00
import 'vendor/flot/jquery.flot';
import 'vendor/flot/jquery.flot.selection';
import 'vendor/flot/jquery.flot.time';
import 'vendor/flot/jquery.flot.stack';
import 'vendor/flot/jquery.flot.pie';
import 'vendor/flot/jquery.flot.stackpercent';
import 'vendor/flot/jquery.flot.fillbelow';
import 'vendor/flot/jquery.flot.crosshair';
import 'vendor/flot/jquery.flot.dashes';
2018-07-18 05:05:45 -05:00
import 'vendor/flot/jquery.flot.gauge';
const flotDeps = [
2017-12-20 05:33:33 -06:00
'jquery.flot',
'jquery.flot.pie',
'jquery.flot.time',
'jquery.flot.fillbelow',
'jquery.flot.crosshair',
'jquery.flot.stack',
'jquery.flot.selection',
'jquery.flot.stackpercent',
'jquery.flot.events',
2018-07-18 05:05:45 -05:00
'jquery.flot.gauge',
];
for (let flotDep of flotDeps) {
exposeToPlugin(flotDep, { fakeDep: 1 });
}
export function importPluginModule(path: string): Promise<any> {
let builtIn = builtInPlugins[path];
if (builtIn) {
return Promise.resolve(builtIn);
}
return System.import(path);
}
export function loadPluginCss(options) {
if (config.bootData.user.lightTheme) {
2017-12-20 05:33:33 -06:00
System.import(options.light + '!css');
} else {
2017-12-20 05:33:33 -06:00
System.import(options.dark + '!css');
}
}