@@ -4,10 +4,11 @@ import * as _ from 'lodash';
44import { parseJson } from "./common/helpers" ;
55import { EOL } from "os" ;
66import { cache } from "./common/decorators" ;
7- import { IProjectData , INsConfig } from "./definitions/project" ;
7+ import { IProjectData , INsConfig , IProjectConfigService } from "./definitions/project" ;
88import { IAndroidResourcesMigrationService , IStaticConfig , IOptions } from "./declarations" ;
99import { IStringDictionary , IFileSystem , IErrors , IProjectHelper } from "./common/declarations" ;
1010import { injector } from "./common/yok" ;
11+ import { IInjector } from "./common/definitions/yok" ;
1112
1213interface IProjectType {
1314 type : string ;
@@ -82,9 +83,14 @@ export class ProjectData implements IProjectData {
8283 private $projectHelper : IProjectHelper ,
8384 private $staticConfig : IStaticConfig ,
8485 private $options : IOptions ,
85- private $logger : ILogger ,
86+ private $logger : ILogger ,
87+ private $injector : IInjector ,
8688 private $androidResourcesMigrationService : IAndroidResourcesMigrationService ,
87- private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ) { }
89+ private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ) { }
90+
91+ get projectConfig ( ) : IProjectConfigService {
92+ return this . $injector . resolve ( 'projectConfigService' ) ;
93+ }
8894
8995 public initializeProjectData ( projectDir ?: string ) : void {
9096 projectDir = projectDir || this . $projectHelper . projectDir ;
@@ -95,9 +101,8 @@ export class ProjectData implements IProjectData {
95101
96102 if ( this . $fs . exists ( projectFilePath ) ) {
97103 const packageJsonContent = this . $fs . readText ( projectFilePath ) ;
98- const nsConfigContent = this . getNsConfigContent ( projectDir ) ;
99104
100- this . initializeProjectDataFromContent ( packageJsonContent , nsConfigContent , projectDir ) ;
105+ this . initializeProjectDataFromContent ( packageJsonContent , projectDir ) ;
101106 }
102107
103108 return ;
@@ -106,37 +111,27 @@ export class ProjectData implements IProjectData {
106111 this . errorInvalidProject ( projectDir ) ;
107112 }
108113
109- public initializeProjectDataFromContent ( packageJsonContent : string , nsconfigContent : string , projectDir ?: string ) : void {
114+ public initializeProjectDataFromContent ( packageJsonContent : string , projectDir ?: string ) : void {
110115 projectDir = projectDir || this . $projectHelper . projectDir || "" ;
111116 const projectFilePath = this . getProjectFilePath ( projectDir ) ;
112- // If no project found, projectDir should be null
113- let nsData = null ;
114- let nsConfig : INsConfig = null ;
117+ // If no project found, projectDir should be null
118+ let nsConfig : INsConfig = this . projectConfig . readConfig ( projectDir ) ;
115119 let packageJsonData = null ;
116120
117121 try {
118122 packageJsonData = parseJson ( packageJsonContent ) ;
119- nsData = packageJsonData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] ;
120123 } catch ( err ) {
121124 this . $errors . fail ( `The project file ${ this . projectFilePath } is corrupted. ${ EOL } ` +
122125 `Consider restoring an earlier version from your source control or backup.${ EOL } ` +
123126 `Additional technical info: ${ err . toString ( ) } ` ) ;
124127 }
125128
126- try {
127- nsConfig = nsconfigContent ? < INsConfig > parseJson ( nsconfigContent ) : null ;
128- } catch ( err ) {
129- this . $errors . fail ( `The NativeScript configuration file ${ constants . CONFIG_NS_FILE_NAME } is corrupted. ${ EOL } ` +
130- `Consider restoring an earlier version from your source control or backup.${ EOL } ` +
131- `Additional technical info: ${ err . toString ( ) } ` ) ;
132- }
133-
134- if ( nsData ) {
129+ if ( nsConfig ) {
135130 this . projectDir = projectDir ;
136131 this . projectName = this . $projectHelper . sanitizeName ( path . basename ( projectDir ) ) ;
137132 this . platformsDir = path . join ( projectDir , constants . PLATFORMS_DIR_NAME ) ;
138133 this . projectFilePath = projectFilePath ;
139- this . projectIdentifiers = this . initializeProjectIdentifiers ( nsData . id ) ;
134+ this . projectIdentifiers = this . initializeProjectIdentifiers ( nsConfig ) ;
140135 this . dependencies = packageJsonData . dependencies ;
141136 this . devDependencies = packageJsonData . devDependencies ;
142137 this . projectType = this . getProjectType ( ) ;
@@ -207,22 +202,8 @@ export class ProjectData implements IProjectData {
207202 return constants . APP_FOLDER_NAME ;
208203 }
209204
210- private getNsConfigContent ( projectDir : string ) : string {
211- if ( ! projectDir ) {
212- return null ;
213- }
214-
215- const configNSFilePath = path . join ( projectDir , this . getNsConfigRelativePath ( ) ) ;
216-
217- if ( ! this . $fs . exists ( configNSFilePath ) ) {
218- return null ;
219- }
220-
221- return this . $fs . readText ( configNSFilePath ) ;
222- }
223-
224205 public getNsConfigRelativePath ( ) : string {
225- return constants . CONFIG_NS_FILE_NAME ;
206+ return constants . CONFIG_FILE_NAME_JS ;
226207 }
227208
228209 private resolveToProjectDir ( pathToResolve : string , projectDir ?: string ) : string {
@@ -237,21 +218,17 @@ export class ProjectData implements IProjectData {
237218 return path . resolve ( projectDir , pathToResolve ) ;
238219 }
239220
240- private initializeProjectIdentifiers ( data : string | Mobile . IProjectIdentifier ) : Mobile . IProjectIdentifier {
241- let identifier : Mobile . IProjectIdentifier ;
242- data = data || "" ;
243-
244- if ( typeof data === "string" ) {
245- identifier = {
246- android : data ,
247- ios : data
248- } ;
249- } else {
250- identifier = {
251- android : data . android || "" ,
252- ios : data . ios || ""
253- } ;
254- }
221+ private initializeProjectIdentifiers ( config : INsConfig ) : Mobile . IProjectIdentifier {
222+ let identifier : Mobile . IProjectIdentifier = {
223+ ios : '' ,
224+ android : ''
225+ } ;
226+ if ( config . ios ) {
227+ identifier . ios = config . ios . id || config . id ;
228+ }
229+ if ( config . android ) {
230+ identifier . android = config . android . id || config . id ;
231+ }
255232
256233 return identifier ;
257234 }
0 commit comments