Skip to content

Commit 79d744b

Browse files
KristianDDpetekanev
authored andcommitted
chore(nsconfig): fix comments
1 parent 797ba82 commit 79d744b

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

lib/definitions/project.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ interface IProjectService {
5353
isValidNativeScriptProject(pathToProject?: string): boolean;
5454
}
5555

56+
interface INsConfig {
57+
appPath?: string;
58+
appResourcesPath?:string;
59+
}
60+
5661
interface IProjectData extends IProjectDir {
5762
projectName: string;
5863
platformsDir: string;
@@ -63,7 +68,7 @@ interface IProjectData extends IProjectDir {
6368
appDirectoryPath: string;
6469
appResourcesDirectoryPath: string;
6570
projectType: string;
66-
nsConfig: any;
71+
nsConfig: INsConfig;
6772
/**
6873
* Initializes project data with the given project directory. If none supplied defaults to --path option or cwd.
6974
* @param {string} projectDir Project root directory.

lib/project-data.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ export class ProjectData implements IProjectData {
5555
const projectFilePath = this.getProjectFilePath(projectDir);
5656

5757
if (this.$fs.exists(projectFilePath)) {
58-
let packageJsonContent: any = null;
59-
packageJsonContent = this.$fs.readText(projectFilePath);
60-
const nsConfigContent: any = this.getNsConfigContent(projectDir);
58+
const packageJsonContent = this.$fs.readText(projectFilePath);
59+
const nsConfigContent = this.getNsConfigContent(projectDir);
6160

6261
this.initializeProjectDataFromContent(packageJsonContent, nsConfigContent, projectDir);
6362
}
@@ -72,9 +71,9 @@ export class ProjectData implements IProjectData {
7271
projectDir = projectDir || this.$projectHelper.projectDir || "";
7372
const projectFilePath = this.getProjectFilePath(projectDir);
7473
// If no project found, projectDir should be null
75-
let nsData: any = null;
76-
let nsConfig: any = null;
77-
let packageJsonData: any = null;
74+
let nsData = null;
75+
let nsConfig: INsConfig = null;
76+
let packageJsonData = null;
7877

7978
try {
8079
packageJsonData = parseJson(packageJsonContent);
@@ -86,7 +85,7 @@ export class ProjectData implements IProjectData {
8685
}
8786

8887
try {
89-
nsConfig = nsconfigContent ? parseJson(nsconfigContent) : null;
88+
nsConfig = nsconfigContent ? <INsConfig>parseJson(nsconfigContent) : null;
9089
} catch (err) {
9190
this.$errors.failWithoutHelp(`The NativeScript configuration file ${constants.CONFIG_NS_FILE_NAME} is corrupted. ${EOL}` +
9291
`Consider restoring an earlier version from your source control or backup.${EOL}` +
@@ -125,15 +124,9 @@ export class ProjectData implements IProjectData {
125124
}
126125

127126
public getAppResourcesDirectoryPath(projectDir?: string): string {
128-
if (!projectDir) {
129-
projectDir = this.projectDir;
130-
}
131-
132-
if (!projectDir) {
133-
return null;
134-
}
127+
const appResourcesRelativePath = this.getAppResourcesRelativeDirectoryPath();
135128

136-
return path.resolve(projectDir, this.getAppResourcesRelativeDirectoryPath());
129+
return this.resolveToProjectDir(appResourcesRelativePath, projectDir);
137130
}
138131

139132
public getAppResourcesRelativeDirectoryPath(): string {
@@ -145,15 +138,9 @@ export class ProjectData implements IProjectData {
145138
}
146139

147140
public getAppDirectoryPath(projectDir?: string): string {
148-
if (!projectDir) {
149-
projectDir = this.projectDir;
150-
}
151-
152-
if (!projectDir) {
153-
return null;
154-
}
141+
const appRelativePath = this.getAppDirectoryRelativePath();
155142

156-
return path.resolve(projectDir, this.getAppDirectoryRelativePath());
143+
return this.resolveToProjectDir(appRelativePath, projectDir);
157144
}
158145

159146
public getAppDirectoryRelativePath(): string {
@@ -174,6 +161,18 @@ export class ProjectData implements IProjectData {
174161
return this.$fs.readText(configNSFilePath);
175162
}
176163

164+
private resolveToProjectDir(pathToResolve: string, projectDir?: string): string {
165+
if (!projectDir) {
166+
projectDir = this.projectDir;
167+
}
168+
169+
if (!projectDir) {
170+
return null;
171+
}
172+
173+
return path.resolve(projectDir, pathToResolve);
174+
}
175+
177176
private getProjectType(): string {
178177
let detectedProjectType = _.find(ProjectData.PROJECT_TYPES, (projectType) => projectType.isDefaultProjectType).type;
179178

lib/services/app-files-updater.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ export class AppFilesUpdater {
7878

7979
// exclude the app_resources directory from being enumerated
8080
// for copying if it is present in the application sources dir
81-
const appResourcesPath = projectData.appResourcesDirectoryPath;
82-
sourceFiles = sourceFiles.filter(dirName => !path.normalize(dirName).startsWith(path.normalize(appResourcesPath)));
81+
const appResourcesPathNormalized = path.normalize(projectData.appResourcesDirectoryPath);
82+
sourceFiles = sourceFiles.filter(dirName => !path.normalize(dirName).startsWith(appResourcesPathNormalized));
8383

8484
return sourceFiles;
8585
}

lib/services/prepare-platform-js-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class PreparePlatformJSService extends PreparePlatformService implements
103103
}
104104
}
105105

106-
private copyAppResourcesFiles(config: IPreparePlatformJSInfo) {
106+
private copyAppResourcesFiles(config: IPreparePlatformJSInfo): void {
107107
const appDestinationDirectoryPath = path.join(config.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
108108
const appResourcesSourcePath = config.projectData.appResourcesDirectoryPath;
109109

lib/services/project-data-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class ProjectDataService implements IProjectDataService {
3636

3737
// TODO: Add tests
3838
// TODO: Remove $projectData and replace it with $projectDataService.getProjectData
39+
@exported("projectDataService")
3940
public getProjectData(projectDir: string): IProjectData {
4041
const projectDataInstance = this.$injector.resolve<IProjectData>(ProjectData);
4142
projectDataInstance.initializeProjectData(projectDir);

0 commit comments

Comments
 (0)