UNPKG

@rushstack/heft

Version:

Build all your JavaScript projects the same way: A way that works.

72 lines 3.81 kB
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. import { CommandLineAction } from '@rushstack/ts-command-line'; import { OperationStatus } from '@rushstack/operation-graph'; import { Constants } from '../../utilities/Constants'; import { definePhaseScopingParameters, expandPhases } from './RunAction'; import { deleteFilesAsync } from '../../plugins/DeleteFilesPlugin'; import { ensureCliAbortSignal, initializeHeft, runWithLoggingAsync } from '../HeftActionRunner'; export class CleanAction extends CommandLineAction { constructor(options) { super({ actionName: 'clean', documentation: 'Clean the project, removing temporary task folders and specified clean paths.', summary: 'Clean the project, removing temporary task folders and specified clean paths.' }); this.watch = false; this._terminal = options.terminal; this._metricsCollector = options.metricsCollector; this._internalHeftSession = options.internalHeftSession; const { toParameter, toExceptParameter, onlyParameter } = definePhaseScopingParameters(this); this._toParameter = toParameter; this._toExceptParameter = toExceptParameter; this._onlyParameter = onlyParameter; this._verboseFlag = this.defineFlagParameter({ parameterLongName: Constants.verboseParameterLongName, parameterShortName: Constants.verboseParameterShortName, description: 'If specified, log information useful for debugging.' }); } get selectedPhases() { if (!this._selectedPhases) { if (this._onlyParameter.values.length || this._toParameter.values.length || this._toExceptParameter.values.length) { this._selectedPhases = expandPhases(this._onlyParameter, this._toParameter, this._toExceptParameter, this._internalHeftSession, this._terminal); } else { // No selected phases, clean everything this._selectedPhases = this._internalHeftSession.phases; } } return this._selectedPhases; } async onExecuteAsync() { const { heftConfiguration } = this._internalHeftSession; const abortSignal = ensureCliAbortSignal(this._terminal); // Record this as the start of task execution. this._metricsCollector.setStartTime(); initializeHeft(heftConfiguration, this._terminal, this._verboseFlag.value); await runWithLoggingAsync(this._cleanFilesAsync.bind(this), this, this._internalHeftSession.loggingManager, this._terminal, this._metricsCollector, abortSignal); } async _cleanFilesAsync() { const deleteOperations = []; for (const phase of this.selectedPhases) { // Add the temp folder and cache folder (if requested) for each task const phaseSession = this._internalHeftSession.getSessionForPhase(phase); for (const task of phase.tasks) { const taskSession = phaseSession.getSessionForTask(task); deleteOperations.push({ sourcePath: taskSession.tempFolderPath }); } // Add the manually specified clean operations deleteOperations.push(...phase.cleanFiles); } // Delete the files if (deleteOperations.length) { const rootFolderPath = this._internalHeftSession.heftConfiguration.buildFolderPath; await deleteFilesAsync(rootFolderPath, deleteOperations, this._terminal); } return deleteOperations.length === 0 ? OperationStatus.NoOp : OperationStatus.Success; } } //# sourceMappingURL=CleanAction.js.map