Skip to content

Commit dd2c26d

Browse files
docs: Add new methods to PublicAPI
1 parent d5bfec2 commit dd2c26d

File tree

2 files changed

+134
-1
lines changed

2 files changed

+134
-1
lines changed

PublicAPI.md

+115-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const tns = require("nativescript");
1414
* [projectDataService](#projectdataservice)
1515
* [getProjectData](#getprojectdata)
1616
* [getProjectDataFromContent](#getprojectdatafromcontent)
17+
* [getNsConfigDefaultContent](#getnsconfigdefaultcontent)
18+
* [getAssetsStructure](#getassetsstructure)
19+
* [getIOSAssetsStructure](#getiosassetsstructure)
20+
* [getAndroidAssetsStructure](#getandroidassetsstructure)
1721
* [extensibilityService](#extensibilityservice)
1822
* [installExtension](#installextension)
1923
* [uninstallExtension](#uninstallextension)
@@ -41,7 +45,9 @@ const tns = require("nativescript");
4145
* [analyticsSettingsService](#analyticsSettingsService)
4246
* [getClientId](#getClientId)
4347
* [constants](#constants)
44-
48+
* [assetsGenerationService](#assetsgenerationservice)
49+
* [generateIcons](#generateicons)
50+
* [generateSplashScreens](#generatesplashscreens)
4551

4652
## Module projectService
4753

@@ -199,6 +205,66 @@ Returns the default content of "nsconfig.json" merged with the properties provid
199205
getNsConfigDefaultContent(data?: Object): string
200206
```
201207
208+
### getAssetsStructure
209+
Gives information about the whole assets structure for both iOS and Android. For each of the platforms, the returned object will contain icons, splashBackgrounds, splashCenterImages and splashImages (only for iOS).
210+
* Definition:
211+
```TypeScript
212+
/**
213+
* Gives information about the whole assets structure for both iOS and Android.
214+
* For each of the platforms, the returned object will contain icons, splashBackgrounds, splashCenterImages and splashImages (only for iOS).
215+
* @param {IProjectDir} opts Object with a single property - projectDir. This is the root directory where NativeScript project is located.
216+
* @returns {Promise<IAssetsStructure>} An object describing the current asset structure.
217+
*/
218+
getAssetsStructure(opts: IProjectDir): Promise<IAssetsStructure>;
219+
```
220+
221+
* Usage:
222+
```JavaScript
223+
tns.projectDataService.getAssetsStructure({ projectDir: "/Users/username/myNativeScriptProject" })
224+
.then(assetsStructure => console.log(`The current assets structure is ${JSON.stringify(assetsStructure, null, 2)}.`))
225+
.catch(err => console.log("Failed to get assets structure."));
226+
```
227+
228+
### getIOSAssetsStructure
229+
Gives information about the assets structure for iOS .The returned object will contain icons, splashBackgrounds, splashCenterImages and splashImages.
230+
* Definition:
231+
```TypeScript
232+
/**
233+
* Gives information about the whole assets structure for iOS.
234+
* The returned object will contain icons, splashBackgrounds, splashCenterImages and splashImages.
235+
* @param {IProjectDir} opts Object with a single property - projectDir. This is the root directory where NativeScript project is located.
236+
* @returns {Promise<IAssetGroup>} An object describing the current asset structure for iOS.
237+
*/
238+
getIOSAssetsStructure(opts: IProjectDir): Promise<IAssetGroup>;
239+
```
240+
241+
* Usage:
242+
```JavaScript
243+
tns.projectDataService.getIOSAssetsStructure({ projectDir: "/Users/username/myNativeScriptProject" })
244+
.then(assetsStructure => console.log(`The current assets structure for iOS is ${JSON.stringify(assetsStructure, null, 2)}.`))
245+
.catch(err => console.log("Failed to get assets structure."));
246+
```
247+
248+
### getAndroidAssetsStructure
249+
Gives information about the assets structure for Android .The returned object will contain icons, splashBackgrounds and splashCenterImages.
250+
* Definition:
251+
```TypeScript
252+
/**
253+
* Gives information about the whole assets structure for Android.
254+
* The returned object will contain icons, splashBackgrounds and splashCenterImages.
255+
* @param {IProjectDir} opts Object with a single property - projectDir. This is the root directory where NativeScript project is located.
256+
* @returns {Promise<IAssetGroup>} An object describing the current asset structure for Android.
257+
*/
258+
getAndroidAssetsStructure(opts: IProjectDir): Promise<IAssetGroup>;
259+
```
260+
261+
* Usage:
262+
```JavaScript
263+
tns.projectDataService.getAndroidAssetsStructure({ projectDir: "/Users/username/myNativeScriptProject" })
264+
.then(assetsStructure => console.log(`The current assets structure for Android is ${JSON.stringify(assetsStructure, null, 2)}.`))
265+
.catch(err => console.log("Failed to get assets structure."));
266+
```
267+
202268
## extensibilityService
203269
`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.
204270
@@ -1013,6 +1079,54 @@ tns.analyticsSettingsService.getPlaygroundInfo("/my/project/path")
10131079
## constants
10141080
Contains various constants related to NativeScript.
10151081
1082+
## assetsGenerationService
1083+
`assetsGenerationService` module allows generation of assets - icons and splashes.
1084+
1085+
### generateIcons
1086+
The `generateIcons` method generates icons for specified platform (or both iOS and Android in case platform is not specified) and places them on correct location in the specified project.
1087+
1088+
* Definition:
1089+
```TypeScript
1090+
/**
1091+
* Generate icons for iOS and Android
1092+
* @param {IResourceGenerationData} iconsGenerationData Provides the data needed for icons generation
1093+
* @returns {Promise<void>}
1094+
*/
1095+
generateIcons({ imagePath: string, projectDir: string, platform?: string }): Promise<void>;
1096+
```
1097+
1098+
* Usage:
1099+
```JavaScript
1100+
tns.assetsGenerationService.generateIcons({ projectDir: "/Users/username/myNativeScriptProject", imagePath: "/Users/username/image.png" })
1101+
.then(() => {
1102+
console.log("Successfully generated icons");
1103+
});
1104+
```
1105+
1106+
1107+
### generateSplashScreens
1108+
The `generateSplashScreens` method generates icons for specified platform (or both iOS and Android in case platform is not specified) and places them on correct location in the specified project.
1109+
1110+
* Definition:
1111+
```TypeScript
1112+
/**
1113+
* Generate splash screens for iOS and Android
1114+
* @param {ISplashesGenerationData} splashesGenerationData Provides the data needed for splash screens generation
1115+
* @returns {Promise<void>}
1116+
*/
1117+
generateSplashScreens({ imagePath: string, projectDir: string, platform?: string, background?: string }): Promise<void>;
1118+
```
1119+
1120+
* Usage:
1121+
```JavaScript
1122+
tns.assetsGenerationService.generateSplashScreens({ projectDir: "/Users/username/myNativeScriptProject", imagePath: "/Users/username/image.png", background: "blue" })
1123+
.then(() => {
1124+
console.log("Successfully generated splash screens");
1125+
});
1126+
```
1127+
1128+
1129+
10161130
## How to add a new method to Public API
10171131
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.
10181132
For example the `$options` injected module contains information about all `--` options passed on the terminal. When the CLI is used as a library, the options are not populated. Before adding method to public API, make sure its implementation does not rely on `$options`.

lib/definitions/project.d.ts

+19
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,29 @@ interface IProjectDataService {
124124

125125
getProjectData(projectDir?: string): IProjectData;
126126

127+
/**
128+
* Gives information about the whole assets structure for both iOS and Android.
129+
* For each of the platforms, the returned object will contain icons, splashBackgrounds, splashCenterImages and splashImages (only for iOS).
130+
* @param {IProjectDir} opts Object with a single property - projectDir. This is the root directory where NativeScript project is located.
131+
* @returns {Promise<IAssetsStructure>} An object describing the current asset structure.
132+
*/
127133
getAssetsStructure(opts: IProjectDir): Promise<IAssetsStructure>;
128134

135+
136+
/**
137+
* Gives information about the whole assets structure for iOS.
138+
* The returned object will contain icons, splashBackgrounds, splashCenterImages and splashImages.
139+
* @param {IProjectDir} opts Object with a single property - projectDir. This is the root directory where NativeScript project is located.
140+
* @returns {Promise<IAssetGroup>} An object describing the current asset structure for iOS.
141+
*/
129142
getIOSAssetsStructure(opts: IProjectDir): Promise<IAssetGroup>;
130143

144+
/**
145+
* Gives information about the whole assets structure for Android.
146+
* The returned object will contain icons, splashBackgrounds and splashCenterImages.
147+
* @param {IProjectDir} opts Object with a single property - projectDir. This is the root directory where NativeScript project is located.
148+
* @returns {Promise<IAssetGroup>} An object describing the current asset structure for Android.
149+
*/
131150
getAndroidAssetsStructure(opts: IProjectDir): Promise<IAssetGroup>;
132151
}
133152

0 commit comments

Comments
 (0)