1
1
const { rollup } = require ( 'rollup' ) ;
2
2
const { spawn } = require ( 'child_process' ) ;
3
3
const { Observable } = require ( 'rxjs' ) ;
4
- const { copy, readFileSync } = require ( 'fs-extra' ) ;
4
+ const { copy, readFileSync, writeFile } = require ( 'fs-extra' ) ;
5
5
const { prettySize } = require ( 'pretty-size' ) ;
6
6
const gzipSize = require ( 'gzip-size' ) ;
7
7
@@ -32,7 +32,16 @@ const GLOBALS = {
32
32
'angularfire2' : 'angularfire2'
33
33
} ;
34
34
35
- // constants for running typescript commands
35
+ // Map of dependency versions across all packages
36
+ const VERSIONS = {
37
+ ANGULAR_VERSION : '^4.0.0' ,
38
+ FIREBASE_VERSION : '^4.0.0' ,
39
+ RXJS_VERSION : '^5.0.1' ,
40
+ ZONEJS_VERSION : '^0.8.0' ,
41
+ ANGULARFIRE2_VERSION : '4.0.0-rc.2'
42
+ } ;
43
+
44
+ // Constants for running typescript commands
36
45
const TSC = 'node_modules/.bin/tsc' ;
37
46
const NGC = 'node_modules/.bin/ngc' ;
38
47
const TSC_ARGS = ( name , config = 'build' ) => [ `-p` , `${ process . cwd ( ) } /src/${ name } /tsconfig-${ config } .json` ] ;
@@ -52,6 +61,11 @@ function spawnObservable(command, args) {
52
61
} ) ;
53
62
}
54
63
64
+ /**
65
+ * Create a UMD bundle given a module name
66
+ * @param {string } name
67
+ * @param {Object } globals
68
+ */
55
69
function createUmd ( name , globals ) {
56
70
// core module is angularfire2 the rest are angularfire2.feature
57
71
const moduleName = name === 'core' ? 'angularfire2' : `angularfire2.${ name } ` ;
@@ -76,6 +90,10 @@ function createUmd(name, globals) {
76
90
} ) ;
77
91
}
78
92
93
+ /**
94
+ * Get the file path of the src package.json for a module
95
+ * @param {string } moduleName
96
+ */
79
97
function getSrcPackageFile ( moduleName ) {
80
98
const PATHS = {
81
99
core : `${ process . cwd ( ) } /src/core/package.json` ,
@@ -85,6 +103,10 @@ function getSrcPackageFile(moduleName) {
85
103
return PATHS [ moduleName ] ;
86
104
}
87
105
106
+ /**
107
+ * Get the file path of the dist package.json for a module
108
+ * @param {string } moduleName
109
+ */
88
110
function getDestPackageFile ( moduleName ) {
89
111
const PATHS = {
90
112
core : `${ process . cwd ( ) } /dist/packages-dist/package.json` ,
@@ -94,6 +116,33 @@ function getDestPackageFile(moduleName) {
94
116
return PATHS [ moduleName ] ;
95
117
}
96
118
119
+ /**
120
+ * Create an observable of package.json dependency version replacements.
121
+ * This keeps the dependency versions across each package in sync.
122
+ * @param {string } name
123
+ * @param {Object } versions
124
+ */
125
+ function replaceVersionsObservable ( name , versions ) {
126
+ return Observable . create ( ( observer ) => {
127
+ const package = getSrcPackageFile ( name ) ;
128
+ let pkg = readFileSync ( package , 'utf8' ) ;
129
+ const regexs = Object . keys ( versions ) . map ( key =>
130
+ ( { expr : new RegExp ( key , 'g' ) , key, val : versions [ key ] } ) ) ;
131
+ regexs . forEach ( reg => {
132
+ pkg = pkg . replace ( reg . expr , reg . val ) ;
133
+ } ) ;
134
+ const outPath = getDestPackageFile ( name ) ;
135
+ writeFile ( outPath , pkg , err => {
136
+ if ( err ) {
137
+ observer . error ( err ) ;
138
+ } else {
139
+ observer . next ( pkg ) ;
140
+ observer . complete ( ) ;
141
+ }
142
+ } ) ;
143
+ } ) ;
144
+ }
145
+
97
146
function copyPackage ( moduleName ) {
98
147
return copy ( getSrcPackageFile ( moduleName ) , getDestPackageFile ( moduleName ) ) ;
99
148
}
@@ -111,7 +160,7 @@ function buildModule(name, globals) {
111
160
return Observable
112
161
. forkJoin ( es2015$ , esm$ )
113
162
. switchMap ( ( ) => Observable . from ( createUmd ( name , globals ) ) )
114
- . switchMap ( ( ) => Observable . from ( copyPackage ( name ) ) ) ;
163
+ . switchMap ( ( ) => replaceVersionsObservable ( name , VERSIONS ) ) ;
115
164
}
116
165
117
166
function buildLibrary ( globals ) {
@@ -123,13 +172,10 @@ function buildLibrary(globals) {
123
172
. switchMapTo ( auth$ )
124
173
. switchMapTo ( db$ )
125
174
. do ( ( ) => {
126
- const core = measure ( 'core' ) ;
127
- const auth = measure ( 'auth' ) ;
128
- const db = measure ( 'database' ) ;
129
175
console . log ( `
130
- core.umd.js - ${ core }
131
- auth.umd.js - ${ auth }
132
- database.umd.js - ${ db }
176
+ core.umd.js - ${ measure ( ' core' ) }
177
+ auth.umd.js - ${ measure ( ' auth' ) }
178
+ database.umd.js - ${ measure ( 'database' ) }
133
179
` ) ;
134
180
} ) ;
135
181
}
0 commit comments