8
8
*/
9
9
import { Architect , BuilderInfo , BuilderProgressState , Target } from '@angular-devkit/architect' ;
10
10
import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node' ;
11
- import {
12
- json ,
13
- logging ,
14
- schema ,
15
- tags ,
16
- terminal ,
17
- workspaces ,
18
- } from '@angular-devkit/core' ;
11
+ import { json , logging , schema , tags , terminal , workspaces } from '@angular-devkit/core' ;
19
12
import { NodeJsSyncHost , createConsoleLogger } from '@angular-devkit/core/node' ;
20
13
import { existsSync } from 'fs' ;
21
14
import * as minimist from 'minimist' ;
22
15
import * as path from 'path' ;
23
16
import { tap } from 'rxjs/operators' ;
24
17
import { MultiProgressBar } from '../src/progress' ;
25
18
26
-
27
19
function findUp ( names : string | string [ ] , from : string ) {
28
20
if ( ! Array . isArray ( names ) ) {
29
21
names = [ names ] ;
@@ -64,21 +56,19 @@ function usage(logger: logging.Logger, exitCode = 0): never {
64
56
` ) ;
65
57
66
58
process . exit ( exitCode ) ;
67
- throw 0 ; // The node typing sometimes don't have a never type for process.exit().
59
+ throw 0 ; // The node typing sometimes don't have a never type for process.exit().
68
60
}
69
61
70
- function _targetStringFromTarget ( { project, target, configuration} : Target ) {
62
+ function _targetStringFromTarget ( { project, target, configuration } : Target ) {
71
63
return `${project } :${target } ${configuration !== undefined ? ':' + configuration : ''} `;
72
64
}
73
65
74
-
75
66
interface BarInfo {
76
67
status?: string;
77
68
builder: BuilderInfo;
78
69
target?: Target;
79
70
}
80
71
81
-
82
72
async function _executeTarget(
83
73
parentLogger: logging.Logger,
84
74
workspace: workspaces.WorkspaceDefinition,
@@ -104,63 +94,64 @@ async function _executeTarget(
104
94
const run = await architect.scheduleTarget(targetSpec, argv, { logger });
105
95
const bars = new MultiProgressBar<number, BarInfo>(':name :bar (:current/:total) :status');
106
96
107
- run.progress.subscribe(
108
- update => {
109
- const data = bars.get( update.id) || {
110
- id : update.id ,
111
- builder : update.builder ,
112
- target : update.target ,
113
- status: update.status || '',
114
- name: (( update.target ? _targetStringFromTarget(update.target) : update.builder.name)
115
- + ' '.repeat(80)
116
- ).substr(0, 40),
117
- };
118
-
119
- if (update.status !== undefined) {
120
- data.status = update.status;
121
- }
97
+ run.progress.subscribe(update => {
98
+ const data = bars.get(update.id) || {
99
+ id: update.id,
100
+ builder : update.builder ,
101
+ target : update.target ,
102
+ status : update.status || '' ,
103
+ name: (
104
+ ( update.target ? _targetStringFromTarget(update.target) : update.builder.name) +
105
+ ' '.repeat(80)
106
+ ).substr(0, 40),
107
+ };
108
+
109
+ if (update.status !== undefined) {
110
+ data.status = update.status;
111
+ }
122
112
123
- switch (update.state) {
124
- case BuilderProgressState.Error:
125
- data.status = 'Error: ' + update.error;
126
- bars.update(update.id, data);
127
- break;
128
-
129
- case BuilderProgressState.Stopped:
130
- data.status = 'Done.';
131
- bars.complete(update.id);
132
- bars.update(update.id, data, update.total, update.total);
133
- break;
134
-
135
- case BuilderProgressState.Waiting:
136
- bars.update(update.id, data);
137
- break;
138
-
139
- case BuilderProgressState.Running:
140
- bars.update(update.id, data, update.current, update.total);
141
- break;
142
- }
113
+ switch (update.state) {
114
+ case BuilderProgressState.Error:
115
+ data.status = 'Error: ' + update.error;
116
+ bars.update(update.id, data);
117
+ break;
118
+
119
+ case BuilderProgressState.Stopped:
120
+ data.status = 'Done.';
121
+ bars.complete(update.id);
122
+ bars.update(update.id, data, update.total, update.total);
123
+ break;
124
+
125
+ case BuilderProgressState.Waiting:
126
+ bars.update(update.id, data);
127
+ break;
128
+
129
+ case BuilderProgressState.Running:
130
+ bars.update(update.id, data, update.current, update.total);
131
+ break;
132
+ }
143
133
144
- bars.render();
145
- },
146
- );
134
+ bars.render();
135
+ });
147
136
148
137
// Wait for full completion of the builder.
149
138
try {
150
- const { success } = await run.output.pipe(
151
- tap(result => {
152
- if (result.success) {
153
- parentLogger.info(terminal.green('SUCCESS'));
154
- } else {
155
- parentLogger.info(terminal.yellow('FAILURE'));
156
- }
157
- parentLogger.info('Result: ' + JSON.stringify({ ...result, info: undefined }, null, 4));
158
-
159
- parentLogger.info('\nLogs:');
160
- logs.forEach(l => parentLogger.next(l));
161
- logs.splice(0);
162
- }),
163
- ).toPromise();
139
+ const { success } = await run.output
140
+ .pipe(
141
+ tap(result => {
142
+ if (result.success) {
143
+ parentLogger.info(terminal.green('SUCCESS'));
144
+ } else {
145
+ parentLogger.info(terminal.yellow('FAILURE'));
146
+ }
147
+ parentLogger.info('Result: ' + JSON.stringify({ ...result, info: undefined }, null, 4));
148
+
149
+ parentLogger.info('\nLogs:');
150
+ logs.forEach(l => parentLogger.next(l));
151
+ logs.splice(0);
152
+ }),
153
+ )
154
+ .toPromise();
164
155
165
156
await run.stop();
166
157
bars.terminate();
@@ -178,7 +169,6 @@ async function _executeTarget(
178
169
}
179
170
}
180
171
181
-
182
172
async function main(args: string[]): Promise<number> {
183
173
/** Parse the command line. */
184
174
const argv = minimist(args, { boolean: ['help'] });
@@ -195,18 +185,15 @@ async function main(args: string[]): Promise<number> {
195
185
196
186
// Load workspace configuration file.
197
187
const currentPath = process.cwd();
198
- const configFileNames = [
199
- 'angular.json',
200
- '.angular.json',
201
- 'workspace.json',
202
- '.workspace.json',
203
- ];
188
+ const configFileNames = ['angular.json', '.angular.json', 'workspace.json', '.workspace.json'];
204
189
205
190
const configFilePath = findUp(configFileNames, currentPath);
206
191
207
192
if (!configFilePath) {
208
- logger.fatal(` Workspace configuration file ( $ { configFileNames . join ( ', ' ) } ) cannot be found in `
209
- + ` '${currentPath}' or in parent directories . `);
193
+ logger.fatal(
194
+ ` Workspace configuration file ( $ { configFileNames . join ( ', ' ) } ) cannot be found in ` +
195
+ ` '${currentPath}' or in parent directories . `,
196
+ );
210
197
211
198
return 3;
212
199
}
@@ -227,10 +214,13 @@ async function main(args: string[]): Promise<number> {
227
214
return await _executeTarget ( logger , workspace , root , argv , registry ) ;
228
215
}
229
216
230
- main ( process . argv . slice ( 2 ) )
231
- . then ( code => {
217
+ main ( process . argv . slice ( 2 ) ) . then (
218
+ code => {
232
219
process . exit ( code ) ;
233
- } , err => {
220
+ } ,
221
+ err => {
222
+ // tslint:disable-next-line: no-console
234
223
console . error ( 'Error: ' + err . stack || err . message || err ) ;
235
224
process . exit ( - 1 ) ;
236
- } ) ;
225
+ } ,
226
+ ) ;
0 commit comments