UNPKG

constatic

Version:

Constatic is a CLI for creating and managing modern TypeScript projects, providing an organized structure and features that streamline development.

41 lines (40 loc) 908 B
// src/helpers/files.ts import fs from "node:fs/promises"; import { copy as fsCopy } from "fs-extra"; import { log } from "./log.js"; import { uiMessage } from "./ui.js"; var json = { async read(path) { const stringfiedJson = await fs.readFile(path, "utf-8"); return JSON.parse(stringfiedJson); }, async write(path, data) { const stringfiedJson = JSON.stringify(data, null, 2); fs.writeFile(path, stringfiedJson, "utf-8"); } }; async function copy(src, dest, options) { return fsCopy(src, dest, options).catch((err) => { const message = [ `src: ${src}`, `dest: ${dest}`, `${err}` ]; log.fail(uiMessage({ "pt-BR": [ "Ocorreu um erro ao tentar copiar!", ...message ].join(` `), "en-US": [ "An error occurred while trying to copy", ...message ].join(` `) })); }); } export { json, copy };