/
pronix432
/
ttcodegen
Обзор
Документация
Войти
/
pronix432
/
ttcodegen
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/core.ts
38 строк
1 KB
Iskander Karimov
Add slash
30 май 2023, 16:10
30 май 2023, 16:10
f38d98b
Код
Авторство
О чём код?
import { glob } from "glob"; import { FileData, Params, RenderProps } from "./types"; import { createFile, getFileContent } from "./filesManager"; import { renderTemplate } from "./templateEngine"; import { join } from "path"; import { drawCreatedFiles, formatTemplatePath, slash } from "./utils"; const renderFile = async ( templatePath: string, params: Params ): Promise<FileData> => { const template = await getFileContent(templatePath); const content = renderTemplate(template, params); const preparedPath = renderTemplate(templatePath, params); const formattedPath = formatTemplatePath( preparedPath, join(params.path, params.name) ); return { path: formattedPath, content }; }; export async function renderFiles({ option, params, config }: RenderProps) { const searchPath = `**${slash}${config.templatesDirectoryPath}/${option.name}${slash}**${slash}*.hbs`; const templateFilesPaths = await glob(searchPath); const files = await Promise.all( templateFilesPaths.map((templatePath) => renderFile(templatePath, params)) ); files.map(({ path, content }) => createFile(`${path}`, content)); drawCreatedFiles(files); }