@@ -62,20 +62,69 @@ export class NpmPluginPrepare {
6262 ) {
6363 }
6464
65+ protected beforePrepare ( dependencies : IDictionary < IDependencyData > , platform : string ) : void {
66+ this . $platformsData . getPlatformData ( platform ) . platformProjectService . beforePrepareAllPlugins ( dependencies ) . wait ( ) ;
67+ }
68+
69+ protected afterPrepare ( dependencies : IDictionary < IDependencyData > , platform : string ) : void {
70+ this . $platformsData . getPlatformData ( platform ) . platformProjectService . afterPrepareAllPlugins ( ) . wait ( ) ;
71+ this . writePreparedDependencyInfo ( dependencies , platform ) ;
72+ }
73+
74+ private writePreparedDependencyInfo ( dependencies : IDictionary < IDependencyData > , platform : string ) : void {
75+ let prepareData : IDictionary < boolean > = { } ;
76+ _ . values ( dependencies ) . forEach ( d => {
77+ prepareData [ d . name ] = true ;
78+ } ) ;
79+ this . $fs . createDirectory ( this . preparedPlatformsDir ( platform ) ) . wait ( ) ;
80+ this . $fs . writeJson ( this . preparedPlatformsFile ( platform ) , prepareData , " " , "utf8" ) . wait ( ) ;
81+ }
82+
83+ private preparedPlatformsDir ( platform : string ) : string {
84+ const platformRoot = this . $platformsData . getPlatformData ( platform ) . projectRoot ;
85+ if ( / a n d r o i d / i. test ( platform ) ) {
86+ return path . join ( platformRoot , "build" , "intermediates" ) ;
87+ } else if ( / i o s / i. test ( platform ) ) {
88+ return path . join ( platformRoot , "build" ) ;
89+ } else {
90+ throw new Error ( "Invalid platform: " + platform ) ;
91+ }
92+ }
93+
94+ private preparedPlatformsFile ( platform : string ) : string {
95+ return path . join ( this . preparedPlatformsDir ( platform ) , "prepared-platforms.json" ) ;
96+ }
97+
98+ protected getPreviouslyPreparedDependencies ( platform : string ) : IDictionary < boolean > {
99+ if ( ! this . $fs . exists ( this . preparedPlatformsFile ( platform ) ) . wait ( ) ) {
100+ return { } ;
101+ }
102+ return this . $fs . readJson ( this . preparedPlatformsFile ( platform ) , "utf8" ) . wait ( ) ;
103+ }
104+
105+ private allPrepared ( dependencies : IDictionary < IDependencyData > , platform : string ) : boolean {
106+ let result = true ;
107+ const previouslyPrepared = this . getPreviouslyPreparedDependencies ( platform ) ;
108+ _ . values ( dependencies ) . forEach ( d => {
109+ if ( ! previouslyPrepared [ d . name ] ) {
110+ result = false ;
111+ }
112+ } ) ;
113+ return result ;
114+ }
115+
65116 public preparePlugins ( dependencies : IDictionary < IDependencyData > , platform : string ) : void {
66- if ( _ . isEmpty ( dependencies ) ) {
117+ if ( _ . isEmpty ( dependencies ) || this . allPrepared ( dependencies , platform ) ) {
67118 return ;
68119 }
69120
70- this . $platformsData . getPlatformData ( platform ) . platformProjectService . beforePrepareAllPlugins ( dependencies ) . wait ( ) ;
71-
121+ this . beforePrepare ( dependencies , platform ) ;
72122 _ . each ( dependencies , dependency => {
73123 let isPlugin = ! ! dependency . nativescript ;
74124 if ( isPlugin ) {
75- console . log ( "preparing: " + dependency . name ) ;
76125 this . $pluginsService . prepare ( dependency , platform ) . wait ( ) ;
77126 }
78127 } ) ;
79- this . $platformsData . getPlatformData ( platform ) . platformProjectService . afterPrepareAllPlugins ( ) . wait ( ) ;
128+ this . afterPrepare ( dependencies , platform ) ;
80129 }
81130}
0 commit comments