You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: PublicAPI.md
+121-80
Original file line number
Diff line number
Diff line change
@@ -3,35 +3,17 @@ Public API
3
3
4
4
This document describes all methods that can be invoked when NativeScript CLI is required as library, i.e.
5
5
6
-
<table>
7
-
<tr>
8
-
<td>
9
-
JavaScript
10
-
</td>
11
-
<td>
12
-
TypeScript
13
-
</td>
14
-
</tr>
15
-
<tr>
16
-
<td>
17
-
<prelang="javascript">
6
+
```JavaScript
18
7
consttns=require("nativescript");
19
-
</pre>
20
-
</td>
21
-
<td>
22
-
<prelang="typescript">
23
-
import * as tns from "nativescript";
24
-
</pre>
25
-
</td>
26
-
</tr>
27
-
28
-
</table>
8
+
```
29
9
30
10
## Module projectService
31
11
32
12
`projectService` modules allow you to create new NativeScript application.
33
13
34
-
*`createProject(projectSettings: IProjectSettings): Promise<void>` - Creates new NativeScript application. By passing `projectSettings` argument you specify the name of the application, the template that will be used, etc.:
14
+
### createProject
15
+
* Description: `createProject(projectSettings: IProjectSettings): Promise<void>` - Creates new NativeScript application. By passing `projectSettings` argument you specify the name of the application, the template that will be used, etc.:
16
+
35
17
```TypeScript
36
18
/**
37
19
* Describes available settings when creating new NativeScript application.
.catch((err) => console.log("Unable to create project, reason: ", err);
111
-
</pre>
112
-
</td>
113
-
</tr>
114
-
</table>
115
-
116
-
*`isValidNativeScriptProject(projectDir: string): boolean` - Checks if the specified path is a valid NativeScript project. Returns `true` in case the directory is a valid project, `false` otherwise.
* Definition: `isValidNativeScriptProject(projectDir: string): boolean` - Checks if the specified path is a valid NativeScript project. Returns `true` in case the directory is a valid project, `false` otherwise.
`extensibilityService` module gives access to methods for working with CLI's extensions - list, install, uninstall, load them. The extensions add new functionality to CLI, so once an extension is loaded, all methods added to it's public API are accessible directly through CLI when it is used as a library. Extensions may also add new commands, so they are accessible through command line when using NativeScript CLI.
82
+
83
+
A common interface describing the results of a method is `IExtensionData`:
84
+
```TypeScript
85
+
/**
86
+
* Describes each extension.
87
+
*/
88
+
interface IExtensionData {
89
+
/**
90
+
* The name of the extension.
91
+
*/
92
+
extensionName: string;
93
+
}
94
+
```
95
+
96
+
### installExtension
97
+
Installs specified extension and loads it in the current process, so the functionality that it adds can be used immediately.
98
+
99
+
* Definition:
100
+
```TypeScript
101
+
/**
102
+
* Installs and loads specified extension.
103
+
* @param{string}extensionName Name of the extension to be installed. It may contain version as well, i.e. myPackage, [email protected], myPackage.tgz, https://github.com/myOrganization/myPackage/tarball/master, https://github.com/myOrganization/myPackage etc.
104
+
* @returns{Promise<IExtensionData>} Information about installed extensions.
console.log(`The extension ${extensionName} is installed with version ${version}.`);
154
+
}
155
+
```
156
+
157
+
### loadExtensions
158
+
Loads all currently installed extensions. The method returns array of Promises, one for each installed extension. In case any of the extensions cannot be loaded, only its Promise is rejected.
159
+
160
+
* Definition
161
+
```TypeScript
162
+
/**
163
+
* Loads all extensions, so their methods and commands can be used from CLI.
164
+
* For each of the extensions, a new Promise is returned. It will be rejected in case the extension cannot be loaded. However other promises will not be reflected by this failure.
165
+
* In case a promise is rejected, the error will have additional property (extensionName) that shows which is the extension that cannot be loaded in the process.
166
+
* @returns{Promise<IExtensionData>[]} Array of promises, each is resolved with information about loaded extension.
console.log(`Failed to load extension: ${err.extensionName}`);
178
+
console.log(err);
179
+
});
180
+
}
181
+
```
141
182
142
183
## How to add a new method to Public API
143
184
CLI is designed as command line tool and when it is used as a library, it does not give you access to all of the methods. This is mainly implementation detail. Most of the CLI's code is created to work in command line, not as a library, so before adding method to public API, most probably it will require some modification.
Installs specified extension. Each extension adds additional functionality that's accessible directly from NativeScript CLI.
9
+
10
+
### Attributes
11
+
12
+
*`<Extension>` is any of the following.
13
+
* 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.
14
+
* A `<Local Path>` to the directory which contains the extension, including its `package.json` file.
15
+
* A `<Local Path>` to a `.tar.gz` archive containing a directory with the extension and its `package.json` file.
16
+
* A `<URL>` which resolves to a `.tar.gz` archive containing a directory with the extension and its `package.json` file.
17
+
* A `<git Remote URL>` which resolves to a `.tar.gz` archive containing a directory with the extension and its `package.json` file.
18
+
19
+
<% if(isHtml) { %>
20
+
### Related Commands
21
+
22
+
Command | Description
23
+
----------|----------
24
+
[extension](extension.html) | Prints information about all installed extensions.
allowedParameters: ICommandParameter[]=[this.$stringParameterBuilder.createMandatoryParameter("You have to provide a valid name for extension that you want to install.")];
allowedParameters: ICommandParameter[]=[this.$stringParameterBuilder.createMandatoryParameter("You have to provide a valid name for extension that you want to uninstall.")];
0 commit comments