UNPKG

@rushstack/heft

Version:

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

50 lines 2.35 kB
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. import { OperationStatus } from '@rushstack/operation-graph'; import { deleteFilesAsync } from '../../plugins/DeleteFilesPlugin'; export class PhaseOperationRunner { get name() { return `Phase ${JSON.stringify(this._options.phase.phaseName)}`; } constructor(options) { this.silent = true; this._isClean = false; this._options = options; } async executeAsync(context) { const { internalHeftSession, phase } = this._options; const { clean } = internalHeftSession.parameterManager.defaultParameters; // Load and apply the plugins for this phase only const phaseSession = internalHeftSession.getSessionForPhase(phase); const { phaseLogger, cleanLogger } = phaseSession; await phaseSession.applyPluginsAsync(phaseLogger.terminal); if (this._isClean || !clean) { return OperationStatus.NoOp; } // Run the clean hook const startTime = performance.now(); // Grab the additional clean operations from the phase cleanLogger.terminal.writeVerboseLine('Starting clean'); const deleteOperations = Array.from(phase.cleanFiles); // Delete all temp folders for tasks by default const tempFolderGlobs = [ /* heft@>0.60.0 */ phase.phaseName, /* heft@<=0.60.0 */ `${phase.phaseName}.*` ]; deleteOperations.push({ sourcePath: internalHeftSession.heftConfiguration.tempFolderPath, includeGlobs: tempFolderGlobs }); // Delete the files if any were specified if (deleteOperations.length) { const rootFolderPath = internalHeftSession.heftConfiguration.buildFolderPath; await deleteFilesAsync(rootFolderPath, deleteOperations, cleanLogger.terminal); } // Ensure we only run the clean operation once this._isClean = true; cleanLogger.terminal.writeVerboseLine(`Finished clean (${performance.now() - startTime}ms)`); // Return success and allow for the TaskOperationRunner to execute tasks return OperationStatus.Success; } } //# sourceMappingURL=PhaseOperationRunner.js.map