cl-generate
Version:
A cross-platform CLI tool to generate NestJS clean architecture modules
22 lines (20 loc) • 616 B
JavaScript
const fs = require("fs").promises;
const path = require("path");
const { COLORS } = require("../constants/index");
module.exports = async function createDir(dirPath) {
try {
await fs.mkdir(dirPath, { recursive: true });
console.log(`${COLORS.GREEN}✔ Created directory:${COLORS.NC} ${dirPath}`);
} catch (error) {
if (error.code === "EEXIST") {
console.log(
`${COLORS.YELLOW}⚠ Directory already exists:${COLORS.NC} ${dirPath}`
);
} else {
throw new Error(
`Failed to create directory: ${dirPath} - ${error.message}`
);
}
}
};