6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { logging } from '@angular-devkit/core' ;
10
9
import { spawn } from 'child_process' ;
11
10
import fs from 'fs' ;
12
11
import { dirname , join , relative , resolve } from 'path' ;
@@ -35,7 +34,7 @@ function _copy(from: string, to: string) {
35
34
fs . writeFileSync ( to , buffer ) ;
36
35
}
37
36
38
- function _recursiveCopy ( from : string , to : string , logger : logging . Logger ) {
37
+ function _recursiveCopy ( from : string , to : string , logger : Console ) {
39
38
if ( ! fs . existsSync ( from ) ) {
40
39
logger . error ( `File "${ from } " does not exist.` ) ;
41
40
process . exit ( 4 ) ;
@@ -53,13 +52,13 @@ function rimraf(location: string) {
53
52
fs . rmSync ( location , { force : true , recursive : true , maxRetries : 3 } ) ;
54
53
}
55
54
56
- function _clean ( logger : logging . Logger ) {
55
+ function _clean ( logger : Console ) {
57
56
logger . info ( 'Cleaning...' ) ;
58
57
logger . info ( ' Removing dist/...' ) ;
59
58
rimraf ( join ( __dirname , '../dist' ) ) ;
60
59
}
61
60
62
- function _exec ( cmd : string , captureStdout : boolean , logger : logging . Logger ) : Promise < string > {
61
+ function _exec ( cmd : string , captureStdout : boolean , logger : Console ) : Promise < string > {
63
62
return new Promise ( ( resolve , reject ) => {
64
63
const proc = spawn ( cmd , {
65
64
stdio : 'pipe' ,
@@ -89,36 +88,40 @@ function _exec(cmd: string, captureStdout: boolean, logger: logging.Logger): Pro
89
88
} ) ;
90
89
}
91
90
92
- async function _build ( logger : logging . Logger , mode : BuildMode ) : Promise < string [ ] > {
93
- logger . info ( `Building (mode=${ mode } )...` ) ;
91
+ async function _build ( logger : Console , mode : BuildMode ) : Promise < string [ ] > {
92
+ logger . group ( `Building (mode=${ mode } )...` ) ;
94
93
95
- const queryLogger = logger . createChild ( 'query ') ;
94
+ logger . group ( 'Finding targets... ') ;
96
95
const queryTargetsCmd =
97
96
`${ bazelCmd } query --output=label "attr(name, npm_package_archive, //packages/...` +
98
97
' except //packages/angular/ssr/schematics/...)"' ;
99
- const targets = ( await _exec ( queryTargetsCmd , true , queryLogger ) ) . split ( / \r ? \n / ) ;
100
-
101
- const buildLogger = logger . createChild ( 'build' ) ;
98
+ const targets = ( await _exec ( queryTargetsCmd , true , logger ) ) . split ( / \r ? \n / ) ;
99
+ logger . groupEnd ( ) ;
102
100
103
101
// If we are in release mode, run `bazel clean` to ensure the execroot and action cache
104
102
// are not populated. This is necessary because targets using `npm_package` rely on
105
103
// workspace status variables for the package version. Such NPM package targets are not
106
104
// rebuilt if only the workspace status variables change. This could result in accidental
107
105
// re-use of previously built package output with a different `version` in the `package.json`.
108
106
if ( mode == 'release' ) {
109
- buildLogger . info ( 'Building in release mode. Resetting the Bazel execroot and action cache.' ) ;
110
- await _exec ( `${ bazelCmd } clean` , false , buildLogger ) ;
107
+ logger . info ( 'Building in release mode. Resetting the Bazel execroot and action cache.' ) ;
108
+ await _exec ( `${ bazelCmd } clean` , false , logger ) ;
111
109
}
112
110
113
- await _exec ( `${ bazelCmd } build --config=${ mode } ${ targets . join ( ' ' ) } ` , false , buildLogger ) ;
111
+ logger . group ( 'Building targets...' ) ;
112
+ await _exec ( `${ bazelCmd } build --config=${ mode } ${ targets . join ( ' ' ) } ` , false , logger ) ;
113
+ logger . groupEnd ( ) ;
114
+
115
+ logger . groupEnd ( ) ;
114
116
115
117
return targets ;
116
118
}
117
119
118
120
export default async function (
119
121
argv : { local ?: boolean ; snapshot ?: boolean } = { } ,
120
- logger : logging . Logger = new logging . Logger ( 'build-logger' ) ,
121
122
) : Promise < { name : string ; outputPath : string } [ ] > {
123
+ const logger = globalThis . console ;
124
+
122
125
const bazelBin = await _exec ( `${ bazelCmd } info bazel-bin` , true , logger ) ;
123
126
124
127
_clean ( logger ) ;
@@ -135,8 +138,7 @@ export default async function (
135
138
const targets = await _build ( logger , buildMode ) ;
136
139
const output : { name : string ; outputPath : string } [ ] = [ ] ;
137
140
138
- logger . info ( 'Moving packages and tars to dist/' ) ;
139
- const packageLogger = logger . createChild ( 'packages' ) ;
141
+ logger . group ( 'Moving packages and tars to dist/' ) ;
140
142
141
143
for ( const target of targets ) {
142
144
const packageDir = target . replace ( / \/ \/ p a c k a g e s \/ ( .* ) : n p m _ p a c k a g e _ a r c h i v e / , '$1' ) ;
@@ -146,13 +148,15 @@ export default async function (
146
148
const packageName = require ( packageJsonPath ) . name ;
147
149
const destDir = `${ distRoot } /${ packageName } ` ;
148
150
149
- packageLogger . info ( packageName ) ;
151
+ logger . info ( packageName ) ;
150
152
151
153
_recursiveCopy ( bazelOutDir , destDir , logger ) ;
152
154
_copy ( tarPath , `${ distRoot } /${ packageName . replace ( '@' , '_' ) . replace ( '/' , '_' ) } .tgz` ) ;
153
155
154
156
output . push ( { name : packageDir , outputPath : destDir } ) ;
155
157
}
156
158
159
+ logger . groupEnd ( ) ;
160
+
157
161
return output ;
158
162
}
0 commit comments