"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoveLinksAction = void 0;
exports.removeLinksAsync = removeLinksAsync;
const node_path_1 = __importDefault(require("node:path"));
const node_core_library_1 = require("@rushstack/node-core-library");
const ts_command_line_1 = require("@rushstack/ts-command-line");
const CreateLinksUtilities_1 = require("../../utilities/CreateLinksUtilities");
const constants_1 = require("../../utilities/constants");
async function removeLinksAsync(terminal, targetRootFolder, extractorMetadataObject) {
    await node_core_library_1.Async.forEachAsync(extractorMetadataObject.links, async ({ linkPath }) => {
        const newLinkPath = node_path_1.default.join(targetRootFolder, linkPath);
        terminal.writeVerboseLine(`Removing link at path "${newLinkPath}"`);
        await node_core_library_1.FileSystem.deleteFileAsync(newLinkPath, { throwIfNotExists: false });
    }, { concurrency: constants_1.MAX_CONCURRENCY });
}
class RemoveLinksAction extends ts_command_line_1.CommandLineAction {
    constructor(terminal) {
        super({
            actionName: 'remove',
            summary: 'Remove symlinks created by the "create" action',
            documentation: 'This action removes the symlinks created by the "create" action.'
        });
        this._terminal = terminal;
    }
    async onExecuteAsync() {
        const extractorMetadataObject = await (0, CreateLinksUtilities_1.getExtractorMetadataAsync)();
        this._terminal.writeLine(`Removing links for extraction at path "${constants_1.TARGET_ROOT_FOLDER}"`);
        await removeLinksAsync(this._terminal, constants_1.TARGET_ROOT_FOLDER, extractorMetadataObject);
    }
}
exports.RemoveLinksAction = RemoveLinksAction;
//# sourceMappingURL=RemoveLinksAction.js.map