"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPackageInfo = exports.isDirectory = exports.ejsWriteFile = void 0;
/**
 * 文件相关操作在这里维护
 */
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const chalk_1 = __importDefault(require("chalk"));
const ejs_1 = __importDefault(require("ejs"));
const fsEx = require('fs-extra');
/**
 * 动态渲染文件内容并写入到某文件
 * @param {string} src 模板绝对路径
 * @param {string} dist 写入到绝对路径
 * @param {object} data 模板参数
 * @returns
 */
function ejsWriteFile(src, dist, data) {
    return new Promise((resolve) => {
        ejs_1.default.renderFile(src, data, {}, (err, res) => {
            if (err) {
                console.log(chalk_1.default.red(`${err}`));
                resolve(false);
                return;
            }
            fsEx.writeFileSync(dist, res);
            resolve(true);
        });
    });
}
exports.ejsWriteFile = ejsWriteFile;
// 判断是否是个目录
function isDirectory(path) {
    return fs_1.default.statSync(path).isDirectory();
}
exports.isDirectory = isDirectory;
function getPackageInfo() {
    const packagePath = path_1.default.resolve(process.cwd(), './package.json');
    if (!fsEx.pathExistsSync(packagePath)) {
        throw new Error(chalk_1.default.red(`error: 当前路径不存在package.json`));
    }
    const json = fs_1.default.readFileSync(packagePath).toString();
    return JSON.parse(json);
}
exports.getPackageInfo = getPackageInfo;
exports.default = {
    ejsWriteFile,
    isDirectory,
    getPackageInfo
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmlsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3V0aWxzL2ZpbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUE7O0dBRUc7QUFDSCxnREFBdUI7QUFDdkIsNENBQW1CO0FBQ25CLGtEQUF5QjtBQUN6Qiw4Q0FBcUI7QUFDckIsTUFBTSxJQUFJLEdBQUcsT0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