"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.PurgeAction = void 0;
const terminal_1 = require("@rushstack/terminal");
const BaseRushAction_1 = require("./BaseRushAction");
const Stopwatch_1 = require("../../utilities/Stopwatch");
const PurgeManager_1 = require("../../logic/PurgeManager");
const UnlinkManager_1 = require("../../logic/UnlinkManager");
const actionNameConstants_1 = require("../../utilities/actionNameConstants");
class PurgeAction extends BaseRushAction_1.BaseRushAction {
    constructor(parser) {
        super({
            actionName: actionNameConstants_1.PURGE_ACTION_NAME,
            summary: 'For diagnostic purposes, use this command to delete caches and other temporary files used by Rush',
            documentation: 'The "rush purge" command is used to delete temporary files created by Rush.  This is' +
                ' useful if you are having problems and suspect that cache files may be corrupt.',
            parser
        });
        this._unsafeParameter = this.defineFlagParameter({
            parameterLongName: '--unsafe',
            description: '(UNSAFE!) Also delete shared files such as the package manager instances stored in' +
                ' the ".rush" folder in the user\'s home directory.  This is a more aggressive fix that is' +
                ' NOT SAFE to run in a live environment because it will cause other concurrent Rush processes to fail.'
        });
    }
    async runAsync() {
        const stopwatch = Stopwatch_1.Stopwatch.start();
        const unlinkManager = new UnlinkManager_1.UnlinkManager(this.rushConfiguration);
        const purgeManager = new PurgeManager_1.PurgeManager(this.rushConfiguration, this.rushGlobalFolder);
        await unlinkManager.unlinkAsync(/*force:*/ true);
        if (this._unsafeParameter.value) {
            purgeManager.purgeUnsafe();
        }
        else {
            purgeManager.purgeNormal();
        }
        await purgeManager.startDeleteAllAsync();
        // eslint-disable-next-line no-console
        console.log('\n' +
            terminal_1.Colorize.green(`Rush purge started successfully and will complete asynchronously. (${stopwatch.toString()})`));
    }
}
exports.PurgeAction = PurgeAction;
//# sourceMappingURL=PurgeAction.js.map