@@ -14,23 +14,25 @@ import constants = require("./../../constants");
14
14
* and tees a copy to the given path outside the tmp dir.
15
15
*/
16
16
export class DestCopy implements IBroccoliPlugin {
17
- constructor ( private inputPath : string , private cachePath : string , private outputRoot : string , private projectDir : string ) { }
18
-
19
- public rebuild ( treeDiff : IDiffResult ) : void {
20
- let dependencies = this . getDependencies ( ) ;
21
- let devDependencies = this . getDevDependencies ( this . projectDir ) ;
17
+ private dependencies : IDictionary < any > = null ;
18
+ private devDependencies : IDictionary < any > = null ;
22
19
23
- treeDiff . changedDirectories . forEach ( changedDirectory => {
24
- let changedDirectoryAbsolutePath = path . join ( this . inputPath , constants . NODE_MODULES_FOLDER_NAME , changedDirectory ) ;
20
+ constructor ( private inputPath : string , private cachePath : string , private outputRoot : string , private projectDir : string ) {
21
+ this . dependencies = Object . create ( null ) ;
22
+ this . devDependencies = this . getDevDependencies ( projectDir ) ;
23
+ }
24
+
25
+ public rebuildChangedDirectories ( changedDirectories : string [ ] ) : void {
26
+ _ . each ( changedDirectories , changedDirectoryAbsolutePath => {
25
27
let packageJsonFiles = [ path . join ( changedDirectoryAbsolutePath , "package.json" ) ] ;
26
28
let nodeModulesFolderPath = path . join ( changedDirectoryAbsolutePath , "node_modules" ) ;
27
29
packageJsonFiles = packageJsonFiles . concat ( this . enumeratePackageJsonFilesSync ( nodeModulesFolderPath ) ) ;
28
-
30
+
29
31
_ . each ( packageJsonFiles , packageJsonFilePath => {
30
32
let fileContent = require ( packageJsonFilePath ) ;
31
33
let isPlugin = fileContent . nativescript ;
32
34
33
- if ( ! devDependencies [ fileContent . name ] ) { // Don't flatten dev dependencies
35
+ if ( ! this . devDependencies [ fileContent . name ] ) { // Don't flatten dev dependencies
34
36
35
37
let currentDependency = {
36
38
name : fileContent . name ,
@@ -39,7 +41,7 @@ export class DestCopy implements IBroccoliPlugin {
39
41
isPlugin : isPlugin
40
42
} ;
41
43
42
- let addedDependency = dependencies [ currentDependency . name ] ;
44
+ let addedDependency = this . dependencies [ currentDependency . name ] ;
43
45
if ( addedDependency ) {
44
46
if ( semver . gt ( currentDependency . version , addedDependency . version ) ) {
45
47
let currentDependencyMajorVersion = semver . major ( currentDependency . version ) ;
@@ -49,22 +51,26 @@ export class DestCopy implements IBroccoliPlugin {
49
51
let logger = $injector . resolve ( "$logger" ) ;
50
52
currentDependencyMajorVersion === addedDependencyMajorVersion ? logger . out ( message ) : logger . warn ( message ) ;
51
53
52
- dependencies [ currentDependency . name ] = currentDependency ;
54
+ this . dependencies [ currentDependency . name ] = currentDependency ;
53
55
}
54
56
} else {
55
- dependencies [ currentDependency . name ] = currentDependency ;
57
+ this . dependencies [ currentDependency . name ] = currentDependency ;
56
58
}
57
59
}
58
60
} ) ;
59
61
} ) ;
60
62
61
- _ . each ( dependencies , dependency => {
62
- shelljs . cp ( "-R " , dependency . directory , this . outputRoot ) ;
63
+ _ . each ( this . dependencies , dependency => {
64
+ shelljs . cp ( "-Rf " , dependency . directory , this . outputRoot ) ;
63
65
shelljs . rm ( "-rf" , path . join ( this . outputRoot , dependency . name , "node_modules" ) ) ;
64
66
if ( dependency . isPlugin ) {
65
67
shelljs . rm ( "-rf" , path . join ( this . outputRoot , dependency . name , "platforms" ) ) ;
66
68
}
67
69
} ) ;
70
+ }
71
+
72
+ public rebuild ( treeDiff : IDiffResult ) : void {
73
+ this . rebuildChangedDirectories ( treeDiff . changedDirectories ) ;
68
74
69
75
// Cache input tree
70
76
let projectFilePath = path . join ( this . projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
@@ -73,22 +79,6 @@ export class DestCopy implements IBroccoliPlugin {
73
79
fs . writeFileSync ( projectFilePath , JSON . stringify ( projectFileContent , null , "\t" ) , { encoding : "utf8" } ) ;
74
80
}
75
81
76
- private getDependencies ( ) : IDictionary < any > {
77
- let result = Object . create ( null ) ;
78
- if ( fs . existsSync ( this . outputRoot ) ) {
79
- let dirs = fs . readdirSync ( this . outputRoot ) ;
80
- _ . each ( dirs , dir => {
81
- let filePath = path . join ( dir , constants . PACKAGE_JSON_FILE_NAME ) ;
82
- if ( fs . existsSync ( filePath ) ) {
83
- let fileContent = require ( filePath ) ;
84
- result [ fileContent . name ] = fileContent ;
85
- }
86
- } ) ;
87
- }
88
-
89
- return result ;
90
- }
91
-
92
82
private getDevDependencies ( projectDir : string ) : IDictionary < any > {
93
83
let projectFilePath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
94
84
let projectFileContent = require ( projectFilePath ) ;
0 commit comments