Skip to content

Commit 13b17ba

Browse files
alan-agius4clydin
authored andcommitted
refactor(@angular-devkit/build-angular): add spinners for localize and downlevelling
1 parent 976cea4 commit 13b17ba

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

‎packages/angular_devkit/build_angular/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ ts_library(
157157
"@npm//minimatch",
158158
"@npm//ng-packagr",
159159
"@npm//open",
160+
"@npm//ora",
160161
"@npm//parse5",
161162
"@npm//parse5-htmlparser2-tree-adapter",
162163
"@npm//pnp-webpack-plugin",

‎packages/angular_devkit/build_angular/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"mini-css-extract-plugin": "0.11.2",
4444
"minimatch": "3.0.4",
4545
"open": "7.2.1",
46+
"ora": "5.1.0",
4647
"parse5": "6.0.1",
4748
"parse5-htmlparser2-tree-adapter": "6.0.1",
4849
"pnp-webpack-plugin": "1.6.4",

‎packages/angular_devkit/build_angular/src/browser/index.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { EmittedFiles, WebpackLoggingCallback, runWebpack } from '@angular-devki
1010
import { join, json, normalize, tags, virtualFs } from '@angular-devkit/core';
1111
import { NodeJsSyncHost } from '@angular-devkit/core/node';
1212
import * as fs from 'fs';
13+
import * as ora from 'ora';
1314
import * as path from 'path';
1415
import { Observable, from } from 'rxjs';
1516
import { concatMap, map, switchMap } from 'rxjs/operators';
@@ -28,6 +29,7 @@ import { BundleActionExecutor } from '../utils/action-executor';
2829
import { WebpackConfigOptions } from '../utils/build-options';
2930
import { ThresholdSeverity, checkBudgets } from '../utils/bundle-calculator';
3031
import { findCachePath } from '../utils/cache-path';
32+
import { colors } from '../utils/color';
3133
import { copyAssets } from '../utils/copy-assets';
3234
import { cachingDisabled } from '../utils/environment-options';
3335
import { i18nInlineEmittedFiles } from '../utils/i18n-inlining';
@@ -457,8 +459,7 @@ export function buildWebpackBrowser(
457459

458460
// Execute the bundle processing actions
459461
try {
460-
context.logger.info('Generating ES5 bundles for differential loading...');
461-
462+
const dlSpinner = ora('Generating ES5 bundles for differential loading...').start();
462463
for await (const result of executor.processAll(processActions)) {
463464
processResults.push(result);
464465
}
@@ -475,10 +476,10 @@ export function buildWebpackBrowser(
475476
);
476477
}
477478

478-
context.logger.info('ES5 bundle generation complete.');
479+
dlSpinner.succeed('ES5 bundle generation complete.');
479480

480481
if (i18n.shouldInline) {
481-
context.logger.info('Generating localized bundles...');
482+
const spinner = ora('Generating localized bundles...').start();
482483

483484
const inlineActions: InlineOptions[] = [];
484485
const processedFiles = new Set<string>();
@@ -528,12 +529,14 @@ export function buildWebpackBrowser(
528529
);
529530
}
530531
for (const diagnostic of result.diagnostics) {
532+
spinner.stop();
531533
if (diagnostic.type === 'error') {
532534
hasErrors = true;
533535
context.logger.error(diagnostic.message);
534536
} else {
535537
context.logger.warn(diagnostic.message);
536538
}
539+
spinner.start();
537540
}
538541
}
539542

@@ -555,14 +558,16 @@ export function buildWebpackBrowser(
555558
'',
556559
);
557560
} catch (err) {
558-
context.logger.error('Localized bundle generation failed: ' + err.message);
561+
spinner.fail(colors.redBright('Localized bundle generation failed: ' + err.message));
559562

560563
return { success: false };
561564
}
562565

563-
context.logger.info(
564-
`Localized bundle generation ${hasErrors ? 'failed' : 'complete'}.`,
565-
);
566+
if (hasErrors) {
567+
spinner.fail(colors.redBright('Localized bundle generation failed.'));
568+
} else {
569+
spinner.succeed('Localized bundle generation complete.');
570+
}
566571

567572
if (hasErrors) {
568573
return { success: false };

‎packages/angular_devkit/build_angular/src/utils/i18n-inlining.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import { BuilderContext } from '@angular-devkit/architect';
99
import { EmittedFiles } from '@angular-devkit/build-webpack';
1010
import * as fs from 'fs';
11+
import * as ora from 'ora';
1112
import * as path from 'path';
1213
import { BundleActionExecutor } from './action-executor';
14+
import { colors } from './color';
1315
import { copyAssets } from './copy-assets';
1416
import { I18nOptions } from './i18n-options';
1517
import { InlineOptions } from './process-bundle';
@@ -73,6 +75,8 @@ export async function i18nInlineEmittedFiles(
7375
): Promise<boolean> {
7476
const executor = new BundleActionExecutor({ i18n });
7577
let hasErrors = false;
78+
const spinner = ora('Generating localized bundles...').start();
79+
7680
try {
7781
const { options, originalFiles: processedFiles } = emittedFilesToInlineOptions(
7882
emittedFiles,
@@ -85,12 +89,14 @@ export async function i18nInlineEmittedFiles(
8589

8690
for await (const result of executor.inlineAll(options)) {
8791
for (const diagnostic of result.diagnostics) {
92+
spinner.stop();
8893
if (diagnostic.type === 'error') {
8994
hasErrors = true;
9095
context.logger.error(diagnostic.message);
9196
} else {
9297
context.logger.warn(diagnostic.message);
9398
}
99+
spinner.start();
94100
}
95101
}
96102

@@ -108,17 +114,17 @@ export async function i18nInlineEmittedFiles(
108114
'',
109115
);
110116
} catch (err) {
111-
context.logger.error('Localized bundle generation failed: ' + err.message);
117+
spinner.fail(colors.redBright('Localized bundle generation failed: ' + err.message));
112118

113119
return false;
114120
} finally {
115121
executor.stop();
116122
}
117123

118124
if (hasErrors) {
119-
context.logger.error('Localized bundle generation failed.');
125+
spinner.fail(colors.redBright('Localized bundle generation failed.'));
120126
} else {
121-
context.logger.info('Localized bundle generation complete.');
127+
spinner.succeed('Localized bundle generation complete.');
122128
}
123129

124130
return !hasErrors;

0 commit comments

Comments
 (0)