Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): provide option to allow automati…
Browse files Browse the repository at this point in the history
…cally 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
  • Loading branch information
alan-agius4 committed Feb 2, 2024
1 parent 1011f31 commit 7a12074
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions goldens/public-api/angular_devkit/build_angular/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface ApplicationBuilderOptions {
baseHref?: string;
browser: string;
budgets?: Budget_2[];
clearScreen?: boolean;
crossOrigin?: CrossOrigin_2;
deleteOutputPath?: boolean;
externalDependencies?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ import { shouldWatchRoot } from '../../utils/environment-options';
import { NormalizedCachedOptions } from '../../utils/normalize-cache';
import { NormalizedOutputOptions } from './options';

// Watch workspace for package manager changes
const packageWatchFiles = [
// manifest can affect module resolution
'package.json',
// npm lock file
'package-lock.json',
// pnpm lock file
'pnpm-lock.yaml',
// yarn lock file including Yarn PnP manifest files (https://yarnpkg.com/advanced/pnp-spec/)
'yarn.lock',
'.pnp.cjs',
'.pnp.data.json',
];

export async function* runEsBuildBuildAction(
action: (rebuildState?: RebuildState) => ExecutionResult | Promise<ExecutionResult>,
options: {
Expand All @@ -36,13 +50,15 @@ export async function* runEsBuildBuildAction(
poll?: number;
signal?: AbortSignal;
preserveSymlinks?: boolean;
clearScreen?: boolean;
},
): AsyncIterable<(ExecutionResult['outputWithFiles'] | ExecutionResult['output']) & BuilderOutput> {
const {
writeToFileSystemFilter,
writeToFileSystem,
watch,
poll,
clearScreen,
logger,
deleteOutputPath,
cacheOptions,
Expand Down Expand Up @@ -113,20 +129,6 @@ export async function* runEsBuildBuildAction(
watcher.add(projectRoot);
}

// Watch workspace for package manager changes
const packageWatchFiles = [
// manifest can affect module resolution
'package.json',
// npm lock file
'package-lock.json',
// pnpm lock file
'pnpm-lock.yaml',
// yarn lock file including Yarn PnP manifest files (https://yarnpkg.com/advanced/pnp-spec/)
'yarn.lock',
'.pnp.cjs',
'.pnp.data.json',
];

watcher.add(
packageWatchFiles
.map((file) => path.join(workspaceRoot, file))
Expand Down Expand Up @@ -164,6 +166,11 @@ export async function* runEsBuildBuildAction(
break;
}

if (clearScreen) {
// eslint-disable-next-line no-console
console.clear();
}

if (verbose) {
logger.info(changes.toDebugString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export async function* buildApplicationInternal(
projectRoot: normalizedOptions.projectRoot,
workspaceRoot: normalizedOptions.workspaceRoot,
progress: normalizedOptions.progress,
clearScreen: normalizedOptions.clearScreen,
writeToFileSystem,
// For app-shell and SSG server files are not required by users.
// Omit these when SSR is not enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export async function normalizeOptions(
namedChunks,
budgets,
deployUrl,
clearScreen,
} = options;

// Return all the normalized options
Expand Down Expand Up @@ -348,6 +349,7 @@ export async function normalizeOptions(
loaderExtensions,
jsonLogs: useJSONBuildLogs,
colors: colors.enabled,
clearScreen,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@
},
"default": []
},
"clearScreen": {
"type": "boolean",
"default": false,
"description": "Automatically clear the terminal screen during rebuilds."
},
"optimization": {
"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.",
"default": true,
Expand Down

0 comments on commit 7a12074

Please sign in to comment.