"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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_extra_1 = __importDefault(require("fs-extra"));
const inquirer_1 = __importDefault(require("inquirer"));
const chalk_1 = __importDefault(require("chalk"));
const util_1 = require("../../util");
function initDir(targetdir, inCurrent = false) {
    return __awaiter(this, void 0, void 0, function* () {
        if (fs_extra_1.default.pathExistsSync(targetdir)) {
            yield util_1.clearConsole();
            if (inCurrent) {
                const { ok } = (yield inquirer_1.default.prompt([
                    {
                        name: 'ok',
                        type: 'confirm',
                        message: '是否在当前目录下生成新项目？',
                    },
                ]));
                if (!ok) {
                    return;
                }
            }
            else {
                const { action } = yield inquirer_1.default.prompt([
                    {
                        name: 'action',
                        type: 'list',
                        message: `目标路径 ${chalk_1.default.cyan(targetdir)} 已存在。`,
                        choices: [
                            { name: '覆盖', value: 'override' },
                            { name: '合并', value: 'merge' },
                            { name: '忽略', value: false },
                        ],
                    },
                ]);
                console.log(action);
                if (!action) {
                    return;
                }
                if (action === 'override') {
                    console.log(`\n 删除路径中 ${chalk_1.default.cyan(targetdir)}...`);
                    yield fs_extra_1.default.removeSync(targetdir);
                }
            }
        }
    });
}
exports.initDir = initDir;
//# sourceMappingURL=inquirerScripts.js.map