Skip to content

Commit 7a12074

Browse files
committed
feat(@angular-devkit/build-angular): provide option to allow automatically cleaning the terminal screen during rebuilds
When setting `"clearScreen": true` to the appliction builder during rebuilds the terminimal screen will be cleaned. ```json { "projects": { "my-app": { "projectType": "application", "root": "", "sourceRoot": "src", "architect": { "build": { "builder": "@angular-devkit/build-angular:application", "options": { "clearScreen": true } } } } } } ``` Closes #25699
1 parent 1011f31 commit 7a12074

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

goldens/public-api/angular_devkit/build_angular/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface ApplicationBuilderOptions {
3030
baseHref?: string;
3131
browser: string;
3232
budgets?: Budget_2[];
33+
clearScreen?: boolean;
3334
crossOrigin?: CrossOrigin_2;
3435
deleteOutputPath?: boolean;
3536
externalDependencies?: string[];

packages/angular_devkit/build_angular/src/builders/application/build-action.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ import { shouldWatchRoot } from '../../utils/environment-options';
1919
import { NormalizedCachedOptions } from '../../utils/normalize-cache';
2020
import { NormalizedOutputOptions } from './options';
2121

22+
// Watch workspace for package manager changes
23+
const packageWatchFiles = [
24+
// manifest can affect module resolution
25+
'package.json',
26+
// npm lock file
27+
'package-lock.json',
28+
// pnpm lock file
29+
'pnpm-lock.yaml',
30+
// yarn lock file including Yarn PnP manifest files (https://yarnpkg.com/advanced/pnp-spec/)
31+
'yarn.lock',
32+
'.pnp.cjs',
33+
'.pnp.data.json',
34+
];
35+
2236
export async function* runEsBuildBuildAction(
2337
action: (rebuildState?: RebuildState) => ExecutionResult | Promise<ExecutionResult>,
2438
options: {
@@ -36,13 +50,15 @@ export async function* runEsBuildBuildAction(
3650
poll?: number;
3751
signal?: AbortSignal;
3852
preserveSymlinks?: boolean;
53+
clearScreen?: boolean;
3954
},
4055
): AsyncIterable<(ExecutionResult['outputWithFiles'] | ExecutionResult['output']) & BuilderOutput> {
4156
const {
4257
writeToFileSystemFilter,
4358
writeToFileSystem,
4459
watch,
4560
poll,
61+
clearScreen,
4662
logger,
4763
deleteOutputPath,
4864
cacheOptions,
@@ -113,20 +129,6 @@ export async function* runEsBuildBuildAction(
113129
watcher.add(projectRoot);
114130
}
115131

116-
// Watch workspace for package manager changes
117-
const packageWatchFiles = [
118-
// manifest can affect module resolution
119-
'package.json',
120-
// npm lock file
121-
'package-lock.json',
122-
// pnpm lock file
123-
'pnpm-lock.yaml',
124-
// yarn lock file including Yarn PnP manifest files (https://yarnpkg.com/advanced/pnp-spec/)
125-
'yarn.lock',
126-
'.pnp.cjs',
127-
'.pnp.data.json',
128-
];
129-
130132
watcher.add(
131133
packageWatchFiles
132134
.map((file) => path.join(workspaceRoot, file))
@@ -164,6 +166,11 @@ export async function* runEsBuildBuildAction(
164166
break;
165167
}
166168

169+
if (clearScreen) {
170+
// eslint-disable-next-line no-console
171+
console.clear();
172+
}
173+
167174
if (verbose) {
168175
logger.info(changes.toDebugString());
169176
}

packages/angular_devkit/build_angular/src/builders/application/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export async function* buildApplicationInternal(
126126
projectRoot: normalizedOptions.projectRoot,
127127
workspaceRoot: normalizedOptions.workspaceRoot,
128128
progress: normalizedOptions.progress,
129+
clearScreen: normalizedOptions.clearScreen,
129130
writeToFileSystem,
130131
// For app-shell and SSG server files are not required by users.
131132
// Omit these when SSR is not enabled.

packages/angular_devkit/build_angular/src/builders/application/options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ export async function normalizeOptions(
294294
namedChunks,
295295
budgets,
296296
deployUrl,
297+
clearScreen,
297298
} = options;
298299

299300
// Return all the normalized options
@@ -348,6 +349,7 @@ export async function normalizeOptions(
348349
loaderExtensions,
349350
jsonLogs: useJSONBuildLogs,
350351
colors: colors.enabled,
352+
clearScreen,
351353
};
352354
}
353355

packages/angular_devkit/build_angular/src/builders/application/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@
133133
},
134134
"default": []
135135
},
136+
"clearScreen": {
137+
"type": "boolean",
138+
"default": false,
139+
"description": "Automatically clear the terminal screen during rebuilds."
140+
},
136141
"optimization": {
137142
"description": "Enables optimization of the build output. Including minification of scripts and styles, tree-shaking, dead-code elimination, inlining of critical CSS and fonts inlining. For more information, see https://angular.io/guide/workspace-config#optimization-configuration.",
138143
"default": true,

0 commit comments

Comments
 (0)