@@ -14,23 +14,26 @@ 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 => {
27
+ //let changedDirectoryAbsolutePath = path.join(this.inputPath, constants.NODE_MODULES_FOLDER_NAME, changedDirectory);
25
28
let packageJsonFiles = [ path . join ( changedDirectoryAbsolutePath , "package.json" ) ] ;
26
29
let nodeModulesFolderPath = path . join ( changedDirectoryAbsolutePath , "node_modules" ) ;
27
30
packageJsonFiles = packageJsonFiles . concat ( this . enumeratePackageJsonFilesSync ( nodeModulesFolderPath ) ) ;
28
-
31
+
29
32
_ . each ( packageJsonFiles , packageJsonFilePath => {
30
33
let fileContent = require ( packageJsonFilePath ) ;
31
34
let isPlugin = fileContent . nativescript ;
32
35
33
- if ( ! devDependencies [ fileContent . name ] ) { // Don't flatten dev dependencies
36
+ if ( ! this . devDependencies [ fileContent . name ] ) { // Don't flatten dev dependencies
34
37
35
38
let currentDependency = {
36
39
name : fileContent . name ,
@@ -39,7 +42,7 @@ export class DestCopy implements IBroccoliPlugin {
39
42
isPlugin : isPlugin
40
43
} ;
41
44
42
- let addedDependency = dependencies [ currentDependency . name ] ;
45
+ let addedDependency = this . dependencies [ currentDependency . name ] ;
43
46
if ( addedDependency ) {
44
47
if ( semver . gt ( currentDependency . version , addedDependency . version ) ) {
45
48
let currentDependencyMajorVersion = semver . major ( currentDependency . version ) ;
@@ -49,22 +52,26 @@ export class DestCopy implements IBroccoliPlugin {
49
52
let logger = $injector . resolve ( "$logger" ) ;
50
53
currentDependencyMajorVersion === addedDependencyMajorVersion ? logger . out ( message ) : logger . warn ( message ) ;
51
54
52
- dependencies [ currentDependency . name ] = currentDependency ;
55
+ this . dependencies [ currentDependency . name ] = currentDependency ;
53
56
}
54
57
} else {
55
- dependencies [ currentDependency . name ] = currentDependency ;
58
+ this . dependencies [ currentDependency . name ] = currentDependency ;
56
59
}
57
60
}
58
61
} ) ;
59
62
} ) ;
60
63
61
- _ . each ( dependencies , dependency => {
64
+ _ . each ( this . dependencies , dependency => {
62
65
shelljs . cp ( "-R" , dependency . directory , this . outputRoot ) ;
63
66
shelljs . rm ( "-rf" , path . join ( this . outputRoot , dependency . name , "node_modules" ) ) ;
64
67
if ( dependency . isPlugin ) {
65
68
shelljs . rm ( "-rf" , path . join ( this . outputRoot , dependency . name , "platforms" ) ) ;
66
69
}
67
70
} ) ;
71
+ }
72
+
73
+ public rebuild ( treeDiff : IDiffResult ) : void {
74
+ this . rebuildChangedDirectories ( treeDiff . changedDirectories ) ;
68
75
69
76
// Cache input tree
70
77
let projectFilePath = path . join ( this . projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
@@ -73,22 +80,6 @@ export class DestCopy implements IBroccoliPlugin {
73
80
fs . writeFileSync ( projectFilePath , JSON . stringify ( projectFileContent , null , "\t" ) , { encoding : "utf8" } ) ;
74
81
}
75
82
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
83
private getDevDependencies ( projectDir : string ) : IDictionary < any > {
93
84
let projectFilePath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
94
85
let projectFileContent = require ( projectFilePath ) ;
0 commit comments