@@ -5,20 +5,20 @@ import { parseJson } from "./common/helpers";
55import { EOL } from "os" ;
66import { cache } from "./common/decorators" ;
77import {
8- IProjectData ,
98 INsConfig ,
109 IProjectConfigService ,
10+ IProjectData ,
1111} from "./definitions/project" ;
1212import {
1313 IAndroidResourcesMigrationService ,
14- IStaticConfig ,
1514 IOptions ,
15+ IStaticConfig ,
1616} from "./declarations" ;
1717import {
18- IStringDictionary ,
19- IFileSystem ,
2018 IErrors ,
19+ IFileSystem ,
2120 IProjectHelper ,
21+ IStringDictionary ,
2222} from "./common/declarations" ;
2323import { injector } from "./common/yok" ;
2424import { IInjector } from "./common/definitions/yok" ;
@@ -68,16 +68,19 @@ export class ProjectData implements IProjectData {
6868 public platformsDir : string ;
6969 public projectFilePath : string ;
7070 public projectIdentifiers : Mobile . IProjectIdentifier ;
71+
7172 get projectId ( ) : string {
7273 this . warnProjectId ( ) ;
7374 return this . projectIdentifiers . ios ;
7475 }
76+
7577 //just in case hook/extension modifies it.
7678 set projectId ( identifier : string ) {
7779 this . warnProjectId ( ) ;
7880 this . projectIdentifiers . ios = identifier ;
7981 this . projectIdentifiers . android = identifier ;
8082 }
83+
8184 public projectName : string ;
8285 public packageJsonData : any ;
8386 public nsConfig : INsConfig ;
@@ -137,16 +140,23 @@ export class ProjectData implements IProjectData {
137140 ) : void {
138141 projectDir = projectDir || this . $projectHelper . projectDir || "" ;
139142 const projectFilePath = this . getProjectFilePath ( projectDir ) ;
140- // If no project found, projectDir should be null
141- // handle migration cases
142- let isMigrate = false ;
143- if ( this . $options . argv && this . $options . argv . _ && this . $options . argv . _ . length ) {
144- this . $logger . info ( 'this.$options.argv._[0]:' , this . $options . argv . _ [ 0 ] ) ;
145- isMigrate = this . $options . argv . _ [ 0 ] === 'migrate' ;
146- }
147- this . $logger . info ( 'about to call readConfig...' )
148- this . $logger . info ( 'isMigrate:' , isMigrate ) ;
149- const nsConfig : INsConfig = isMigrate ? null : this . projectConfig . readConfig ( projectDir ) ;
143+ // If no project found, projectDir should be null
144+ // handle migration cases
145+ let isMigrate = false ;
146+ if (
147+ this . $options . argv &&
148+ this . $options . argv . _ &&
149+ this . $options . argv . _ . length
150+ ) {
151+ this . $logger . debug (
152+ "the value of this.$options.argv._[0] is: " + this . $options . argv . _ [ 0 ]
153+ ) ;
154+ isMigrate = this . $options . argv . _ [ 0 ] === "migrate" ;
155+ }
156+ this . $logger . debug ( `'initializingProjectData, isMigrate is ${ isMigrate } .` ) ;
157+ const nsConfig : INsConfig = isMigrate
158+ ? null
159+ : this . projectConfig . readConfig ( projectDir ) ;
150160 let packageJsonData = null ;
151161
152162 try {
@@ -272,15 +282,14 @@ export class ProjectData implements IProjectData {
272282 public getAppDirectoryRelativePath ( ) : string {
273283 if ( this . nsConfig && this . nsConfig [ constants . CONFIG_NS_APP_ENTRY ] ) {
274284 return this . nsConfig [ constants . CONFIG_NS_APP_ENTRY ] ;
275- }
276-
277- if ( this . $fs . exists ( path . resolve ( this . projectDir , constants . SRC_DIR ) ) ) {
278- return constants . SRC_DIR ;
279- } else {
280- // legacy project setup often uses app folder
281- return constants . APP_FOLDER_NAME ;
282- }
285+ }
283286
287+ if ( this . $fs . exists ( path . resolve ( this . projectDir , constants . SRC_DIR ) ) ) {
288+ return constants . SRC_DIR ;
289+ } else {
290+ // legacy project setup often uses app folder
291+ return constants . APP_FOLDER_NAME ;
292+ }
284293 }
285294
286295 public getNsConfigRelativePath ( ) : string {
@@ -305,27 +314,27 @@ export class ProjectData implements IProjectData {
305314 private initializeProjectIdentifiers (
306315 config : INsConfig
307316 ) : Mobile . IProjectIdentifier {
308- if ( config ) {
309- const identifier : Mobile . IProjectIdentifier = {
310- ios : config . id ,
311- android : config . id ,
312- } ;
313-
314- if ( config . ios && config . ios . id ) {
315- identifier . ios = config . ios . id ;
316- }
317- if ( config . android && config . android . id ) {
318- identifier . android = config . android . id ;
319- }
320-
321- return identifier ;
322- } else {
323- // when migrating projects this can be ignored
324- return {
325- ios : '' ,
326- android : ''
327- } ;
328- }
317+ if ( config ) {
318+ const identifier : Mobile . IProjectIdentifier = {
319+ ios : config . id ,
320+ android : config . id ,
321+ } ;
322+
323+ if ( config . ios && config . ios . id ) {
324+ identifier . ios = config . ios . id ;
325+ }
326+ if ( config . android && config . android . id ) {
327+ identifier . android = config . android . id ;
328+ }
329+
330+ return identifier ;
331+ } else {
332+ // when migrating projects this can be ignored
333+ return {
334+ ios : "" ,
335+ android : "" ,
336+ } ;
337+ }
329338 }
330339
331340 private getProjectType ( ) : string {
@@ -360,4 +369,5 @@ export class ProjectData implements IProjectData {
360369 ) ;
361370 }
362371}
372+
363373injector . register ( "projectData" , ProjectData , true ) ;
0 commit comments