@@ -2,10 +2,15 @@ import { spawn } from 'child_process';
2
2
import { copy , writeFile , readFile } from 'fs-extra' ;
3
3
import { prettySize } from 'pretty-size' ;
4
4
import { sync as gzipSync } from 'gzip-size' ;
5
+ import { join } from 'path' ;
5
6
6
- const rootPackage = import ( `${ process . cwd ( ) } /package.json` ) ;
7
+ const src = ( ...args :string [ ] ) => join ( process . cwd ( ) , 'src' , ...args ) ;
8
+ const dest = ( ...args :string [ ] ) => join ( process . cwd ( ) , 'dist' , 'packages-dist' , ...args ) ;
7
9
8
- async function replaceVersions ( path : string ) {
10
+ const rootPackage = import ( join ( process . cwd ( ) , 'package.json' ) ) ;
11
+
12
+ async function replacePackageJsonVersions ( ) {
13
+ const path = dest ( 'package.json' ) ;
9
14
const root = await rootPackage ;
10
15
var pkg = await import ( path ) ;
11
16
Object . keys ( pkg . peerDependencies ) . forEach ( peer => {
@@ -15,22 +20,33 @@ async function replaceVersions(path: string) {
15
20
return writeFile ( path , JSON . stringify ( pkg , null , 2 ) ) ;
16
21
}
17
22
23
+ async function replaceSchematicVersions ( ) {
24
+ const root = await rootPackage ;
25
+ const path = dest ( 'schematics' , 'versions.json' ) ;
26
+ const dependencies = await import ( path ) ;
27
+ Object . keys ( dependencies . default ) . forEach ( name => {
28
+ dependencies . default [ name ] . version = root . dependencies [ name ] || root . devDependencies [ name ] ;
29
+ } ) ;
30
+ return writeFile ( path , JSON . stringify ( dependencies , null , 2 ) ) ;
31
+ }
32
+
18
33
function spawnPromise ( command : string , args : string [ ] ) {
19
34
return new Promise ( resolve => spawn ( command , args , { stdio : 'inherit' } ) . on ( 'close' , resolve ) ) ;
20
35
}
21
36
22
37
async function compileSchematics ( ) {
23
- await spawnPromise ( `${ process . cwd ( ) } /node_modules/.bin/tsc ` , [ '-p' , ` ${ process . cwd ( ) } / src/ schematics/ tsconfig.json` ] ) ;
38
+ await spawnPromise ( `npx ` , [ 'tsc' , ' -p', src ( ' schematics' , ' tsconfig.json' ) ] ) ;
24
39
return Promise . all ( [
25
- copy ( `${ process . cwd ( ) } /src/core/builders.json` , `${ process . cwd ( ) } /dist/packages-dist/builders.json` ) ,
26
- copy ( `${ process . cwd ( ) } /src/core/collection.json` , `${ process . cwd ( ) } /dist/packages-dist/collection.json` ) ,
27
- copy ( `${ process . cwd ( ) } /src/schematics/deploy/schema.json` , `${ process . cwd ( ) } /dist/packages-dist/schematics/deploy/schema.json` )
40
+ copy ( src ( 'core' , 'builders.json' ) , dest ( 'builders.json' ) ) ,
41
+ copy ( src ( 'core' , 'collection.json' ) , dest ( 'collection.json' ) ) ,
42
+ copy ( src ( 'schematics' , 'deploy' , 'schema.json' ) , dest ( 'deploy' , 'schema.json' ) ) ,
43
+ replaceSchematicVersions ( )
28
44
] ) ;
29
45
}
30
46
31
47
async function replaceDynamicImportsForUMD ( ) {
32
- const perfPath = ` ${ process . cwd ( ) } /dist/packages-dist/ bundles/ angular-fire-performance.umd.js` ;
33
- const messagingPath = ` ${ process . cwd ( ) } /dist/packages-dist/ bundles/ angular-fire-messaging.umd.js` ;
48
+ const perfPath = dest ( ' bundles' , ' angular-fire-performance.umd.js' ) ;
49
+ const messagingPath = dest ( ' bundles' , ' angular-fire-messaging.umd.js' ) ;
34
50
const [ perf , messaging ] = await Promise . all ( [
35
51
readFile ( perfPath , 'utf8' ) ,
36
52
readFile ( messagingPath , 'utf8' )
@@ -42,22 +58,22 @@ async function replaceDynamicImportsForUMD() {
42
58
}
43
59
44
60
async function measure ( module : string ) {
45
- const path = ` ${ process . cwd ( ) } /dist/packages-dist/ bundles/ ${ module } .umd.js`;
61
+ const path = dest ( ' bundles' , ` ${ module } .umd.js`) ;
46
62
const file = await readFile ( path ) ;
47
63
const gzip = prettySize ( gzipSync ( file ) , true ) ;
48
64
const size = prettySize ( file . byteLength , true ) ;
49
65
return { size, gzip } ;
50
66
}
51
67
52
68
async function buildLibrary ( ) {
53
- await spawnPromise ( ` ${ process . cwd ( ) } /node_modules/.bin/ng` , [ 'build' ] ) ;
69
+ await spawnPromise ( 'npx' , [ 'ng' , 'build' ] ) ;
54
70
await Promise . all ( [
55
- copy ( ` ${ process . cwd ( ) } / .npmignore` , ` ${ process . cwd ( ) } /dist/packages-dist/ .npmignore` ) ,
56
- copy ( ` ${ process . cwd ( ) } / README.md` , ` ${ process . cwd ( ) } /dist/packages-dist/ README.md` ) ,
57
- copy ( ` ${ process . cwd ( ) } / docs` , ` ${ process . cwd ( ) } /dist/packages-dist/ docs` ) ,
58
- copy ( ` ${ process . cwd ( ) } / src/ firebase-node` , ` ${ process . cwd ( ) } /dist/packages-dist/ firebase-node` ) ,
71
+ copy ( join ( process . cwd ( ) , ' .npmignore' ) , dest ( ' .npmignore' ) ) ,
72
+ copy ( join ( process . cwd ( ) , ' README.md' ) , dest ( ' README.md' ) ) ,
73
+ copy ( join ( process . cwd ( ) , ' docs' ) , dest ( ' docs' ) ) ,
74
+ copy ( src ( ' firebase-node' ) , dest ( ' firebase-node' ) ) ,
59
75
compileSchematics ( ) ,
60
- replaceVersions ( ` ${ process . cwd ( ) } /dist/packages-dist/package.json` ) ,
76
+ replacePackageJsonVersions ( ) ,
61
77
replaceDynamicImportsForUMD ( )
62
78
] ) ;
63
79
return Promise . all ( [
@@ -74,9 +90,9 @@ async function buildLibrary() {
74
90
}
75
91
76
92
async function buildWrapper ( ) {
77
- await copy ( ` ${ process . cwd ( ) } / src/ wrapper` , ` ${ process . cwd ( ) } / dist/ wrapper-dist` ) ;
93
+ await copy ( src ( ' wrapper' ) , join ( process . cwd ( ) , ' dist' , ' wrapper-dist' ) ) ;
78
94
const root = await rootPackage ;
79
- const path = ` ${ process . cwd ( ) } / dist/ wrapper-dist/ package.json` ;
95
+ const path = join ( process . cwd ( ) , ' dist' , ' wrapper-dist' , ' package.json' ) ;
80
96
var pkg = await import ( path ) ;
81
97
pkg . dependencies [ '@angular/fire' ] = pkg . version = root . version ;
82
98
return writeFile ( path , JSON . stringify ( pkg , null , 2 ) ) ;
0 commit comments