UNPKG

mydata-cli

Version:

A CLI tool for interacting with MyData API and managing data. Supports login, data retrieval, and more. Built with Node.js.

155 lines (110 loc) โ€ข 3.28 kB
import { Command } from "commander"; import fs from "fs"; import path from "path"; import chalk from "chalk"; import dotenv from "dotenv"; import {glob} from "glob"; const readmeCommand = new Command("readme"); readmeCommand .description("Generate a 10/10 quality README.md from package.json and .env") .command("create") .action(() => { const root = process.cwd(); const pkgPath = path.join(root, "package.json"); const readmePath = path.join(root, "README.md"); if (!fs.existsSync(pkgPath)) { console.error(chalk.red("โŒ package.json not found.")); process.exit(1); } const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")); const { name, description, version = "1.0.0", author = "Vinoth S", license = "MIT", keywords = [], } = pkg; const repoURL = `https://github.com/vinoth82003/${name}`; const badgeKeywords = keywords .map( (kw) => `![${kw}](https://img.shields.io/badge/-${kw}-blue?style=flat-square)` ) .join(" "); // Load all .env*. files const envFiles = glob.sync(".env*"); const envVars = {}; envFiles.forEach((file) => { const result = dotenv.config({ path: path.join(root, file) }); if (result.parsed) { Object.assign(envVars, result.parsed); } }); // Create a .env section const envSection = Object.keys(envVars).length ? Object.keys(envVars) .map((key) => `${key}=<hidden>`) .join("\n") : "No environment variables found."; const readme = `# ๐Ÿ“ฆ ${name} ${description || "A modern full-stack application."} --- ## ๐Ÿ“‘ Table of Contents - [About](#about) - [Getting Started](#getting-started) - [Available Scripts](#available-scripts) - [Environment Variables](#environment-variables) - [Contributing](#contributing) - [Changelog](#changelog) - [License](#license) - [Contact](#contact) --- ## ๐Ÿง  About **${name}** is a ${description || "modern web project"}. --- ## ๐Ÿš€ Getting Started \`\`\`bash git clone ${repoURL}.git cd ${name} npm install npm run dev \`\`\` --- ## ๐Ÿงช Available Scripts From your \`package.json\`: \`\`\`json ${JSON.stringify(pkg.scripts, null, 2)} \`\`\` --- ## ๐Ÿ” Environment Variables Loaded from: ${envFiles.join(", ")} \`\`\`env ${envSection} \`\`\` --- ## ๐Ÿค Contributing 1. Fork the repo 2. Create a branch 3. Commit your changes 4. Push to your fork 5. Submit a PR --- ## ๐Ÿ“œ Changelog - \`v${version}\` โ€“ Initial release --- ## ๐Ÿ“„ License Licensed under the **${license}** license. --- ## ๐Ÿ“ฌ Contact - ๐Ÿ“ง Email: [vinothg0618@gmail.com](mailto:vinothg0618@gmail.com) - ๐Ÿ™ GitHub: [vinoth82003](https://github.com/vinoth82003) - ๐Ÿ’ผ LinkedIn: [vinoth82003](https://linkedin.com/in/vinoth82003) - ๐ŸŒ Portfolio: [vinoths.vercel.app](https://vinoths.vercel.app) --- > _Generated by [mycli](https://github.com/vinoth82003/mycli)_ `; fs.writeFileSync(readmePath, readme); console.log(chalk.green(`โœ… README.md created in ${readmePath}`)); }); export default readmeCommand;