Skip to content

Commit f74facd

Browse files
chore: remove dynamicHelpService and dynamicHelpProvider
Remove `dynamicHelpService` and `dynamicHelpProvider` - they were used when the code between AppBuilder CLI and NativeScript CLI was shared. The idea of the service was to get the help content of ScreenBuilder commands. Now we do not need such logic, so just remove it and clean the code from the unused interfaces.
1 parent 022c1b0 commit f74facd

File tree

7 files changed

+36
-102
lines changed

7 files changed

+36
-102
lines changed

lib/bootstrap.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ $injector.requireCommand("package-manager|set", "./commands/package-manager-set"
8585
$injector.requireCommand("package-manager|get", "./commands/package-manager-get");
8686

8787
$injector.require("packageInstallationManager", "./package-installation-manager");
88-
$injector.require("dynamicHelpProvider", "./dynamic-help-provider");
8988

9089
$injector.require("deviceLogProvider", "./common/mobile/device-log-provider");
9190
$injector.require("projectFilesProvider", "./providers/project-files-provider");

lib/common/bootstrap.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ $injector.require("autoCompletionService", "./services/auto-completion-service")
8787
$injector.require("processService", "./services/process-service");
8888
$injector.requirePublic("settingsService", "./services/settings-service");
8989
$injector.require("opener", "./opener");
90-
$injector.require("dynamicHelpService", "./services/dynamic-help-service");
9190
$injector.require("microTemplateService", "./services/micro-templating-service");
9291
$injector.require("mobileHelper", "./mobile/mobile-helper");
9392
$injector.require("emulatorHelper", "./mobile/emulator-helper");

lib/common/declarations.d.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -819,24 +819,6 @@ interface IHook {
819819
fullPath: string;
820820
}
821821

822-
interface IDynamicHelpService {
823-
/**
824-
* Checks if current project's framework is one of the specified as arguments.
825-
* @param args {string[]} Frameworks to be checked.
826-
* @returns {boolean} True in case the current project's framework is one of the passed as args, false otherwise.
827-
*/
828-
isProjectType(...args: string[]): boolean;
829-
830-
isPlatform(...args: string[]): boolean;
831-
832-
/**
833-
* Gives an object containing all required variables that can be used in help content and their values.
834-
* @param {any} Object with one boolean property - `isHtml` - it defines if the help content is generated for html or for console help.
835-
* @returs {IDictionary<any>} Key-value pairs of variables and their values.
836-
*/
837-
getLocalVariables(options: { isHtml: boolean }): IDictionary<any>;
838-
}
839-
840822
/**
841823
* Describes standard username/password type credentials.
842824
*/
@@ -935,22 +917,6 @@ interface IQrCodeImageData {
935917
imageData: string;
936918
}
937919

938-
interface IDynamicHelpProvider {
939-
/**
940-
* Checks if current project's framework is one of the specified as arguments.
941-
* @param args {string[]} Frameworks to be checked.
942-
* @returns {boolean} True in case the current project's framework is one of the passed as args, false otherwise.
943-
*/
944-
isProjectType(args: string[]): boolean;
945-
946-
/**
947-
* Gives an object containing all required variables that can be used in help content and their values.
948-
* @param {any} Object with one boolean property - `isHtml` - it defines if the help content is generated for html or for console help.
949-
* @returs {IDictionary<any>} Key-value pairs of variables and their values.
950-
*/
951-
getLocalVariables(options: { isHtml: boolean }): IDictionary<any>;
952-
}
953-
954920
interface IMicroTemplateService {
955921
parseContent(data: string, options: { isHtml: boolean }): Promise<string>;
956922
}

lib/common/services/dynamic-help-service.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
import * as util from "util";
2+
import * as os from "os";
3+
import * as constants from "../constants";
4+
import { formatListOfNames } from '../helpers';
25

36
export class MicroTemplateService implements IMicroTemplateService {
47
private dynamicCallRegex: RegExp;
58

6-
constructor(private $dynamicHelpService: IDynamicHelpService,
7-
private $injector: IInjector) {
9+
constructor(private $injector: IInjector) {
810
// Injector's dynamicCallRegex doesn't have 'g' option, which we need here.
911
// Use ( ) in order to use $1 to get whole expression later
1012
this.dynamicCallRegex = new RegExp(util.format("(%s)", this.$injector.dynamicCallRegex.source), "g");
1113
}
1214

1315
public async parseContent(data: string, options: { isHtml: boolean }): Promise<string> {
14-
const localVariables = this.$dynamicHelpService.getLocalVariables(options);
16+
const localVariables = this.getLocalVariables(options);
1517
const compiledTemplate = _.template(data.replace(this.dynamicCallRegex, "this.$injector.getDynamicCallData(\"$1\")"));
1618
// When debugging parsing, uncomment the line below:
1719
// console.log(compiledTemplate.source);
1820
return await compiledTemplate.apply(this, [localVariables]);
1921
}
22+
23+
private isPlatform(...args: string[]): boolean {
24+
const platform = os.platform().toLowerCase();
25+
return _.some(args, arg => arg.toLowerCase() === platform);
26+
}
27+
28+
private getLocalVariables(options: { isHtml: boolean }): IDictionary<any> {
29+
const isHtml = options.isHtml;
30+
// in html help we want to show all help. Only CONSOLE specific help(wrapped in if(isConsole) ) must be omitted
31+
const localVariables: IDictionary<any> = {
32+
constants
33+
};
34+
localVariables["isLinux"] = isHtml || this.isPlatform("linux");
35+
localVariables["isWindows"] = isHtml || this.isPlatform("win32");
36+
localVariables["isMacOS"] = isHtml || this.isPlatform("darwin");
37+
localVariables["isConsole"] = !isHtml;
38+
localVariables["isHtml"] = isHtml;
39+
localVariables["formatListOfNames"] = formatListOfNames;
40+
localVariables["isJekyll"] = false;
41+
42+
return localVariables;
43+
}
2044
}
2145
$injector.register("microTemplateService", MicroTemplateService);

lib/common/test/unit-tests/services/help-service.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,6 @@ const createTestInjector = (opts?: { isProjectTypeResult: boolean; isPlatformRes
2020
injector.register("logger", CommonLoggerStub);
2121

2222
opts = opts || { isPlatformResult: true, isProjectTypeResult: true };
23-
24-
injector.register("dynamicHelpProvider", {
25-
getLocalVariables: () => ({})
26-
});
27-
28-
injector.register("dynamicHelpService", {
29-
isProjectType: (...args: string[]): boolean => opts.isProjectTypeResult,
30-
isPlatform: (...args: string[]): boolean => { return opts.isPlatformResult; },
31-
getLocalVariables: (): IDictionary<any> => {
32-
const localVariables: IDictionary<any> = {};
33-
localVariables["myLocalVar"] = opts.isProjectTypeResult;
34-
localVariables["isLinux"] = opts.isPlatformResult;
35-
localVariables["isWindows"] = opts.isPlatformResult;
36-
localVariables["isMacOS"] = opts.isPlatformResult;
37-
return localVariables;
38-
}
39-
});
4023
injector.register("microTemplateService", MicroTemplateService);
4124
injector.register("helpService", HelpService);
4225
injector.register("opener", {
@@ -53,6 +36,15 @@ const createTestInjector = (opts?: { isProjectTypeResult: boolean; isPlatformRes
5336

5437
injector.registerCommand("foo", {});
5538

39+
const microTemplateService: any = injector.resolve("microTemplateService");
40+
microTemplateService.getLocalVariables = (): IDictionary<any> => {
41+
const localVariables: IDictionary<any> = {};
42+
localVariables["myLocalVar"] = opts.isProjectTypeResult;
43+
localVariables["isLinux"] = opts.isPlatformResult;
44+
localVariables["isWindows"] = opts.isPlatformResult;
45+
localVariables["isMacOS"] = opts.isPlatformResult;
46+
return localVariables;
47+
};
5648
return injector;
5749
};
5850

lib/dynamic-help-provider.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)