@@ -11,88 +11,100 @@ let vinylFilterSince = require("vinyl-filter-since");
11
11
let through = require ( "through2" ) ;
12
12
13
13
export class Builder implements IBroccoliBuilder {
14
- constructor ( private $fs : IFileSystem ,
15
- private $nodeModulesTree : INodeModulesTree ,
16
- private $projectData : IProjectData ,
17
- private $projectDataService : IProjectDataService ,
18
- private $injector : IInjector ,
19
- private $logger : ILogger ) { }
20
-
21
- public getChangedNodeModules ( absoluteOutputPath : string , platform : string , lastModifiedTime ?: Date ) : IFuture < any > {
22
- return ( ( ) => {
23
- let projectDir = this . $projectData . projectDir ;
24
- let isNodeModulesModified = false ;
25
- let nodeModulesPath = path . join ( projectDir , constants . NODE_MODULES_FOLDER_NAME ) ;
26
- let nodeModules : any = { } ;
27
-
28
- if ( lastModifiedTime ) {
29
- let pipeline = gulp . src ( path . join ( projectDir , "node_modules/**" ) )
30
- . pipe ( vinylFilterSince ( lastModifiedTime ) )
31
- . pipe ( through . obj ( ( chunk : any , enc : any , cb : Function ) => {
32
- if ( chunk . path === nodeModulesPath ) {
33
- isNodeModulesModified = true ;
34
- }
35
-
36
- if ( ! isNodeModulesModified ) {
37
- let rootModuleName = chunk . path . split ( nodeModulesPath ) [ 1 ] . split ( path . sep ) [ 1 ] ;
38
- let rootModuleFullPath = path . join ( nodeModulesPath , rootModuleName ) ;
39
- nodeModules [ rootModuleFullPath ] = rootModuleFullPath ;
40
- }
41
-
42
- cb ( null ) ;
43
- } ) )
44
- . pipe ( gulp . dest ( absoluteOutputPath ) ) ;
45
-
46
- let future = new Future < void > ( ) ;
47
-
48
- pipeline . on ( 'end' , ( err : Error , data : any ) => {
49
- if ( err ) {
50
- future . throw ( err ) ;
51
- } else {
52
- future . return ( ) ;
53
- }
54
- } ) ;
55
-
56
- future . wait ( ) ;
57
- }
58
-
59
- if ( isNodeModulesModified && this . $fs . exists ( absoluteOutputPath ) . wait ( ) ) {
60
- let currentPreparedTnsModules = this . $fs . readDirectory ( absoluteOutputPath ) . wait ( ) ;
61
- let tnsModulesPath = path . join ( projectDir , constants . APP_FOLDER_NAME , constants . TNS_MODULES_FOLDER_NAME ) ;
62
- if ( ! this . $fs . exists ( tnsModulesPath ) . wait ( ) ) {
63
- tnsModulesPath = path . join ( projectDir , constants . NODE_MODULES_FOLDER_NAME , constants . TNS_CORE_MODULES_NAME ) ;
64
- }
65
- let tnsModulesInApp = this . $fs . readDirectory ( tnsModulesPath ) . wait ( ) ;
66
- let modulesToDelete = _ . difference ( currentPreparedTnsModules , tnsModulesInApp ) ;
67
- _ . each ( modulesToDelete , moduleName => this . $fs . deleteDirectory ( path . join ( absoluteOutputPath , moduleName ) ) . wait ( ) ) ;
68
- }
69
-
70
- if ( ! lastModifiedTime || isNodeModulesModified ) {
71
- let nodeModulesDirectories = this . $fs . exists ( nodeModulesPath ) . wait ( ) ? this . $fs . readDirectory ( nodeModulesPath ) . wait ( ) : [ ] ;
72
- _ . each ( nodeModulesDirectories , nodeModuleDirectoryName => {
73
- let nodeModuleFullPath = path . join ( nodeModulesPath , nodeModuleDirectoryName ) ;
74
- nodeModules [ nodeModuleFullPath ] = nodeModuleFullPath ;
75
- } ) ;
76
- }
77
-
78
- return nodeModules ;
79
- } ) . future < any > ( ) ( ) ;
80
- }
81
-
82
- public prepareNodeModules ( absoluteOutputPath : string , platform : string , lastModifiedTime ?: Date ) : IFuture < void > {
83
- return ( ( ) => {
84
- let nodeModules = this . getChangedNodeModules ( absoluteOutputPath , platform , lastModifiedTime ) . wait ( ) ;
85
- let destCopy = this . $injector . resolve ( destCopyLib . DestCopy , {
86
- inputPath : this . $projectData . projectDir ,
87
- cachePath : "" ,
88
- outputRoot : absoluteOutputPath ,
89
- projectDir : this . $projectData . projectDir ,
90
- platform : platform
91
- } ) ;
92
-
93
- destCopy . rebuildChangedDirectories ( _ . keys ( nodeModules ) ) ;
94
-
95
- } ) . future < void > ( ) ( ) ;
96
- }
14
+ constructor (
15
+ private $fs : IFileSystem ,
16
+ private $nodeModulesTree : INodeModulesTree ,
17
+ private $projectData : IProjectData ,
18
+ private $projectDataService : IProjectDataService ,
19
+ private $injector : IInjector ,
20
+ private $logger : ILogger
21
+ ) {
22
+ }
23
+
24
+ public getChangedNodeModules ( absoluteOutputPath : string , platform : string , lastModifiedTime ?: Date ) : IFuture < any > {
25
+ return ( ( ) => {
26
+ let projectDir = this . $projectData . projectDir ;
27
+ let isNodeModulesModified = false ;
28
+ let nodeModulesPath = path . join ( projectDir , constants . NODE_MODULES_FOLDER_NAME ) ;
29
+ let nodeModules : any = { } ;
30
+
31
+ if ( lastModifiedTime ) {
32
+ let pipeline = gulp . src ( path . join ( projectDir , "node_modules/**" ) )
33
+ . pipe ( vinylFilterSince ( lastModifiedTime ) )
34
+ . pipe ( through . obj ( ( chunk : any , enc : any , cb : Function ) => {
35
+ if ( chunk . path === nodeModulesPath ) {
36
+ isNodeModulesModified = true ;
37
+ }
38
+
39
+ if ( ! isNodeModulesModified ) {
40
+ let rootModuleName = chunk . path . split ( nodeModulesPath ) [ 1 ] . split ( path . sep ) [ 1 ] ;
41
+ let rootModuleFullPath = path . join ( nodeModulesPath , rootModuleName ) ;
42
+ nodeModules [ rootModuleFullPath ] = rootModuleFullPath ;
43
+ }
44
+
45
+ cb ( null ) ;
46
+ } ) )
47
+ . pipe ( gulp . dest ( absoluteOutputPath ) ) ;
48
+
49
+ let future = new Future < void > ( ) ;
50
+
51
+ pipeline . on ( 'end' , ( err : Error , data : any ) => {
52
+ if ( err ) {
53
+ future . throw ( err ) ;
54
+ } else {
55
+ future . return ( ) ;
56
+ }
57
+ } ) ;
58
+
59
+ future . wait ( ) ;
60
+ }
61
+
62
+ if ( isNodeModulesModified && this . $fs . exists ( absoluteOutputPath ) . wait ( ) ) {
63
+ let currentPreparedTnsModules = this . $fs . readDirectory ( absoluteOutputPath ) . wait ( ) ;
64
+ let tnsModulesPath = path . join ( projectDir , constants . APP_FOLDER_NAME , constants . TNS_MODULES_FOLDER_NAME ) ;
65
+ if ( ! this . $fs . exists ( tnsModulesPath ) . wait ( ) ) {
66
+ tnsModulesPath = path . join ( projectDir , constants . NODE_MODULES_FOLDER_NAME , constants . TNS_CORE_MODULES_NAME ) ;
67
+ }
68
+ let tnsModulesInApp = this . $fs . readDirectory ( tnsModulesPath ) . wait ( ) ;
69
+ let modulesToDelete = _ . difference ( currentPreparedTnsModules , tnsModulesInApp ) ;
70
+ _ . each ( modulesToDelete , moduleName => this . $fs . deleteDirectory ( path . join ( absoluteOutputPath , moduleName ) ) . wait ( ) ) ;
71
+ }
72
+
73
+ if ( ! lastModifiedTime || isNodeModulesModified ) {
74
+ this . listModules ( nodeModulesPath , nodeModules ) ;
75
+ }
76
+
77
+ return nodeModules ;
78
+ } ) . future < any > ( ) ( ) ;
79
+ }
80
+
81
+ private listModules ( nodeModulesPath : string , nodeModules : any ) : void {
82
+ let nodeModulesDirectories = this . $fs . exists ( nodeModulesPath ) . wait ( ) ? this . $fs . readDirectory ( nodeModulesPath ) . wait ( ) : [ ] ;
83
+ _ . each ( nodeModulesDirectories , nodeModuleDirectoryName => {
84
+ let isNpmScope = / ^ @ / . test ( nodeModuleDirectoryName ) ;
85
+ let nodeModuleFullPath = path . join ( nodeModulesPath , nodeModuleDirectoryName ) ;
86
+ if ( isNpmScope ) {
87
+ this . listModules ( nodeModuleFullPath , nodeModules ) ;
88
+ } else {
89
+ nodeModules [ nodeModuleFullPath ] = nodeModuleFullPath ;
90
+ }
91
+ } ) ;
92
+ }
93
+
94
+ public prepareNodeModules ( absoluteOutputPath : string , platform : string , lastModifiedTime ?: Date ) : IFuture < void > {
95
+ return ( ( ) => {
96
+ let nodeModules = this . getChangedNodeModules ( absoluteOutputPath , platform , lastModifiedTime ) . wait ( ) ;
97
+ let destCopy = this . $injector . resolve ( destCopyLib . DestCopy , {
98
+ inputPath : this . $projectData . projectDir ,
99
+ cachePath : "" ,
100
+ outputRoot : absoluteOutputPath ,
101
+ projectDir : this . $projectData . projectDir ,
102
+ platform : platform
103
+ } ) ;
104
+
105
+ destCopy . rebuildChangedDirectories ( _ . keys ( nodeModules ) ) ;
106
+
107
+ } ) . future < void > ( ) ( ) ;
108
+ }
97
109
}
98
110
$injector . register ( "broccoliBuilder" , Builder ) ;
0 commit comments