@@ -33,7 +33,11 @@ import {
3333import { RebuildHubs } from '../../utils/rebuild-events' ;
3434import { updateIndexHtml } from '../../utils/updateIndexHtml' ;
3535import { appendFileSync , existsSync , mkdirSync } from 'fs' ;
36- import { EsBuildResult , MemResults } from '../../utils/mem-resuts' ;
36+ import {
37+ EsBuildResult ,
38+ MemResults ,
39+ NgCliAssetResult ,
40+ } from '../../utils/mem-resuts' ;
3741import { JsonObject } from '@angular-devkit/core' ;
3842
3943function log ( ...args ) {
@@ -42,10 +46,10 @@ function log(...args) {
4246 console . log ( args ) ;
4347}
4448
45- export async function runBuilder (
49+ export async function * runBuilder (
4650 nfOptions : NfBuilderSchema ,
4751 context : BuilderContext
48- ) : Promise < BuilderOutput > {
52+ ) : AsyncIterable < BuilderOutput > {
4953 const target = targetFromTargetString ( nfOptions . target ) ;
5054 const _options = ( await context . getTargetOptions (
5155 target
@@ -57,15 +61,18 @@ export async function runBuilder(
5761 builder
5862 ) ) as JsonObject & Schema ;
5963
64+ const runServer = ! ! nfOptions . port ;
65+ const write = ! runServer ;
66+ const watch = ! ! runServer || nfOptions . watch ;
67+
68+ options . watch = watch ;
6069 const rebuildEvents = new RebuildHubs ( ) ;
6170
6271 const adapter = createAngularBuildAdapter ( options , context , rebuildEvents ) ;
6372 setBuildAdapter ( adapter ) ;
6473
6574 setLogLevel ( options . verbose ? 'verbose' : 'info' ) ;
6675
67- options . watch = ! ! nfOptions . dev ;
68-
6976 const fedOptions : FederationOptions = {
7077 workspaceRoot : context . workspaceRoot ,
7178 outputPath : options . outputPath ,
@@ -97,12 +104,12 @@ export async function runBuilder(
97104 // );
98105
99106 const memResults = new MemResults ( ) ;
100- const write = ! nfOptions . dev ;
107+
101108 let first = true ;
102109 let lastResult : { success : boolean } | undefined ;
103110
104111 if ( ! existsSync ( options . outputPath ) ) {
105- mkdirSync ( options . outputPath ) ;
112+ mkdirSync ( options . outputPath , { recursive : true } ) ;
106113 }
107114
108115 if ( ! write ) {
@@ -116,6 +123,7 @@ export async function runBuilder(
116123 write,
117124 } ) ) {
118125 lastResult = output ;
126+ yield output ;
119127
120128 if ( ! output . success ) {
121129 setError ( 'Compilation Error' ) ;
@@ -125,23 +133,14 @@ export async function runBuilder(
125133 setError ( null ) ;
126134 }
127135
128- if ( ! write ) {
136+ if ( ! write && output . outputFiles ) {
129137 memResults . add ( output . outputFiles . map ( ( file ) => new EsBuildResult ( file ) ) ) ;
138+ }
130139
131- // TODO!
132- // '{\n' +
133- // ' "success": true,\n' +
134- // ' "assetFiles": [\n' +
135- // ' {\n' +
136- // ' "source": "C:\\\\temp\\\\native\\\\src\\\\favicon.ico",\n' +
137- // ' "destination": "favicon.ico"\n' +
138- // ' },\n' +
139- // ' {\n' +
140- // ' "source": "C:\\\\temp\\\\native\\\\src\\\\assets\\\\shutterstock_1835092750.jpg",\n' +
141- // ' "destination": "assets\\\\shutterstock_1835092750.jpg"\n' +
142- // ' }\n' +
143- // ' ]\n' +
144- // '}'
140+ if ( ! write && output . assetFiles ) {
141+ memResults . add (
142+ output . assetFiles . map ( ( file ) => new NgCliAssetResult ( file ) )
143+ ) ;
145144 }
146145
147146 if ( write ) {
@@ -152,17 +151,23 @@ export async function runBuilder(
152151 await buildForFederation ( config , fedOptions , externals ) ;
153152 }
154153
155- if ( first && nfOptions . dev ) {
154+ if ( first && runServer ) {
156155 startServer ( nfOptions , options . outputPath , memResults ) ;
157- } else if ( ! first && nfOptions . dev ) {
156+ }
157+
158+ if ( ! first && runServer ) {
158159 reloadBrowser ( ) ;
160+ }
159161
162+ if ( ! first && watch ) {
160163 setTimeout ( async ( ) => {
161164 logger . info ( 'Rebuilding federation artefacts ...' ) ;
162165 await Promise . all ( [ rebuildEvents . rebuild . emit ( ) ] ) ;
163166 logger . info ( 'Done!' ) ;
164167
165- setTimeout ( ( ) => reloadShell ( nfOptions . shell ) , 0 ) ;
168+ if ( runServer ) {
169+ setTimeout ( ( ) => reloadShell ( nfOptions . shell ) , 0 ) ;
170+ }
166171 } , nfOptions . rebuildDelay ) ;
167172 }
168173
@@ -171,7 +176,7 @@ export async function runBuilder(
171176
172177 // updateIndexHtml(fedOptions);
173178 // const output = await lastValueFrom(builderRun.output as any);
174- return lastResult || { success : false } ;
179+ yield lastResult || { success : false } ;
175180}
176181
177182export default createBuilder ( runBuilder ) as any ;
0 commit comments