Content-Length: 507994 | pFad | http://github.com/MizoPro/nativescript-cli/commit/d84fcb0a0b31152a7fd079cf896d13c20df7ca58

D2 chore(nsconfig): export constants and getDefautNConfig to public API · MizoPro/nativescript-cli@d84fcb0 · GitHub
Skip to content

Commit d84fcb0

Browse files
committed
chore(nsconfig): export constants and getDefautNConfig to public API
1 parent 24b4467 commit d84fcb0

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed

Diff for: PublicAPI.md

+14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const tns = require("nativescript");
4040
* [events](#events)
4141
* [analyticsSettingsService](#analyticsSettingsService)
4242
* [getClientId](#getClientId)
43+
* [constants](#constants)
4344

4445

4546
## Module projectService
@@ -187,6 +188,17 @@ Returns an IProjectData object that is initialized with the provided package.jso
187188
getProjectDataFromContent(packageJsonContent: string, nsconfigContent: string, projectDir?: string): IProjectData
188189
```
189190
191+
### getNsConfigDefaultContent
192+
Returns the default content of "nsconfig.json" merged with the properties provided by the the `data` argument.
193+
* Definition:
194+
```TypeScript
195+
/**
196+
* Returns the default content of "nsconfig.json" merged with the properties provided by the "data" argument.
197+
* @param {Object} data Properties that should not be defaulted.
198+
*/
199+
getNsConfigDefaultContent(data: Object): string
200+
```
201+
190202
## extensibilityService
191203
`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.
192204
@@ -998,6 +1010,8 @@ tns.analyticsSettingsService.getPlaygroundInfo("/my/project/path")
9981010
console.log(playgroundInfo.usedTutorial);
9991011
});
10001012
```
1013+
## constants
1014+
Contains various constants related to NativeScript.
10011015
10021016
## How to add a new method to Public API
10031017
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.

Diff for: lib/bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ $injector.require("options", "./options");
55
// note: order above is important!
66
$injector.require("nativescript-cli", "./nativescript-cli");
77

8+
$injector.requirePublicClass("constants", "./constants-provider");
89
$injector.require("projectData", "./project-data");
910
$injector.requirePublic("projectDataService", "./services/project-data-service");
1011
$injector.requirePublic("projectService", "./services/project-service");

Diff for: lib/constants-provider.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as constants from './constants';
2+
3+
export class Constants implements IDictionary<any> {
4+
constructor () {
5+
Object.assign(this, constants);
6+
}
7+
}
8+
9+
$injector.register("constants", Constants);

Diff for: lib/project-data.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class ProjectData implements IProjectData {
3737
public projectFilePath: string;
3838
public projectId: string;
3939
public projectName: string;
40-
public nsConfig: any;
40+
public nsConfig: INsConfig;
4141
public appDirectoryPath: string;
4242
public appResourcesDirectoryPath: string;
4343
public dependencies: any;
@@ -160,7 +160,7 @@ export class ProjectData implements IProjectData {
160160
return null;
161161
}
162162

163-
const configNSFilePath = path.join(projectDir, constants.CONFIG_NS_FILE_NAME);
163+
const configNSFilePath = path.join(projectDir, this.getNsConfigRelativePath());
164164

165165
if (!this.$fs.exists(configNSFilePath)) {
166166
return null;
@@ -169,6 +169,10 @@ export class ProjectData implements IProjectData {
169169
return this.$fs.readText(configNSFilePath);
170170
}
171171

172+
public getNsConfigRelativePath(): string {
173+
return constants.CONFIG_NS_FILE_NAME;
174+
}
175+
172176
private resolveToProjectDir(pathToResolve: string, projectDir?: string): string {
173177
if (!projectDir) {
174178
projectDir = this.projectDir;

Diff for: lib/services/project-data-service.ts

+8
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,13 @@ export class ProjectDataService implements IProjectDataService {
124124
projectFilePath
125125
};
126126
}
127+
128+
@exported("projectDataService")
129+
public getNsConfigDefaultContent(data: Object): string {
130+
const config: INsConfig = {};
131+
Object.assign(config, data);
132+
133+
return JSON.stringify(config);
134+
}
127135
}
128136
$injector.register("projectDataService", ProjectDataService);

Diff for: test/nativescript-cli-lib.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ describe("nativescript-cli-lib", () => {
1616
settingsService: ["setSettings"],
1717
deviceEmitter: null,
1818
projectService: ["createProject", "isValidNativeScriptProject"],
19-
projectDataService: ["getProjectData", "getProjectDataFromContent"],
19+
projectDataService: ["getProjectData", "getProjectDataFromContent", "getNsConfigDefaultContent"],
20+
constants: ["CONFIG_NS_APP_RESOURCES_ENTRY", "CONFIG_NS_APP_ENTRY", "CONFIG_NS_FILE_NAME"],
2021
localBuildService: ["build"],
2122
deviceLogProvider: null,
2223
npm: ["install", "uninstall", "view", "search"],

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/MizoPro/nativescript-cli/commit/d84fcb0a0b31152a7fd079cf896d13c20df7ca58

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy