"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostInstallCliCommand = void 0;
const helpers_1 = require("../common/helpers");
const yok_1 = require("../common/yok");
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 = [];
    }
    execute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            const isRunningWithSudoUser = !!process.env.SUDO_USER;
            if (!this.$hostInfo.isWindows) {
                if (isRunningWithSudoUser) {
                    yield this.$fs.setCurrentUserAsOwner(this.$settingsService.getProfileDir(), process.env.SUDO_USER);
                }
            }
            const canExecutePostInstallTask = !isRunningWithSudoUser || helpers_1.doesCurrentNpmCommandMatch([/^--unsafe-perm$/]);
            if (canExecutePostInstallTask) {
                yield this.$helpService.generateHtmlPages();
                yield this.$analyticsService.checkConsent();
                yield this.$commandsService.tryExecuteCommand("autocomplete", []);
            }
        });
    }
    postCommandAction(args) {
        return __awaiter(this, void 0, void 0, function* () {
            this.$logger.info("");
            this.$logger.info("You have successfully installed the NativeScript CLI!".green.bold);
            this.$logger.info("");
            this.$logger.info("Your next step is to create a new project:");
            this.$logger.info("ns create".green.bold);
            this.$logger.info("");
            this.$logger.printMarkdown("New to NativeScript?".bold +
                " Try the tutorials in NativeScript Playground: `https://play.nativescript.org`");
            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);
