Skip to content

Commit 194106c

Browse files
feat: improve initialization service
Improve initialization service, so it can be used to initialize all settings required at the beginning of CLI process.
1 parent 9bff5a0 commit 194106c

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

PublicAPI.md

+27-6
Original file line numberDiff line numberDiff line change
@@ -1528,20 +1528,41 @@ tns.cleanupService.setCleanupLogFile("/Users/username/cleanup-logs.txt");
15281528
The `initializeService` is used to initialize CLI's configuration at the beginning and print all warnings related to current environment.
15291529
15301530
### initialize
1531-
This method inits CLI's logger and prints all system warnings.
1531+
This method executes initialization actions based on the passed parameters. In case `loggerOptions` are not passed, the default CLI logger will be used.
1532+
After initialization, the method will print all system warnings.
15321533
15331534
* Definition
15341535
```TypeScript
1535-
initialize(initOpts?: { loggerOptions?: ILoggerOptions }): Promise<void>
1536+
interface IInitializeOptions {
1537+
loggerOptions?: ILoggerOptions;
1538+
settingsServiceOptions?: IConfigurationSettings;
1539+
extensibilityOptions?: { pathToExtensions: string };
1540+
}
1541+
1542+
interface IInitializeService {
1543+
initialize(initOpts?: IInitializeOptions): Promise<void>;
1544+
}
1545+
15361546
```
15371547
15381548
> NOTE: For more information about loggerOptions, you can check `logger`.
15391549
15401550
* Usage
1541-
```JavaScript
1542-
const tns = require("nativescript");
1543-
tns.initializeService.initialize();
1544-
```
1551+
* Initialization without passing any data - `logger` will be initialized with default CLI settings. Warnings will be printed if there are any.
1552+
```JavaScript
1553+
const tns = require("nativescript");
1554+
tns.initializeService.initialize();
1555+
```
1556+
* Initialize with custom settings service options:
1557+
```JavaScript
1558+
const tns = require("nativescript");
1559+
tns.initializeService.initialize({ settingsServiceOptions: { profileDir: "/Users/username/customDir", userAgentName: "MyApp" } });
1560+
```
1561+
* Initialize with custom extensibility path:
1562+
```JavaScript
1563+
const tns = require("nativescript");
1564+
tns.initializeService.initialize({ extensibilityOptions: { pathToExtensions: "/Users/username/customDir/extensions" } });
1565+
```
15451566
15461567
## logger
15471568

lib/common/definitions/extensibility.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ interface IExtensibilityService {
130130
* @returns {IExtensionCommandInfo} Information about the extension and the registered command.
131131
*/
132132
getExtensionNameWhereCommandIsRegistered(inputOpts: IGetExtensionCommandInfoParams): Promise<IExtensionCommandInfo>;
133+
134+
/**
135+
* Defines the path where CLI will search for extensions.
136+
*/
137+
pathToExtensions: string;
133138
}
134139

135140
/**
+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
interface IInitializeOptions {
2+
loggerOptions?: ILoggerOptions;
3+
settingsServiceOptions?: IConfigurationSettings;
4+
extensibilityOptions?: { pathToExtensions: string };
5+
}
6+
17
interface IInitializeService {
2-
initialize(initOpts?: { loggerOptions?: ILoggerOptions }): Promise<void>;
8+
initialize(initOpts?: IInitializeOptions): Promise<void>;
39
}

lib/services/initialize-service.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class InitializeService implements IInitializeService {
55
// Injecting something may lead to logger initialization, but we want to initialize it from here.
66
constructor(private $injector: IInjector) { }
77

8-
public async initialize(initOpts?: { loggerOptions?: ILoggerOptions }): Promise<void> {
8+
public async initialize(initOpts?: IInitializeOptions): Promise<void> {
99
initOpts = initOpts || {};
1010
const $logger = this.$injector.resolve<ILogger>("logger");
1111
if (initOpts.loggerOptions) {
@@ -14,6 +14,18 @@ export class InitializeService implements IInitializeService {
1414
$logger.initializeCliLogger();
1515
}
1616

17+
if (initOpts.settingsServiceOptions) {
18+
const $settingsService = this.$injector.resolve<ISettingsService>("settingsService");
19+
$settingsService.setSettings(initOpts.settingsServiceOptions);
20+
}
21+
22+
if (initOpts.extensibilityOptions) {
23+
if (initOpts.extensibilityOptions.pathToExtensions) {
24+
const $extensibilityService = this.$injector.resolve<IExtensibilityService>("extensibilityService");
25+
$extensibilityService.pathToExtensions = initOpts.extensibilityOptions.pathToExtensions;
26+
}
27+
}
28+
1729
await this.showWarnings($logger);
1830
}
1931

0 commit comments

Comments
 (0)