Skip to content

feat(extensibility): Add hint how to get access to a command from extension#3394

Merged
rosen-vladimirov merged 2 commits into
masterfrom
vladimirov/extensions-lookup
Mar 1, 2018
Merged

feat(extensibility): Add hint how to get access to a command from extension#3394
rosen-vladimirov merged 2 commits into
masterfrom
vladimirov/extensions-lookup

Conversation

@rosen-vladimirov
Copy link
Copy Markdown
Contributor

In case user executes any command that is registered in extension, but this extension is not installed, they'll receive error:
Unknown command .... Instead of showing this, it is better to tell them how to get access to this command.
In order to achieve this, implement a new logic in extensibilityService to find commands registered in all extensions. CLI searches npm (via npms API) for packages that have the keyword nativescript:extension.
After that, CLI gets the package.json of the latest version of each dependency (via registry.npmjs.org) and searches for nativescript key in it. In case it has nativescript key, CLI reads the commands value inside it. The value should be string array containg all commands registered in extension's bootstrap.
When user writes down a command that is not registered in CLI, we check if there's such command and in case it is found, CLI will instruct the user how to install the respective extension.
Same will happen in case user tries to access the help content of a command that is registered in extension.

Copy link
Copy Markdown
Contributor Author

@rosen-vladimirov rosen-vladimirov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Add additional tests to ensure calls to getExtensionNameWhereCommandIsRegistered will never throw error.
  2. Handle default commands, i.e. containing |*

Comment thread lib/services/extensibility-service.ts Outdated
return {
extensionName,
registeredCommandName: currentCommand,
installationMessage: `The command ${currentCommand} is registered in extension ${extensionName}. You can install it by executing 'tns extension install ${extensionName}'`
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautify the command name (replace | with ).

Copy link
Copy Markdown
Contributor

@Fatme Fatme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯

Comment thread lib/node-package-manager.ts Outdated
const url = `https://registry.npmjs.org/${packageName}`;
this.$logger.trace(`Trying to get data from npm registry for package ${packageName}, url is: ${url}`);
const responseData = (await this.$httpClient.httpRequest(url)).body;
this.$logger.trace(`Successfully received data from npm registry for package ${packageName}.`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't print responseData as well?

@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/extensions-lookup branch from dfbe0b5 to 338f815 Compare February 27, 2018 22:20
…ension

In case user executes any command that is registered in extension, but this extension is not installed, they'll receive error:
`Unknown command ...`. Instead of showing this, it is better to tell them how to get access to this command.
In order to achieve this, implement a new logic in `extensibilityService` to find commands registered in all extensions. CLI searches npm (via npms API) for packages that have the keyword `nativescript:extension`.
After that, CLI gets the package.json of the latest version of each dependency (via registry.npmjs.org) and searches for nativescript key in it. In case it has nativescript key, CLI reads the commands value inside it. The value should be string array containg all commands registered in extension's bootstrap.
When user writes down a command that is not registered in CLI, we check if there's such command and in case it is found, CLI will instruc the user how to install the respective extension.
Same will happen in case user tries to access the help content of a command that is registered in extension.
@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/extensions-lookup branch from 338f815 to e411ca5 Compare March 1, 2018 12:50
@rosen-vladimirov rosen-vladimirov merged commit 44727d8 into master Mar 1, 2018
@rosen-vladimirov rosen-vladimirov deleted the vladimirov/extensions-lookup branch March 1, 2018 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants