Skip to content

Commit

Permalink
Added extra option and value in getPluginInfoFromString.
Browse files Browse the repository at this point in the history
Closes #1217.
  • Loading branch information
imolorhe committed May 2, 2020
1 parent 7487bb8 commit 53ff5ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -68,6 +68,22 @@ describe('PluginRegistryService', () => {
});
});

it('return extra option if specified', () => {
const service: PluginRegistryService = TestBed.get(PluginRegistryService);
expect(service.getPluginInfoFromString('altair-graphql-plugin-plugin-name@0.0.1::[opt]->[1]')).toEqual({
name: 'altair-graphql-plugin-plugin-name',
version: '0.0.1',
pluginSource: PluginSource.NPM,
opt: '1',
} as any);
expect(service.getPluginInfoFromString('url:altair-graphql-plugin-plugin-name@0.0.1::[url]->[http://localhost:8080]')).toEqual({
name: 'altair-graphql-plugin-plugin-name',
version: '0.0.1',
pluginSource: PluginSource.URL,
url: 'http://localhost:8080',
} as any);
});

it('return specified values', () => {
const service: PluginRegistryService = TestBed.get(PluginRegistryService);
expect(service.getPluginInfoFromString('url:altair-graphql-plugin-plugin-name@0.1.1')).toEqual({
Expand Down
Expand Up @@ -103,14 +103,14 @@ export class PluginRegistryService {
}

/**
* Given a plugin string in the format: <plugin-source>:<plugin-name>@<version>,
* Given a plugin string in the format: <plugin-source>:<plugin-name>@<version>::[<opt>]->[<opt-value>],
* it returns the details of the plugin
* @param pluginStr
*/
getPluginInfoFromString(pluginStr: string) {
const matches = pluginStr.match(/((.*)\:)?(.[^@]*)(@(.*))?/);
const matches = pluginStr.match(/(([A-Za-z_]*)\:)?(.[A-Za-z0-9\-]*)(@([^#\:\[\]]*))?(\:\:\[(.*)\]->\[(.*)\])?/);
if (matches && matches.length) {
const [, , pluginSource = PluginSource.NPM, pluginName, , pluginVersion = 'latest'] = matches;
const [, , pluginSource = PluginSource.NPM, pluginName, , pluginVersion = 'latest', , opt, optVal ] = matches;
if (pluginName && pluginVersion) {
if (!pluginName.startsWith(PLUGIN_NAME_PREFIX)) {
throw new Error(`Plugin name must start with ${PLUGIN_NAME_PREFIX}`);
Expand All @@ -119,6 +119,7 @@ export class PluginRegistryService {
name: pluginName,
version: pluginVersion,
pluginSource,
...opt && optVal && { [opt]: optVal },
};
}
}
Expand Down

0 comments on commit 53ff5ae

Please sign in to comment.