@@ -33,7 +33,11 @@ import {
33
33
import { RebuildHubs } from '../../utils/rebuild-events' ;
34
34
import { updateIndexHtml } from '../../utils/updateIndexHtml' ;
35
35
import { 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' ;
37
41
import { JsonObject } from '@angular-devkit/core' ;
38
42
39
43
function log ( ...args ) {
@@ -42,10 +46,10 @@ function log(...args) {
42
46
console . log ( args ) ;
43
47
}
44
48
45
- export async function runBuilder (
49
+ export async function * runBuilder (
46
50
nfOptions : NfBuilderSchema ,
47
51
context : BuilderContext
48
- ) : Promise < BuilderOutput > {
52
+ ) : AsyncIterable < BuilderOutput > {
49
53
const target = targetFromTargetString ( nfOptions . target ) ;
50
54
const _options = ( await context . getTargetOptions (
51
55
target
@@ -57,15 +61,18 @@ export async function runBuilder(
57
61
builder
58
62
) ) as JsonObject & Schema ;
59
63
64
+ const runServer = ! ! nfOptions . port ;
65
+ const write = ! runServer ;
66
+ const watch = ! ! runServer || nfOptions . watch ;
67
+
68
+ options . watch = watch ;
60
69
const rebuildEvents = new RebuildHubs ( ) ;
61
70
62
71
const adapter = createAngularBuildAdapter ( options , context , rebuildEvents ) ;
63
72
setBuildAdapter ( adapter ) ;
64
73
65
74
setLogLevel ( options . verbose ? 'verbose' : 'info' ) ;
66
75
67
- options . watch = ! ! nfOptions . dev ;
68
-
69
76
const fedOptions : FederationOptions = {
70
77
workspaceRoot : context . workspaceRoot ,
71
78
outputPath : options . outputPath ,
@@ -97,12 +104,12 @@ export async function runBuilder(
97
104
// );
98
105
99
106
const memResults = new MemResults ( ) ;
100
- const write = ! nfOptions . dev ;
107
+
101
108
let first = true ;
102
109
let lastResult : { success : boolean } | undefined ;
103
110
104
111
if ( ! existsSync ( options . outputPath ) ) {
105
- mkdirSync ( options . outputPath ) ;
112
+ mkdirSync ( options . outputPath , { recursive : true } ) ;
106
113
}
107
114
108
115
if ( ! write ) {
@@ -116,6 +123,7 @@ export async function runBuilder(
116
123
write,
117
124
} ) ) {
118
125
lastResult = output ;
126
+ yield output ;
119
127
120
128
if ( ! output . success ) {
121
129
setError ( 'Compilation Error' ) ;
@@ -125,23 +133,14 @@ export async function runBuilder(
125
133
setError ( null ) ;
126
134
}
127
135
128
- if ( ! write ) {
136
+ if ( ! write && output . outputFiles ) {
129
137
memResults . add ( output . outputFiles . map ( ( file ) => new EsBuildResult ( file ) ) ) ;
138
+ }
130
139
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
+ ) ;
145
144
}
146
145
147
146
if ( write ) {
@@ -152,17 +151,23 @@ export async function runBuilder(
152
151
await buildForFederation ( config , fedOptions , externals ) ;
153
152
}
154
153
155
- if ( first && nfOptions . dev ) {
154
+ if ( first && runServer ) {
156
155
startServer ( nfOptions , options . outputPath , memResults ) ;
157
- } else if ( ! first && nfOptions . dev ) {
156
+ }
157
+
158
+ if ( ! first && runServer ) {
158
159
reloadBrowser ( ) ;
160
+ }
159
161
162
+ if ( ! first && watch ) {
160
163
setTimeout ( async ( ) => {
161
164
logger . info ( 'Rebuilding federation artefacts ...' ) ;
162
165
await Promise . all ( [ rebuildEvents . rebuild . emit ( ) ] ) ;
163
166
logger . info ( 'Done!' ) ;
164
167
165
- setTimeout ( ( ) => reloadShell ( nfOptions . shell ) , 0 ) ;
168
+ if ( runServer ) {
169
+ setTimeout ( ( ) => reloadShell ( nfOptions . shell ) , 0 ) ;
170
+ }
166
171
} , nfOptions . rebuildDelay ) ;
167
172
}
168
173
@@ -171,7 +176,7 @@ export async function runBuilder(
171
176
172
177
// updateIndexHtml(fedOptions);
173
178
// const output = await lastValueFrom(builderRun.output as any);
174
- return lastResult || { success : false } ;
179
+ yield lastResult || { success : false } ;
175
180
}
176
181
177
182
export default createBuilder ( runBuilder ) as any ;
0 commit comments