Skip to content

Commit

Permalink
chore(nsconfig): fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KristianDD authored and petekanev committed Feb 26, 2018
1 parent 797ba82 commit 79d744b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
7 changes: 6 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ interface IProjectService {
isValidNativeScriptProject(pathToProject?: string): boolean;
}

interface INsConfig {
appPath?: string;
appResourcesPath?:string;
}

interface IProjectData extends IProjectDir {
projectName: string;
platformsDir: string;
Expand All @@ -63,7 +68,7 @@ interface IProjectData extends IProjectDir {
appDirectoryPath: string;
appResourcesDirectoryPath: string;
projectType: string;
nsConfig: any;
nsConfig: INsConfig;
/**
* Initializes project data with the given project directory. If none supplied defaults to --path option or cwd.
* @param {string} projectDir Project root directory.
Expand Down
45 changes: 22 additions & 23 deletions lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ export class ProjectData implements IProjectData {
const projectFilePath = this.getProjectFilePath(projectDir);

if (this.$fs.exists(projectFilePath)) {
let packageJsonContent: any = null;
packageJsonContent = this.$fs.readText(projectFilePath);
const nsConfigContent: any = this.getNsConfigContent(projectDir);
const packageJsonContent = this.$fs.readText(projectFilePath);
const nsConfigContent = this.getNsConfigContent(projectDir);

this.initializeProjectDataFromContent(packageJsonContent, nsConfigContent, projectDir);
}
Expand All @@ -72,9 +71,9 @@ export class ProjectData implements IProjectData {
projectDir = projectDir || this.$projectHelper.projectDir || "";
const projectFilePath = this.getProjectFilePath(projectDir);
// If no project found, projectDir should be null
let nsData: any = null;
let nsConfig: any = null;
let packageJsonData: any = null;
let nsData = null;
let nsConfig: INsConfig = null;
let packageJsonData = null;

try {
packageJsonData = parseJson(packageJsonContent);
Expand All @@ -86,7 +85,7 @@ export class ProjectData implements IProjectData {
}

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

public getAppResourcesDirectoryPath(projectDir?: string): string {
if (!projectDir) {
projectDir = this.projectDir;
}

if (!projectDir) {
return null;
}
const appResourcesRelativePath = this.getAppResourcesRelativeDirectoryPath();

return path.resolve(projectDir, this.getAppResourcesRelativeDirectoryPath());
return this.resolveToProjectDir(appResourcesRelativePath, projectDir);
}

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

public getAppDirectoryPath(projectDir?: string): string {
if (!projectDir) {
projectDir = this.projectDir;
}

if (!projectDir) {
return null;
}
const appRelativePath = this.getAppDirectoryRelativePath();

return path.resolve(projectDir, this.getAppDirectoryRelativePath());
return this.resolveToProjectDir(appRelativePath, projectDir);
}

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

private resolveToProjectDir(pathToResolve: string, projectDir?: string): string {
if (!projectDir) {
projectDir = this.projectDir;
}

if (!projectDir) {
return null;
}

return path.resolve(projectDir, pathToResolve);
}

private getProjectType(): string {
let detectedProjectType = _.find(ProjectData.PROJECT_TYPES, (projectType) => projectType.isDefaultProjectType).type;

Expand Down
4 changes: 2 additions & 2 deletions lib/services/app-files-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export class AppFilesUpdater {

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

return sourceFiles;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/prepare-platform-js-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class PreparePlatformJSService extends PreparePlatformService implements
}
}

private copyAppResourcesFiles(config: IPreparePlatformJSInfo) {
private copyAppResourcesFiles(config: IPreparePlatformJSInfo): void {
const appDestinationDirectoryPath = path.join(config.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
const appResourcesSourcePath = config.projectData.appResourcesDirectoryPath;

Expand Down
1 change: 1 addition & 0 deletions lib/services/project-data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class ProjectDataService implements IProjectDataService {

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

0 comments on commit 79d744b

Please sign in to comment.