88 */
99import { Architect , BuilderInfo , BuilderProgressState , Target } from '@angular-devkit/architect' ;
1010import { 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' ;
1912import { NodeJsSyncHost , createConsoleLogger } from '@angular-devkit/core/node' ;
2013import { existsSync } from 'fs' ;
2114import * as minimist from 'minimist' ;
2215import * as path from 'path' ;
2316import { tap } from 'rxjs/operators' ;
2417import { MultiProgressBar } from '../src/progress' ;
2518
26-
2719function findUp ( names : string | string [ ] , from : string ) {
2820 if ( ! Array . isArray ( names ) ) {
2921 names = [ names ] ;
@@ -64,21 +56,19 @@ function usage(logger: logging.Logger, exitCode = 0): never {
6456 ` ) ;
6557
6658 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().
6860}
6961
70- function _targetStringFromTarget ( { project, target, configuration} : Target ) {
62+ function _targetStringFromTarget ( { project, target, configuration } : Target ) {
7163 return `${project } :${target } ${configuration !== undefined ? ':' + configuration : ''} `;
7264}
7365
74-
7566interface BarInfo {
7667 status?: string;
7768 builder: BuilderInfo;
7869 target?: Target;
7970}
8071
81-
8272async function _executeTarget(
8373 parentLogger: logging.Logger,
8474 workspace: workspaces.WorkspaceDefinition,
@@ -104,63 +94,64 @@ async function _executeTarget(
10494 const run = await architect.scheduleTarget(targetSpec, argv, { logger });
10595 const bars = new MultiProgressBar<number, BarInfo>(':name :bar (:current/:total) :status');
10696
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+ }
122112
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+ }
143133
144- bars.render();
145- },
146- );
134+ bars.render();
135+ });
147136
148137 // Wait for full completion of the builder.
149138 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();
164155
165156 await run.stop();
166157 bars.terminate();
@@ -178,7 +169,6 @@ async function _executeTarget(
178169 }
179170}
180171
181-
182172async function main(args: string[]): Promise<number> {
183173 /** Parse the command line. */
184174 const argv = minimist(args, { boolean: ['help'] });
@@ -195,18 +185,15 @@ async function main(args: string[]): Promise<number> {
195185
196186 // Load workspace configuration file.
197187 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'];
204189
205190 const configFilePath = findUp(configFileNames, currentPath);
206191
207192 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+ );
210197
211198 return 3;
212199 }
@@ -227,10 +214,13 @@ async function main(args: string[]): Promise<number> {
227214 return await _executeTarget ( logger , workspace , root , argv , registry ) ;
228215}
229216
230- main ( process . argv . slice ( 2 ) )
231- . then ( code => {
217+ main ( process . argv . slice ( 2 ) ) . then (
218+ code => {
232219 process . exit ( code ) ;
233- } , err => {
220+ } ,
221+ err => {
222+ // tslint:disable-next-line: no-console
234223 console . error ( 'Error: ' + err . stack || err . message || err ) ;
235224 process . exit ( - 1 ) ;
236- } ) ;
225+ } ,
226+ ) ;
0 commit comments