@@ -20,82 +20,76 @@ export class ProjectData implements IProjectData {
2020 private $projectHelper : IProjectHelper ,
2121 private $staticConfig : IStaticConfig ,
2222 private $options : IOptions ) {
23- this . initializeProjectData ( ) . wait ( ) ;
23+ this . initializeProjectData ( ) ;
2424 }
2525
26- private initializeProjectData ( ) : IFuture < void > {
27- return ( ( ) => {
28- let projectDir = this . $projectHelper . projectDir ;
29- // If no project found, projectDir should be null
30- if ( projectDir ) {
31- this . initializeProjectDataCore ( projectDir ) ;
32- let data : any = null ;
26+ private initializeProjectData ( ) : void {
27+ let projectDir = this . $projectHelper . projectDir ;
28+ // If no project found, projectDir should be null
29+ if ( projectDir ) {
30+ this . initializeProjectDataCore ( projectDir ) ;
31+ let data : any = null ;
3332
34- if ( this . $fs . exists ( this . projectFilePath ) ) {
35- let fileContent : any = null ;
36- try {
37- fileContent = this . $fs . readJson ( this . projectFilePath ) ;
38- data = fileContent [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] ;
39- } catch ( err ) {
40- this . $errors . fail ( {
41- formatStr : "The project file %s is corrupted." + EOL +
42- "Consider restoring an earlier version from your source control or backup." + EOL +
43- "Additional technical info: %s" ,
44- suppressCommandHelp : true
45- } ,
46- this . projectFilePath , err . toString ( ) ) ;
47- }
33+ if ( this . $fs . exists ( this . projectFilePath ) ) {
34+ let fileContent : any = null ;
35+ try {
36+ fileContent = this . $fs . readJson ( this . projectFilePath ) ;
37+ data = fileContent [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] ;
38+ } catch ( err ) {
39+ this . $errors . fail ( {
40+ formatStr : "The project file %s is corrupted." + EOL +
41+ "Consider restoring an earlier version from your source control or backup." + EOL +
42+ "Additional technical info: %s" ,
43+ suppressCommandHelp : true
44+ } ,
45+ this . projectFilePath , err . toString ( ) ) ;
46+ }
4847
49- if ( data ) {
50- this . projectId = data . id ;
51- this . dependencies = fileContent . dependencies ;
52- } else { // This is the case when we have package.json file but nativescipt key is not presented in it
53- this . tryToUpgradeProject ( ) . wait ( ) ;
54- }
48+ if ( data ) {
49+ this . projectId = data . id ;
50+ this . dependencies = fileContent . dependencies ;
51+ } else { // This is the case when we have package.json file but nativescipt key is not presented in it
52+ this . tryToUpgradeProject ( ) ;
5553 }
56- } else { // This is the case when no project file found
57- this . tryToUpgradeProject ( ) . wait ( ) ;
5854 }
59- } ) . future < void > ( ) ( ) ;
55+ } else { // This is the case when no project file found
56+ this . tryToUpgradeProject ( ) ;
57+ }
6058 }
6159
6260 private throwNoProjectFoundError ( ) : void {
6361 this . $errors . fail ( "No project found at or above '%s' and neither was a --path specified." , this . $options . path || path . resolve ( "." ) ) ;
6462 }
6563
66- private tryToUpgradeProject ( ) : IFuture < void > {
67- return ( ( ) => {
68- let projectDir = this . projectDir || path . resolve ( this . $options . path || "." ) ;
69- let oldProjectFilePath = path . join ( projectDir , ProjectData . OLD_PROJECT_FILE_NAME ) ;
70- if ( this . $fs . exists ( oldProjectFilePath ) ) {
71- this . upgrade ( projectDir , oldProjectFilePath ) . wait ( ) ;
72- } else {
73- this . throwNoProjectFoundError ( ) ;
74- }
75- } ) . future < void > ( ) ( ) ;
64+ private tryToUpgradeProject ( ) : void {
65+ let projectDir = this . projectDir || path . resolve ( this . $options . path || "." ) ;
66+ let oldProjectFilePath = path . join ( projectDir , ProjectData . OLD_PROJECT_FILE_NAME ) ;
67+ if ( this . $fs . exists ( oldProjectFilePath ) ) {
68+ this . upgrade ( projectDir , oldProjectFilePath ) ;
69+ } else {
70+ this . throwNoProjectFoundError ( ) ;
71+ }
7672 }
7773
78- private upgrade ( projectDir : string , oldProjectFilePath : string ) : IFuture < void > {
79- return ( ( ) => {
80- try {
81- let oldProjectData = this . $fs . readJson ( oldProjectFilePath ) ;
74+ private upgrade ( projectDir : string , oldProjectFilePath : string ) : void {
75+ try {
76+ let oldProjectData = this . $fs . readJson ( oldProjectFilePath ) ;
8277
83- let newProjectFilePath = this . projectFilePath || path . join ( projectDir , this . $staticConfig . PROJECT_FILE_NAME ) ;
84- let newProjectData = this . $fs . exists ( newProjectFilePath ) ? this . $fs . readJson ( newProjectFilePath ) : { } ;
85- newProjectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] = oldProjectData ;
86- this . $fs . writeJson ( newProjectFilePath , newProjectData ) . wait ( ) ;
87- this . projectId = newProjectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] . id ;
78+ let newProjectFilePath = this . projectFilePath || path . join ( projectDir , this . $staticConfig . PROJECT_FILE_NAME ) ;
79+ let newProjectData = this . $fs . exists ( newProjectFilePath ) ? this . $fs . readJson ( newProjectFilePath ) : { } ;
80+ newProjectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] = oldProjectData ;
81+ this . $fs . writeJson ( newProjectFilePath , newProjectData ) ;
82+ this . projectId = newProjectData [ this . $staticConfig . CLIENT_NAME_KEY_IN_PROJECT_FILE ] . id ;
8883
89- this . $fs . deleteFile ( oldProjectFilePath ) ;
90- } catch ( err ) {
91- this . $logger . out ( "An error occurred while upgrading your project." ) ;
92- throw err ;
93- }
84+ this . $fs . deleteFile ( oldProjectFilePath ) ;
85+ } catch ( err ) {
86+ this . $logger . out ( "An error occurred while upgrading your project." ) ;
87+ throw err ;
88+ }
9489
95- this . initializeProjectDataCore ( projectDir ) ;
90+ this . initializeProjectDataCore ( projectDir ) ;
9691
97- this . $logger . out ( "Successfully upgraded your project file." ) ;
98- } ) . future < void > ( ) ( ) ;
92+ this . $logger . out ( "Successfully upgraded your project file." ) ;
9993 }
10094
10195 private initializeProjectDataCore ( projectDir : string ) : void {
0 commit comments