1
1
import * as path from "path" ;
2
- import { NODE_MODULES_FOLDER_NAME , NativePlatformStatus , PACKAGE_JSON_FILE_NAME , APP_GRADLE_FILE_NAME , BUILD_XCCONFIG_FILE_NAME } from "../constants" ;
2
+ import { NativePlatformStatus , PACKAGE_JSON_FILE_NAME , APP_GRADLE_FILE_NAME , BUILD_XCCONFIG_FILE_NAME , PLATFORMS_DIR_NAME } from "../constants" ;
3
3
import { getHash , hook } from "../common/helpers" ;
4
4
import { PrepareData } from "../data/prepare-data" ;
5
5
@@ -8,24 +8,20 @@ const prepareInfoFileName = ".nsprepareinfo";
8
8
class ProjectChangesInfo implements IProjectChangesInfo {
9
9
10
10
public appResourcesChanged : boolean ;
11
- public modulesChanged : boolean ;
12
11
public configChanged : boolean ;
13
- public packageChanged : boolean ;
14
12
public nativeChanged : boolean ;
15
13
public signingChanged : boolean ;
16
14
public nativePlatformStatus : NativePlatformStatus ;
17
15
18
16
public get hasChanges ( ) : boolean {
19
- return this . packageChanged ||
17
+ return this . nativeChanged ||
20
18
this . appResourcesChanged ||
21
- this . modulesChanged ||
22
19
this . configChanged ||
23
20
this . signingChanged ;
24
21
}
25
22
26
23
public get changesRequireBuild ( ) : boolean {
27
- return this . packageChanged ||
28
- this . appResourcesChanged ||
24
+ return this . appResourcesChanged ||
29
25
this . nativeChanged ;
30
26
}
31
27
@@ -39,15 +35,15 @@ export class ProjectChangesService implements IProjectChangesService {
39
35
40
36
private _changesInfo : IProjectChangesInfo ;
41
37
private _prepareInfo : IPrepareInfo ;
42
- private _newFiles : number = 0 ;
43
38
private _outputProjectMtime : number ;
44
39
private _outputProjectCTime : number ;
45
40
46
41
constructor (
47
42
private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
48
43
private $fs : IFileSystem ,
49
44
private $logger : ILogger ,
50
- public $hooksService : IHooksService ) {
45
+ public $hooksService : IHooksService ,
46
+ private $nodeModulesDependenciesBuilder : INodeModulesDependenciesBuilder ) {
51
47
}
52
48
53
49
public get currentChanges ( ) : IProjectChangesInfo {
@@ -59,26 +55,24 @@ export class ProjectChangesService implements IProjectChangesService {
59
55
this . _changesInfo = new ProjectChangesInfo ( ) ;
60
56
const isNewPrepareInfo = await this . ensurePrepareInfo ( platformData , projectData , prepareData ) ;
61
57
if ( ! isNewPrepareInfo ) {
62
- this . _newFiles = 0 ;
63
-
64
- this . _changesInfo . packageChanged = this . isProjectFileChanged ( projectData . projectDir , platformData ) ;
65
-
66
58
const platformResourcesDir = path . join ( projectData . appResourcesDirectoryPath , platformData . normalizedPlatformName ) ;
67
- this . _changesInfo . appResourcesChanged = this . containsNewerFiles ( platformResourcesDir , null , projectData ) ;
68
- /*done because currently all node_modules are traversed, a possible improvement could be traversing only the production dependencies*/
69
- this . _changesInfo . nativeChanged = this . containsNewerFiles (
70
- path . join ( projectData . projectDir , NODE_MODULES_FOLDER_NAME ) ,
71
- path . join ( projectData . projectDir , NODE_MODULES_FOLDER_NAME , "tns-ios-inspector" ) ,
72
- projectData ,
73
- this . fileChangeRequiresBuild ) ;
59
+ this . _changesInfo . appResourcesChanged = this . containsNewerFiles ( platformResourcesDir , projectData ) ;
60
+
61
+ this . $nodeModulesDependenciesBuilder . getProductionDependencies ( projectData . projectDir )
62
+ . filter ( dep => dep . nativescript && this . $fs . exists ( path . join ( dep . directory , PLATFORMS_DIR_NAME , platformData . platformNameLowerCase ) ) )
63
+ . forEach ( dep => {
64
+ this . _changesInfo . nativeChanged = this . _changesInfo . nativeChanged ||
65
+ this . containsNewerFiles ( path . join ( dep . directory , PLATFORMS_DIR_NAME , platformData . platformNameLowerCase ) , projectData ) ||
66
+ this . isFileModified ( path . join ( dep . directory , PACKAGE_JSON_FILE_NAME ) ) ;
67
+ } ) ;
68
+
69
+ if ( ! this . _changesInfo . nativeChanged ) {
70
+ this . _prepareInfo . projectFileHash = this . getProjectFileStrippedHash ( projectData . projectDir , platformData ) ;
71
+ this . _changesInfo . nativeChanged = this . isProjectFileChanged ( projectData . projectDir , platformData ) ;
72
+ }
74
73
75
74
this . $logger . trace ( `Set nativeChanged to ${ this . _changesInfo . nativeChanged } .` ) ;
76
75
77
- if ( this . _newFiles > 0 || this . _changesInfo . nativeChanged ) {
78
- this . $logger . trace ( `Setting modulesChanged to true, newFiles: ${ this . _newFiles } , nativeChanged: ${ this . _changesInfo . nativeChanged } ` ) ;
79
- this . _changesInfo . modulesChanged = true ;
80
- }
81
-
82
76
if ( platformData . platformNameLowerCase === this . $devicePlatformsConstants . iOS . toLowerCase ( ) ) {
83
77
this . _changesInfo . configChanged = this . filesChanged ( [ path . join ( platformResourcesDir , platformData . configurationFileName ) ,
84
78
path . join ( platformResourcesDir , "LaunchScreen.storyboard" ) ,
@@ -101,16 +95,11 @@ export class ProjectChangesService implements IProjectChangesService {
101
95
if ( prepareData . release !== this . _prepareInfo . release ) {
102
96
this . $logger . trace ( `Setting all setting to true. Current options are: ` , prepareData , " old prepare info is: " , this . _prepareInfo ) ;
103
97
this . _changesInfo . appResourcesChanged = true ;
104
- this . _changesInfo . modulesChanged = true ;
105
98
this . _changesInfo . configChanged = true ;
106
99
this . _prepareInfo . release = prepareData . release ;
107
100
}
108
- if ( this . _changesInfo . packageChanged ) {
109
- this . $logger . trace ( "Set modulesChanged to true as packageChanged is true" ) ;
110
- this . _changesInfo . modulesChanged = true ;
111
- }
112
- if ( this . _changesInfo . modulesChanged || this . _changesInfo . appResourcesChanged ) {
113
- this . $logger . trace ( `Set configChanged to true, current value of moduleChanged is: ${ this . _changesInfo . modulesChanged } , appResourcesChanged is: ${ this . _changesInfo . appResourcesChanged } ` ) ;
101
+ if ( this . _changesInfo . appResourcesChanged ) {
102
+ this . $logger . trace ( `Set configChanged to true, appResourcesChanged is: ${ this . _changesInfo . appResourcesChanged } ` ) ;
114
103
this . _changesInfo . configChanged = true ;
115
104
}
116
105
if ( this . _changesInfo . hasChanges ) {
@@ -119,8 +108,6 @@ export class ProjectChangesService implements IProjectChangesService {
119
108
if ( this . _prepareInfo . changesRequireBuild ) {
120
109
this . _prepareInfo . changesRequireBuildTime = this . _prepareInfo . time ;
121
110
}
122
-
123
- this . _prepareInfo . projectFileHash = this . getProjectFileStrippedHash ( projectData . projectDir , platformData ) ;
124
111
}
125
112
126
113
this . _changesInfo . nativePlatformStatus = this . _prepareInfo . nativePlatformStatus ;
@@ -191,7 +178,6 @@ export class ProjectChangesService implements IProjectChangesService {
191
178
this . _outputProjectCTime = 0 ;
192
179
this . _changesInfo = this . _changesInfo || new ProjectChangesInfo ( ) ;
193
180
this . _changesInfo . appResourcesChanged = true ;
194
- this . _changesInfo . modulesChanged = true ;
195
181
this . _changesInfo . configChanged = true ;
196
182
return true ;
197
183
}
@@ -229,48 +215,33 @@ export class ProjectChangesService implements IProjectChangesService {
229
215
return false ;
230
216
}
231
217
232
- private containsNewerFiles ( dir : string , skipDir : string , projectData : IProjectData , processFunc ?: ( filePath : string , projectData : IProjectData ) => boolean ) : boolean {
218
+ private containsNewerFiles ( dir : string , projectData : IProjectData ) : boolean {
233
219
const dirName = path . basename ( dir ) ;
234
220
this . $logger . trace ( `containsNewerFiles will check ${ dir } ` ) ;
235
221
if ( _ . startsWith ( dirName , '.' ) ) {
236
222
this . $logger . trace ( `containsNewerFiles returns false for ${ dir } as its name starts with dot (.) .` ) ;
237
223
return false ;
238
224
}
239
225
240
- const dirFileStat = this . $fs . getFsStats ( dir ) ;
241
- if ( this . isFileModified ( dirFileStat , dir ) ) {
226
+ if ( this . isFileModified ( dir ) ) {
242
227
this . $logger . trace ( `containsNewerFiles returns true for ${ dir } as the dir itself has been modified.` ) ;
243
228
return true ;
244
229
}
245
230
246
231
const files = this . $fs . readDirectory ( dir ) ;
247
232
for ( const file of files ) {
248
233
const filePath = path . join ( dir , file ) ;
249
- if ( filePath === skipDir ) {
250
- continue ;
251
- }
252
234
253
235
const fileStats = this . $fs . getFsStats ( filePath ) ;
254
- const changed = this . isFileModified ( fileStats , filePath ) ;
236
+ const changed = this . isFileModified ( filePath , fileStats ) ;
255
237
256
238
if ( changed ) {
257
- this . $logger . trace ( `File ${ filePath } has been changed.` ) ;
258
- if ( processFunc ) {
259
- this . _newFiles ++ ;
260
- this . $logger . trace ( `Incremented the newFiles counter. Current value is ${ this . _newFiles } ` ) ;
261
- const filePathRelative = path . relative ( projectData . projectDir , filePath ) ;
262
- if ( processFunc . call ( this , filePathRelative , projectData ) ) {
263
- this . $logger . trace ( `containsNewerFiles returns true for ${ dir } . The modified file is ${ filePath } ` ) ;
264
- return true ;
265
- }
266
- } else {
267
- this . $logger . trace ( `containsNewerFiles returns true for ${ dir } . The modified file is ${ filePath } ` ) ;
268
- return true ;
269
- }
239
+ this . $logger . trace ( `containsNewerFiles returns true for ${ dir } . The modified file is ${ filePath } ` ) ;
240
+ return true ;
270
241
}
271
242
272
243
if ( fileStats . isDirectory ( ) ) {
273
- if ( this . containsNewerFiles ( filePath , skipDir , projectData , processFunc ) ) {
244
+ if ( this . containsNewerFiles ( filePath , projectData ) ) {
274
245
this . $logger . trace ( `containsNewerFiles returns true for ${ dir } .` ) ;
275
246
return true ;
276
247
}
@@ -281,9 +252,10 @@ export class ProjectChangesService implements IProjectChangesService {
281
252
return false ;
282
253
}
283
254
284
- private isFileModified ( filePathStat : IFsStats , filePath : string ) : boolean {
285
- let changed = filePathStat . mtime . getTime ( ) >= this . _outputProjectMtime ||
286
- filePathStat . ctime . getTime ( ) >= this . _outputProjectCTime ;
255
+ private isFileModified ( filePath : string , filePathStats ?: IFsStats ) : boolean {
256
+ filePathStats = filePathStats || this . $fs . getFsStats ( filePath ) ;
257
+ let changed = filePathStats . mtime . getTime ( ) >= this . _outputProjectMtime ||
258
+ filePathStats . ctime . getTime ( ) >= this . _outputProjectCTime ;
287
259
288
260
if ( ! changed ) {
289
261
const lFileStats = this . $fs . getLsStats ( filePath ) ;
@@ -293,29 +265,5 @@ export class ProjectChangesService implements IProjectChangesService {
293
265
294
266
return changed ;
295
267
}
296
-
297
- private fileChangeRequiresBuild ( file : string , projectData : IProjectData ) {
298
- if ( path . basename ( file ) === PACKAGE_JSON_FILE_NAME ) {
299
- return true ;
300
- }
301
- const projectDir = projectData . projectDir ;
302
- if ( _ . startsWith ( path . join ( projectDir , file ) , projectData . appResourcesDirectoryPath ) ) {
303
- return true ;
304
- }
305
- if ( _ . startsWith ( file , NODE_MODULES_FOLDER_NAME ) ) {
306
- let filePath = file ;
307
- while ( filePath !== NODE_MODULES_FOLDER_NAME ) {
308
- filePath = path . dirname ( filePath ) ;
309
- const fullFilePath = path . join ( projectDir , path . join ( filePath , PACKAGE_JSON_FILE_NAME ) ) ;
310
- if ( this . $fs . exists ( fullFilePath ) ) {
311
- const json = this . $fs . readJson ( fullFilePath ) ;
312
- if ( json [ "nativescript" ] && _ . startsWith ( file , path . join ( filePath , "platforms" ) ) ) {
313
- return true ;
314
- }
315
- }
316
- }
317
- }
318
- return false ;
319
- }
320
268
}
321
269
$injector . register ( "projectChangesService" , ProjectChangesService ) ;
0 commit comments