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
JavaScript
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) =>
``
)
.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;