"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListPluginsCommand = void 0;
const helpers_1 = require("../../common/helpers");
const yok_1 = require("../../common/yok");
const color_1 = require("../../color");
class ListPluginsCommand {
    constructor($pluginsService, $projectData, $logger) {
        this.$pluginsService = $pluginsService;
        this.$projectData = $projectData;
        this.$logger = $logger;
        this.allowedParameters = [];
        this.$projectData.initializeProjectData();
    }
    async execute(args) {
        const installedPlugins = this.$pluginsService.getDependenciesFromPackageJson(this.$projectData.projectDir);
        const headers = ["Plugin", "Version"];
        const dependenciesData = this.createTableCells(installedPlugins.dependencies);
        const dependenciesTable = (0, helpers_1.createTable)(headers, dependenciesData);
        this.$logger.info("Dependencies:");
        this.$logger.info(dependenciesTable.toString());
        if (installedPlugins.devDependencies &&
            installedPlugins.devDependencies.length) {
            const devDependenciesData = this.createTableCells(installedPlugins.devDependencies);
            const devDependenciesTable = (0, helpers_1.createTable)(headers, devDependenciesData);
            this.$logger.info("Dev Dependencies:");
            this.$logger.info(devDependenciesTable.toString());
        }
        else {
            this.$logger.info("There are no dev dependencies.");
        }
        const viewDependenciesCommand = color_1.color.cyan("npm view <pluginName> grep dependencies");
        const viewDevDependenciesCommand = color_1.color.cyan("npm view <pluginName> grep devDependencies");
        this.$logger.warn("NOTE:");
        this.$logger.warn(`If you want to check the dependencies of installed plugin use ${viewDependenciesCommand}`);
        this.$logger.warn(`If you want to check the dev dependencies of installed plugin use ${viewDevDependenciesCommand}`);
    }
    createTableCells(items) {
        return items.map((item) => [item.name, item.version]);
    }
}
exports.ListPluginsCommand = ListPluginsCommand;
yok_1.injector.registerCommand("plugin|*list", ListPluginsCommand);
