-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement extensibility model for CLI (#2724)
Implement extensibilty of CLI that allows anyone to add easily create packages that add new functionality to NativeScript CLI. The packages are installed in a specific directory, so they are persisted through CLI's updated. The directory where extensions are installed contains a package.json and each extension is npm package installed there. The extensions can be mainatined in two different ways: - navigate to the directory where extensions are installed and use `npm` for install/uninstall/update of packages. - use CLI's commands to update them: `tns extension install <name>`, `tns extension uninstall <name>`, `tns extension` Implement extensibilityService that executes all operations and expose it to public API. In {N} CLI the extensions are loaded in the entry point, before parsing command line arguments. This way extensions can add new commands. In Fusion, after CLI is required as a library, the `extensibilityService.loadExtensions` method should be called. It returns array of Promises - one for each installed extension. Add help for the new commands, but do not link the new commands in other commands help for the moment. Add unit tests for the new service.
- Loading branch information
1 parent
a9afa64
commit 6ad0cef
Showing
16 changed files
with
1,104 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
extension install | ||
========== | ||
|
||
Usage | Synopsis | ||
------|------- | ||
General | `$ tns extension install <Extension>` | ||
|
||
Installs specified extension. Each extension adds additional functionality that's accessible directly from NativeScript CLI. | ||
|
||
### Attributes | ||
|
||
* `<Extension>` is any of the following. | ||
* A `<Name>` or `<Name>@<Version>` where `<Name>` is the name of a package that is published in the npm registry and `<Version>` is a valid version of this plugin. | ||
* A `<Local Path>` to the directory which contains the extension, including its `package.json` file. | ||
* A `<Local Path>` to a `.tar.gz` archive containing a directory with the extension and its `package.json` file. | ||
* A `<URL>` which resolves to a `.tar.gz` archive containing a directory with the extension and its `package.json` file. | ||
* A `<git Remote URL>` which resolves to a `.tar.gz` archive containing a directory with the extension and its `package.json` file. | ||
|
||
<% if(isHtml) { %> | ||
### Related Commands | ||
|
||
Command | Description | ||
----------|---------- | ||
[extension](extension.html) | Prints information about all installed extensions. | ||
[extension-uninstall](extension-uninstall.html) | Uninstalls specified extension. | ||
[autocomplete-status](autocomplete-status.html) | Prints the current status of your command-line completion settings. | ||
[autocomplete-enable](autocomplete-enable.html) | Configures your current command-line completion settings. | ||
[autocomplete-disable](autocomplete-disable.html) | Disables command-line completion for bash and zsh shells. | ||
[usage-reporting](usage-reporting.html) | Configures anonymous usage reporting for the NativeScript CLI. | ||
[error-reporting](error-reporting.html) | Configures anonymous error reporting for the NativeScript CLI. | ||
[doctor](doctor.html) | Checks your system for configuration problems which might prevent the NativeScript CLI from working properly. | ||
[proxy](proxy.html) | Displays proxy settings. | ||
[proxy clear](proxy-clear.html) | Clears proxy settings. | ||
[proxy set](proxy-set.html) | Sets proxy settings. | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
extension uninstall | ||
========== | ||
|
||
Usage | Synopsis | ||
------|------- | ||
General | `$ tns extension uninstall <Extension>` | ||
|
||
Uninstalls specified extension. After that you will not be able to use the functionality that this extensions adds to NativeScript CLI. | ||
|
||
### Attributes | ||
|
||
* `<Extension>` is the name of the extension as listed in its `package.json` file. | ||
|
||
<% if(isHtml) { %> | ||
### Related Commands | ||
|
||
Command | Description | ||
----------|---------- | ||
[extension](extension.html) | Prints information about all installed extensions. | ||
[extension-uninstall](extension-uninstall.html) | Uninstalls specified extension. | ||
[extension-install](extension-install.html) | Installs specified extension. | ||
[autocomplete-status](autocomplete-status.html) | Prints the current status of your command-line completion settings. | ||
[autocomplete-enable](autocomplete-enable.html) | Configures your current command-line completion settings. | ||
[autocomplete-disable](autocomplete-disable.html) | Disables command-line completion for bash and zsh shells. | ||
[usage-reporting](usage-reporting.html) | Configures anonymous usage reporting for the NativeScript CLI. | ||
[error-reporting](error-reporting.html) | Configures anonymous error reporting for the NativeScript CLI. | ||
[doctor](doctor.html) | Checks your system for configuration problems which might prevent the NativeScript CLI from working properly. | ||
[proxy](proxy.html) | Displays proxy settings. | ||
[proxy clear](proxy-clear.html) | Clears proxy settings. | ||
[proxy set](proxy-set.html) | Sets proxy settings. | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
extension | ||
========== | ||
|
||
Usage | Synopsis | ||
------|------- | ||
General | `$ tns extension` | ||
|
||
Prints information about all installed extensions. | ||
|
||
<% if(isHtml) { %> | ||
### Related Commands | ||
|
||
Command | Description | ||
----------|---------- | ||
[extension-install](extension-install.html) | Installs specified extension. | ||
[autocomplete-status](autocomplete-status.html) | Prints the current status of your command-line completion settings. | ||
[autocomplete-enable](autocomplete-enable.html) | Configures your current command-line completion settings. | ||
[autocomplete-disable](autocomplete-disable.html) | Disables command-line completion for bash and zsh shells. | ||
[usage-reporting](usage-reporting.html) | Configures anonymous usage reporting for the NativeScript CLI. | ||
[error-reporting](error-reporting.html) | Configures anonymous error reporting for the NativeScript CLI. | ||
[doctor](doctor.html) | Checks your system for configuration problems which might prevent the NativeScript CLI from working properly. | ||
[proxy](proxy.html) | Displays proxy settings. | ||
[proxy clear](proxy-clear.html) | Clears proxy settings. | ||
[proxy set](proxy-set.html) | Sets proxy settings. | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export class InstallExtensionCommand implements ICommand { | ||
constructor(private $extensibilityService: IExtensibilityService, | ||
private $stringParameterBuilder: IStringParameterBuilder, | ||
private $logger: ILogger) { } | ||
|
||
public async execute(args: string[]): Promise<void> { | ||
const extensionData = await this.$extensibilityService.installExtension(args[0]); | ||
this.$logger.info(`Successfully installed extension ${extensionData.extensionName}.`); | ||
} | ||
|
||
allowedParameters: ICommandParameter[] = [this.$stringParameterBuilder.createMandatoryParameter("You have to provide a valid name for extension that you want to install.")]; | ||
} | ||
$injector.registerCommand("extension|install", InstallExtensionCommand); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as helpers from "../../common/helpers"; | ||
|
||
export class ListExtensionsCommand implements ICommand { | ||
constructor(private $extensibilityService: IExtensibilityService, | ||
private $logger: ILogger) { } | ||
|
||
public async execute(args: string[]): Promise<void> { | ||
const installedExtensions = this.$extensibilityService.getInstalledExtensions(); | ||
if (_.keys(installedExtensions).length) { | ||
this.$logger.info("Installed extensions:"); | ||
const data = _.map(installedExtensions, (version, name) => { | ||
return [name, version]; | ||
}); | ||
|
||
const table = helpers.createTable(["Name", "Version"], data); | ||
this.$logger.out(table.toString()); | ||
} else { | ||
this.$logger.info("No extensions installed."); | ||
} | ||
} | ||
|
||
allowedParameters: ICommandParameter[] = []; | ||
} | ||
$injector.registerCommand("extension|*list", ListExtensionsCommand); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export class UninstallExtensionCommand implements ICommand { | ||
constructor(private $extensibilityService: IExtensibilityService, | ||
private $stringParameterBuilder: IStringParameterBuilder, | ||
private $logger: ILogger) { } | ||
|
||
public async execute(args: string[]): Promise<void> { | ||
const extensionName = args[0]; | ||
await this.$extensibilityService.uninstallExtension(extensionName); | ||
this.$logger.info(`Successfully uninstalled extension ${extensionName}`); | ||
} | ||
|
||
allowedParameters: ICommandParameter[] = [this.$stringParameterBuilder.createMandatoryParameter("You have to provide a valid name for extension that you want to uninstall.")]; | ||
} | ||
$injector.registerCommand("extension|uninstall", UninstallExtensionCommand); |
Oops, something went wrong.