UNPKG

cl-generate

Version:

A cross-platform CLI tool to generate NestJS clean architecture modules

19 lines (17 loc) 601 B
#!/usr/bin/env node const fs = require("fs").promises; const { COLORS } = require("../constants/index"); module.exports = async function createFile(filePath, content) { try { if (!(await fs.stat(filePath).catch(() => false))) { await fs.writeFile(filePath, content.trim(), "utf8"); console.log(`${COLORS.GREEN}✔ Created file:${COLORS.NC} ${filePath}`); } else { console.log( `${COLORS.YELLOW}⚠ File already exists:${COLORS.NC} ${filePath}` ); } } catch (error) { throw new Error(`Failed to create file: ${filePath} - ${error.message}`); } };