Skip to content

Commit

Permalink
Added functionality to use plugins defined in settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Nov 5, 2019
1 parent f909ac2 commit 0a56d3e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
{{ 'SCHEMA_FORM_LIST_ADD' | translate }}
</button>
</nz-form-control>
</nz-form-item>
</nz-form-item>
10 changes: 9 additions & 1 deletion src/app/containers/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,15 @@ export class AppComponent implements OnDestroy {
)
.subscribe(data => {
if (data.settings.enableExperimental) {
this.pluginRegistry.getPlugin('altair-graphql-plugin-graphql-explorer', { version: '0.0.6' });
if (data.settings['plugin.list']) {
data.settings['plugin.list'].forEach(pluginStr => {
const pluginInfo = this.pluginRegistry.getPluginInfoFromString(pluginStr);
if (pluginInfo) {
this.pluginRegistry.getPlugin(pluginInfo.name, { version: pluginInfo.version });
}
});
}
// this.pluginRegistry.getPlugin('altair-graphql-plugin-graphql-explorer', { version: '0.0.6' });
// this.pluginRegistry.getPlugin('altair-graphql-plugin-graphql-explorer', {
// pluginSource: 'url',
// version: '0.0.4',
Expand Down
24 changes: 23 additions & 1 deletion src/app/services/plugin/plugin-registry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class PluginRegistryService {
}

getPlugin(name: string, { pluginSource = PluginSource.NPM, version = 'latest', ...remainingOpts }: any = {}) {
debug.log('PLUGIN: ', name, pluginSource);
debug.log('PLUGIN: ', name, pluginSource, version);
if (!name || this.registry[name]) {
return;
}
let pluginBaseUrl = ``;
switch (pluginSource) {
case PluginSource.NPM:
Expand Down Expand Up @@ -89,6 +92,25 @@ export class PluginRegistryService {
// Returns context based on type of plugin.
}

/**
* Given a plugin string in the format: <plugin-name>@<version>,
* it returns the details of the plugin
* @param pluginStr
*/
getPluginInfoFromString(pluginStr: string) {
const matches = pluginStr.match(/(.[^@]*)(@(.*))?/);
if (matches && matches.length) {
const [, pluginName, , pluginVersion = 'latest'] = matches;
if (pluginName && pluginVersion) {
return {
name: pluginName,
version: pluginVersion,
};
}
}
return null;
}

private emitRegistryUpdate() {
this.pluginRegistrySubject$.next(this.registry);
}
Expand Down

0 comments on commit 0a56d3e

Please sign in to comment.