@rushstack/heft
Version:
Build all your JavaScript projects the same way: A way that works.
76 lines • 4.1 kB
JavaScript
"use strict";
// 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.CleanAction = void 0;
const ts_command_line_1 = require("@rushstack/ts-command-line");
const operation_graph_1 = require("@rushstack/operation-graph");
const Constants_1 = require("../../utilities/Constants");
const RunAction_1 = require("./RunAction");
const DeleteFilesPlugin_1 = require("../../plugins/DeleteFilesPlugin");
const HeftActionRunner_1 = require("../HeftActionRunner");
class CleanAction extends ts_command_line_1.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 } = (0, RunAction_1.definePhaseScopingParameters)(this);
this._toParameter = toParameter;
this._toExceptParameter = toExceptParameter;
this._onlyParameter = onlyParameter;
this._verboseFlag = this.defineFlagParameter({
parameterLongName: Constants_1.Constants.verboseParameterLongName,
parameterShortName: Constants_1.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 = (0, RunAction_1.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 = (0, HeftActionRunner_1.ensureCliAbortSignal)(this._terminal);
// Record this as the start of task execution.
this._metricsCollector.setStartTime();
(0, HeftActionRunner_1.initializeHeft)(heftConfiguration, this._terminal, this._verboseFlag.value);
await (0, HeftActionRunner_1.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 (0, DeleteFilesPlugin_1.deleteFilesAsync)(rootFolderPath, deleteOperations, this._terminal);
}
return deleteOperations.length === 0 ? operation_graph_1.OperationStatus.NoOp : operation_graph_1.OperationStatus.Success;
}
}
exports.CleanAction = CleanAction;
//# sourceMappingURL=CleanAction.js.map