@@ -14,23 +14,32 @@ import constants = require("./../../constants");
1414 * and tees a copy to the given path outside the tmp dir.
1515 */
1616export 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 ;
2219
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 ] : [ ] ;
2635 let nodeModulesFolderPath = path . join ( changedDirectoryAbsolutePath , "node_modules" ) ;
2736 packageJsonFiles = packageJsonFiles . concat ( this . enumeratePackageJsonFilesSync ( nodeModulesFolderPath ) ) ;
28-
37+
2938 _ . each ( packageJsonFiles , packageJsonFilePath => {
3039 let fileContent = require ( packageJsonFilePath ) ;
3140 let isPlugin = fileContent . nativescript ;
3241
33- if ( ! devDependencies [ fileContent . name ] ) { // Don't flatten dev dependencies
42+ if ( ! this . devDependencies [ fileContent . name ] ) { // Don't flatten dev dependencies
3443
3544 let currentDependency = {
3645 name : fileContent . name ,
@@ -39,7 +48,7 @@ export class DestCopy implements IBroccoliPlugin {
3948 isPlugin : isPlugin
4049 } ;
4150
42- let addedDependency = dependencies [ currentDependency . name ] ;
51+ let addedDependency = this . dependencies [ currentDependency . name ] ;
4352 if ( addedDependency ) {
4453 if ( semver . gt ( currentDependency . version , addedDependency . version ) ) {
4554 let currentDependencyMajorVersion = semver . major ( currentDependency . version ) ;
@@ -49,22 +58,27 @@ export class DestCopy implements IBroccoliPlugin {
4958 let logger = $injector . resolve ( "$logger" ) ;
5059 currentDependencyMajorVersion === addedDependencyMajorVersion ? logger . out ( message ) : logger . warn ( message ) ;
5160
52- dependencies [ currentDependency . name ] = currentDependency ;
61+ this . dependencies [ currentDependency . name ] = currentDependency ;
5362 }
5463 } else {
55- dependencies [ currentDependency . name ] = currentDependency ;
64+ this . dependencies [ currentDependency . name ] = currentDependency ;
5665 }
5766 }
5867 } ) ;
5968 } ) ;
6069
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 ) ;
6372 shelljs . rm ( "-rf" , path . join ( this . outputRoot , dependency . name , "node_modules" ) ) ;
6473 if ( dependency . isPlugin ) {
74+ this . $projectFilesManager . processPlatformSpecificFiles ( path . join ( this . outputRoot , dependency . name ) , platform ) . wait ( ) ;
6575 shelljs . rm ( "-rf" , path . join ( this . outputRoot , dependency . name , "platforms" ) ) ;
6676 }
6777 } ) ;
78+ }
79+
80+ public rebuild ( treeDiff : IDiffResult ) : void {
81+ this . rebuildChangedDirectories ( treeDiff . changedDirectories , "" ) ;
6882
6983 // Cache input tree
7084 let projectFilePath = path . join ( this . projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
@@ -73,22 +87,6 @@ export class DestCopy implements IBroccoliPlugin {
7387 fs . writeFileSync ( projectFilePath , JSON . stringify ( projectFileContent , null , "\t" ) , { encoding : "utf8" } ) ;
7488 }
7589
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-
9290 private getDevDependencies ( projectDir : string ) : IDictionary < any > {
9391 let projectFilePath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
9492 let projectFileContent = require ( projectFilePath ) ;
@@ -100,7 +98,10 @@ export class DestCopy implements IBroccoliPlugin {
10098 if ( fs . existsSync ( nodeModulesDirectoryPath ) ) {
10199 let contents = fs . readdirSync ( nodeModulesDirectoryPath ) ;
102100 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+ }
104105
105106 var directoryPath = path . join ( nodeModulesDirectoryPath , contents [ i ] , "node_modules" ) ;
106107 if ( fs . existsSync ( directoryPath ) ) {
0 commit comments