@rushstack/heft
Version:
Build all your JavaScript projects the same way: A way that works.
54 lines • 2.58 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.PhaseOperationRunner = void 0;
const operation_graph_1 = require("@rushstack/operation-graph");
const DeleteFilesPlugin_1 = require("../../plugins/DeleteFilesPlugin");
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 operation_graph_1.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 (0, DeleteFilesPlugin_1.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 operation_graph_1.OperationStatus.Success;
}
}
exports.PhaseOperationRunner = PhaseOperationRunner;
//# sourceMappingURL=PhaseOperationRunner.js.map