"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAppDir = void 0;
const path = require("path");
const fs = require("fs-extra");
const chalk_1 = require("chalk");
const getConflictMsg = (projectName) => {
    return `
  The directory contains files that could conflict:

  ${(0, chalk_1.red)(projectName)}

  Either try using a new directory name, or remove the files listed above.
  `;
};
const createAppDir = (root, appName) => {
    fs.ensureDirSync(root);
    const appDirFiles = fs.readdirSync(root);
    const conflictFile = appDirFiles.includes(appName);
    // new project fail due to conflict
    if (conflictFile) {
        const conflictMsg = getConflictMsg(appName);
        throw conflictMsg;
    }
    else {
        const projectDir = path.join(root, appName);
        fs.ensureDirSync(projectDir);
        return projectDir;
    }
};
exports.createAppDir = createAppDir;
