@@ -14,23 +14,32 @@ 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 ) ;
25
- let packageJsonFiles = [ path . join ( changedDirectoryAbsolutePath , "package.json" ) ] ;
20
+ constructor ( private inputPath : string ,
21
+ private cachePath : string ,
22
+ private outputRoot : string ,
23
+ private projectDir : string ,
24
+ private platform : string ,
25
+ private $fs : IFileSystem ,
26
+ private $projectFilesManager : IProjectFilesManager ) {
27
+ this . dependencies = Object . create ( null ) ;
28
+ this . devDependencies = this . getDevDependencies ( projectDir ) ;
29
+ }
30
+
31
+ public rebuildChangedDirectories ( changedDirectories : string [ ] , platform : string ) : void {
32
+ _ . each ( changedDirectories , changedDirectoryAbsolutePath => {
33
+ let pathToPackageJson = path . join ( changedDirectoryAbsolutePath , "package.json" ) ;
34
+ let packageJsonFiles = fs . existsSync ( pathToPackageJson ) ? [ pathToPackageJson ] : [ ] ;
26
35
let nodeModulesFolderPath = path . join ( changedDirectoryAbsolutePath , "node_modules" ) ;
27
36
packageJsonFiles = packageJsonFiles . concat ( this . enumeratePackageJsonFilesSync ( nodeModulesFolderPath ) ) ;
28
-
37
+
29
38
_ . each ( packageJsonFiles , packageJsonFilePath => {
30
39
let fileContent = require ( packageJsonFilePath ) ;
31
40
let isPlugin = fileContent . nativescript ;
32
41
33
- if ( ! devDependencies [ fileContent . name ] ) { // Don't flatten dev dependencies
42
+ if ( ! this . devDependencies [ fileContent . name ] ) { // Don't flatten dev dependencies
34
43
35
44
let currentDependency = {
36
45
name : fileContent . name ,
@@ -39,7 +48,7 @@ export class DestCopy implements IBroccoliPlugin {
39
48
isPlugin : isPlugin
40
49
} ;
41
50
42
- let addedDependency = dependencies [ currentDependency . name ] ;
51
+ let addedDependency = this . dependencies [ currentDependency . name ] ;
43
52
if ( addedDependency ) {
44
53
if ( semver . gt ( currentDependency . version , addedDependency . version ) ) {
45
54
let currentDependencyMajorVersion = semver . major ( currentDependency . version ) ;
@@ -49,22 +58,27 @@ export class DestCopy implements IBroccoliPlugin {
49
58
let logger = $injector . resolve ( "$logger" ) ;
50
59
currentDependencyMajorVersion === addedDependencyMajorVersion ? logger . out ( message ) : logger . warn ( message ) ;
51
60
52
- dependencies [ currentDependency . name ] = currentDependency ;
61
+ this . dependencies [ currentDependency . name ] = currentDependency ;
53
62
}
54
63
} else {
55
- dependencies [ currentDependency . name ] = currentDependency ;
64
+ this . dependencies [ currentDependency . name ] = currentDependency ;
56
65
}
57
66
}
58
67
} ) ;
59
68
} ) ;
60
69
61
- _ . each ( dependencies , dependency => {
62
- shelljs . cp ( "-R " , dependency . directory , this . outputRoot ) ;
70
+ _ . each ( this . dependencies , dependency => {
71
+ shelljs . cp ( "-Rf " , dependency . directory , this . outputRoot ) ;
63
72
shelljs . rm ( "-rf" , path . join ( this . outputRoot , dependency . name , "node_modules" ) ) ;
64
73
if ( dependency . isPlugin ) {
74
+ this . $projectFilesManager . processPlatformSpecificFiles ( path . join ( this . outputRoot , dependency . name ) , platform ) . wait ( ) ;
65
75
shelljs . rm ( "-rf" , path . join ( this . outputRoot , dependency . name , "platforms" ) ) ;
66
76
}
67
77
} ) ;
78
+ }
79
+
80
+ public rebuild ( treeDiff : IDiffResult ) : void {
81
+ this . rebuildChangedDirectories ( treeDiff . changedDirectories , "" ) ;
68
82
69
83
// Cache input tree
70
84
let projectFilePath = path . join ( this . projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
@@ -73,22 +87,6 @@ export class DestCopy implements IBroccoliPlugin {
73
87
fs . writeFileSync ( projectFilePath , JSON . stringify ( projectFileContent , null , "\t" ) , { encoding : "utf8" } ) ;
74
88
}
75
89
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
90
private getDevDependencies ( projectDir : string ) : IDictionary < any > {
93
91
let projectFilePath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
94
92
let projectFileContent = require ( projectFilePath ) ;
@@ -100,7 +98,10 @@ export class DestCopy implements IBroccoliPlugin {
100
98
if ( fs . existsSync ( nodeModulesDirectoryPath ) ) {
101
99
let contents = fs . readdirSync ( nodeModulesDirectoryPath ) ;
102
100
for ( let i = 0 ; i < contents . length ; ++ i ) {
103
- foundFiles . push ( path . join ( nodeModulesDirectoryPath , contents [ i ] , "package.json" ) ) ;
101
+ let packageJsonFilePath = path . join ( nodeModulesDirectoryPath , contents [ i ] , "package.json" ) ;
102
+ if ( fs . existsSync ( packageJsonFilePath ) ) {
103
+ foundFiles . push ( packageJsonFilePath ) ;
104
+ }
104
105
105
106
var directoryPath = path . join ( nodeModulesDirectoryPath , contents [ i ] , "node_modules" ) ;
106
107
if ( fs . existsSync ( directoryPath ) ) {
0 commit comments