"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostInstallCliCommand = void 0;
const helpers_1 = require("../common/helpers");
const yok_1 = require("../common/yok");
const color_1 = require("../color");
class PostInstallCliCommand {
    constructor($fs, $commandsService, $helpService, $settingsService, $analyticsService, $logger, $hostInfo) {
        this.$fs = $fs;
        this.$commandsService = $commandsService;
        this.$helpService = $helpService;
        this.$settingsService = $settingsService;
        this.$analyticsService = $analyticsService;
        this.$logger = $logger;
        this.$hostInfo = $hostInfo;
        this.disableAnalytics = true;
        this.allowedParameters = [];
    }
    async execute(args) {
        const isRunningWithSudoUser = !!process.env.SUDO_USER;
        if (!this.$hostInfo.isWindows) {
            if (isRunningWithSudoUser) {
                await this.$fs.setCurrentUserAsOwner(this.$settingsService.getProfileDir(), process.env.SUDO_USER);
            }
        }
        const canExecutePostInstallTask = !isRunningWithSudoUser || (0, helpers_1.doesCurrentNpmCommandMatch)([/^--unsafe-perm$/]);
        if (canExecutePostInstallTask) {
            await this.$helpService.generateHtmlPages();
            await this.$analyticsService.checkConsent();
            await this.$commandsService.tryExecuteCommand("autocomplete", []);
        }
    }
    async postCommandAction(args) {
        this.$logger.info("");
        this.$logger.info(color_1.color.green.bold("You have successfully installed the NativeScript CLI!"));
        this.$logger.info("");
        this.$logger.info("Your next step is to create a new project:");
        this.$logger.info(color_1.color.green.bold("ns create"));
        this.$logger.info("");
        this.$logger.printMarkdown("If you have any questions, check Stack Overflow: `https://stackoverflow.com/questions/tagged/nativescript` and our public Discord channel: `https://nativescript.org/discord`");
    }
}
exports.PostInstallCliCommand = PostInstallCliCommand;
yok_1.injector.registerCommand("post-install-cli", PostInstallCliCommand);
