Skip to content

Commit 7fc0c07

Browse files
Show context specific help
In some cases we want to hide some parts of our help. For example if the user is on MacOS, information how to setup Windows or Linux system is not needed for him. Add dynamicHelpProvider which is used to determine some context specific values. Update common lib where we've added the following changes: Add support for multilevel hierarchical commands. This way we can use commands like $ appbuilder appmanager upload android declared as "appmanager|upload|android". Add support for passing multiple arguments to dynamic calls, by changing regular expressions. Add DynamicHelpService which is used to check different conditions when printing our help. Use _.isBoolean where possible. Add dynamicHelpProvider which should be implemented by each CLI. Use lodash _.template as it uses microTemplate internally and pass the help through it. This way we can write javascript directly in our help.txt. Replace of all entries in the help content (when executing), which match our dynamicCallRegex with this.$injector.dynamicCall($1).wait() This way you can call dynamic methods, by just using: \<%= #{platformService.validatePlatform} %\> Add localVariables that allow easy call for default scenarios (isLinux, isMacOS, is Windows). In order to use it, just call: \<% if (isLinux) %\> Practically you can add whatever javascript code you want in help.txt. Just wrap it inside <% %> In case you want to call some method that returns string and you need the string in help.txt just write: Some text... \<%= this.$injector.resolve("project").myMethod() %\> or even simpler: Some text... \<%= #{project.myMethod} %\> The code between <%= and %> will be executed (it's pure javascript, but you are able to use our $injector and $dynamicHelpService) and the returned string will be placed in the help file. In case you want to limit some text only for specific case, just write: \<% if (this.$dynamicHelpService.isPlatform("linux")) { %\> In this version of the NativeScript CLI, you cannot build and deploy to iOS connected devices on Linux systems. \<% } %\> This way the code in if statement will be shown only in case command is run on linux. You can simplify it by using localVariables added in common lib: \<% if (isLinux) { %\> In this version of the NativeScript CLI, you cannot build and deploy to iOS connected devices on Linux systems. \<% } %\> https://huboard.com/NativeScript/nativescript-cli#/issues/60481986
1 parent 918adf0 commit 7fc0c07

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ $injector.requireCommand("emulate|ios", "./commands/emulate");
4040
$injector.require("npm", "./node-package-manager");
4141
$injector.require("lockfile", "./lockfile");
4242
$injector.require("optionsService", "./services/options-service");
43+
$injector.require("dynamicHelpProvider", "./dynamic-help-provider");

lib/dynamic-help-provider.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
///<reference path=".d.ts"/>
2+
3+
"use strict";
4+
5+
import Future = require("fibers/future");
6+
7+
export class DynamicHelpProvider implements IDynamicHelpProvider {
8+
constructor() { }
9+
10+
public isProjectType(args: string[]): IFuture<boolean> {
11+
return Future.fromResult(true);
12+
}
13+
14+
public getLocalVariables(): IFuture<IDictionary<any>> {
15+
var localVariables: IDictionary<any> = {};
16+
return Future.fromResult(localVariables);
17+
}
18+
}
19+
$injector.register("dynamicHelpProvider", DynamicHelpProvider);

resources/help.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ Before running your app in the Android emulator from the Android SDK, verify tha
358358
tools
359359
Before running your app in the Genymotion emulator, verify that your system meets the following requirements.
360360
* Verify that you have installed Genymotion.
361-
* On Windows and Linux systems, verify that you have added the Genymotion installation directory to the PATH environment variable.
362-
* On OS X systems, verify that you have added the following paths to the PATH environment variable.
361+
<% if(isLinux || isWindows) { %>* On Windows and Linux systems, verify that you have added the Genymotion installation directory to the PATH environment variable.<%}%>
362+
<% if(isMacOS) { %>* On OS X systems, verify that you have added the following paths to the PATH environment variable.
363363
* /Applications/Genymotion.app/Contents/MacOS/
364364
* /Applications/Genymotion Shell.app/Contents/MacOS/
365-
365+
<% } %>
366366
Options:
367367
--device - Specifies a connected device on which to run the app.
368368
You cannot use --device and --emulator simultaneously.
@@ -498,11 +498,11 @@ Before running your app in the Android emulator from the Android SDK, verify tha
498498
tools
499499
Before running your app in the Genymotion emulator, verify that your system meets the following requirements.
500500
* Verify that you have installed Genymotion.
501-
* On Windows and Linux systems, verify that you have added the Genymotion installation directory to the PATH environment variable.
502-
* On OS X systems, verify that you have added the following paths to the PATH environment variable.
501+
<% if(isLinux || isWindows) { %>* On Windows and Linux systems, verify that you have added the Genymotion installation directory to the PATH environment variable.<% } %>
502+
<% if(isMacOS) { %>* On OS X systems, verify that you have added the following paths to the PATH environment variable.
503503
* /Applications/Genymotion.app/Contents/MacOS/
504504
* /Applications/Genymotion Shell.app/Contents/MacOS/
505-
505+
<% } %>
506506
Options:
507507
--path - Specifies the directory that contains the project. If not specified, the project is searched
508508
for in the current directory and all directories above it.

0 commit comments

Comments
 (0)