Skip to content

Commit

Permalink
Move getPluginDir into Env
Browse files Browse the repository at this point in the history
  • Loading branch information
kimjoar committed Aug 30, 2017
1 parent 145ffb0 commit 1a8441c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
4 changes: 4 additions & 0 deletions platform/config/Env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class Env {
: this.argv.config;
}

getPluginDir(pluginName: string) {
return resolve(this.pluginsDir, pluginName, 'target', 'dist')
}

private getDefaultConfigFile() {
return resolve(this.configDir, 'kibana.yml');
}
Expand Down
2 changes: 1 addition & 1 deletion platform/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Server {
};

this.plugins = new PluginsService(
configService.env.pluginsDir,
configService.env,
new PluginSystem(core, logger),
configService,
logger
Expand Down
8 changes: 4 additions & 4 deletions platform/server/plugins/PluginsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { Plugin } from './Plugin';
import { PluginSystem } from './PluginSystem';
import { Logger, LoggerFactory } from '../../logging';
import { CoreService } from '../../types';
import { ConfigService } from '../../config';
import { ConfigService, Env } from '../../config';

const readDirAsObservable = Observable.bindNodeCallback(readdir);

export class PluginsService implements CoreService {
private readonly log: Logger;

constructor(
private readonly pluginsDir: string,
private readonly env: Env,
private readonly pluginSystem: PluginSystem,
private readonly configService: ConfigService,
private readonly logger: LoggerFactory
Expand Down Expand Up @@ -54,10 +54,10 @@ export class PluginsService implements CoreService {
* of plugins.
*/
private readPlugins() {
return readDirAsObservable(this.pluginsDir)
return readDirAsObservable(this.env.pluginsDir)
.mergeMap(dirs => dirs)
.map(name => {
const pluginPath = `${this.pluginsDir}/${name}/target/dist/`;
const pluginPath = this.env.getPluginDir(name);
const json = require(pluginPath);

if (!('plugin' in json)) {
Expand Down
11 changes: 6 additions & 5 deletions platform/server/plugins/__tests__/PluginsService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import { resolve } from 'path';
import { PluginsService } from '../PluginsService';
import { logger } from '../../../logging/__mocks__';

const examplesPluginsDir = resolve(__dirname, './examplePlugins');

let mockConfigService: any = jest.genMockFromModule(
'../../../config/ConfigService'
);
let mockPluginSystem: any = jest.genMockFromModule('../PluginSystem');
let env: any = jest.genMockFromModule('../../../config/Env');

beforeEach(() => {
mockPluginSystem = {
Expand All @@ -27,11 +26,13 @@ beforeEach(() => {
};

mockConfigService.isEnabledAtPath = jest.fn(() => Promise.resolve(true));

env.getPluginDir = jest.fn(name => resolve(__dirname, 'examplePlugins', name));
});

test('starts plugins', async () => {
const pluginsService = new PluginsService(
examplesPluginsDir,
env,
mockPluginSystem,
mockConfigService,
logger
Expand All @@ -53,7 +54,7 @@ test('starts plugins', async () => {

test('stops plugins', async () => {
const pluginsService = new PluginsService(
examplesPluginsDir,
env,
mockPluginSystem,
mockConfigService,
logger
Expand All @@ -74,7 +75,7 @@ test('does not start plugin if disabled', async () => {
});

const pluginsService = new PluginsService(
examplesPluginsDir,
env,
mockPluginSystem,
mockConfigService,
logger
Expand Down
5 changes: 4 additions & 1 deletion src/jest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es6"
}
},
"include": [
"../../platform/**/*"
]
}

0 comments on commit 1a8441c

Please sign in to comment.