Skip to content

Commit 78f1f4c

Browse files
committed
feat: add package manager detection
1 parent 6cacc96 commit 78f1f4c

13 files changed

Lines changed: 478 additions & 96 deletions

README.md

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77

88
> CLI tool that scans JavaScript and TypeScript projects and automatically generates clean README.md files with installation, usage, scripts, environment variables, and publishing checklist.
99
10-
## Features
10+
## Features
1111

12-
- 🔍 **Smart Project Detection** — Automatically detects project types (Node.js, React, Vue, Next.js, Vite, Express, TypeScript, CLI packages)
13-
- 📦 **Package.json Analysis** — Extracts metadata, scripts, dependencies, exports, and repository info
14-
- 📝 **Auto-Generated Documentation** — Creates professional README sections with proper formatting
15-
- 🌍 **Environment Variables** — Parses `.env.example` and includes variable tables
16-
- 🎯 **NPM Scripts Table** — Generates markdown tables with human-readable script descriptions
17-
- 🛡️ **Safe by Default** — Won't overwrite existing files without `--force` flag
18-
- 🔧 **CLI & Library Support** — Handles both CLI packages and regular npm libraries
19-
- 📁 **Project Structure** — Optional file tree with `--include-tree`
20-
- **Publishing Checklist** — Built-in checklist for npm package releases
12+
- **Smart Project Detection** — Automatically detects project types (Node.js, React, Vue, Next.js, Vite, Express, TypeScript, CLI packages)
13+
- **Package.json Analysis** — Extracts metadata, scripts, dependencies, exports, and repository info
14+
- **Auto-Generated Documentation** — Creates professional README sections with proper formatting
15+
- **Environment Variables** — Parses `.env.example` and includes variable tables
16+
- **NPM Scripts Table** — Generates markdown tables with human-readable script descriptions
17+
- **Safe by Default** — Won't overwrite existing files without `--force` flag
18+
- **CLI & Library Support** — Handles both CLI packages and regular npm libraries
19+
- **Project Structure** — Optional file tree with `--include-tree`
20+
- **Publishing Checklist** — Built-in checklist for npm package releases
2121

22-
## 📦 Installation
22+
## Installation
2323

2424
### Global Installation
2525

@@ -42,7 +42,7 @@ npm install
4242
npm run build
4343
```
4444

45-
## 🚀 Usage
45+
## Usage
4646

4747
Generate a README.md in the current directory:
4848

@@ -91,7 +91,7 @@ readme-autoscan --include-tree
9191
readme-autoscan --no-checklist
9292
```
9393

94-
## 📋 CLI Options
94+
## CLI Options
9595

9696
| Option | Description |
9797
| ----------------- | -------------------------------------------------- |
@@ -103,7 +103,7 @@ readme-autoscan --no-checklist
103103
| `-v, --version` | Show package version |
104104
| `-h, --help` | Show help message |
105105

106-
## 🎯 Example Output
106+
## Example Output
107107

108108
Here's what a generated README looks like:
109109

@@ -147,7 +147,7 @@ myawesomepackage.someFunction();
147147
This project is licensed under the MIT License.
148148
```
149149

150-
## 🔍 Project Type Detection
150+
## Project Type Detection
151151

152152
README Auto Scan automatically detects these project types:
153153

@@ -161,7 +161,28 @@ README Auto Scan automatically detects these project types:
161161
| Vite | Has `vite` dependency or `vite.config.*` |
162162
| Express | Has `express` dependency |
163163

164-
## 🧪 Development
164+
## Package Manager Detection
165+
166+
README Auto Scan automatically detects your package manager from lock files and generates matching commands in Installation, Available Scripts, and Development sections.
167+
168+
| Lock File | Package Manager |
169+
| ------------------------------ | --------------- |
170+
| `package-lock.json` | npm |
171+
| `pnpm-lock.yaml` | pnpm |
172+
| `yarn.lock` | yarn |
173+
| `bun.lockb` or `bun.lock` | bun |
174+
175+
If no supported lock file is found, it falls back to npm.
176+
177+
Example: if your project contains `pnpm-lock.yaml`, generated commands use:
178+
179+
```bash
180+
pnpm install
181+
pnpm dev
182+
pnpm build
183+
```
184+
185+
## Development
165186

166187
```bash
167188
# Install dependencies
@@ -180,19 +201,25 @@ npm test
180201
npm run dev
181202
```
182203

183-
## 📁 Project Structure
204+
## Project Structure
184205

185206
```text
186207
readme-autoscan/
187208
├─ src/
188-
│ ├─ cli.ts # CLI entry point and argument parsing
189-
│ ├─ scanner.ts # Project scanning and analysis
190-
│ ├─ detector.ts # Project type detection
191-
│ ├─ generator.ts # README markdown generation
192-
│ ├─ env.ts # .env.example parsing
193-
│ ├─ scripts.ts # NPM script descriptions
194-
│ ├─ utils.ts # Utility functions
195-
│ └─ *.test.ts # Test files
209+
│ ├─ cli.ts # CLI entry point and argument parsing
210+
│ ├─ scanner.ts # Project scanning and analysis
211+
│ ├─ detector.ts # Project type detection
212+
│ ├─ generator.ts # README markdown generation
213+
│ ├─ env.ts # .env.example parsing
214+
│ ├─ scripts.ts # NPM script descriptions
215+
│ ├─ package-manager.ts # Package manager detection
216+
│ └─ utils.ts # Utility functions
217+
├─ tests/
218+
│ ├─ generator.test.ts
219+
│ ├─ package-manager.test.ts
220+
│ ├─ scripts.test.ts
221+
│ ├─ utils.test.ts
222+
│ └─ env.test.ts
196223
├─ bin/
197224
│ └─ readme-autoscan.js # Executable entry point
198225
├─ package.json
@@ -201,7 +228,7 @@ readme-autoscan/
201228
└─ LICENSE
202229
```
203230

204-
## 🏗️ Generated README Sections
231+
## Generated README Sections
205232

206233
The tool generates these sections based on your project:
207234

@@ -219,7 +246,7 @@ The tool generates these sections based on your project:
219246
12. **License** — From package.json
220247
13. **Contributing** — Standard contribution message
221248

222-
## 🤝 Contributing
249+
## Contributing
223250

224251
Contributions are welcome! Please feel free to submit a Pull Request.
225252

@@ -229,18 +256,18 @@ Contributions are welcome! Please feel free to submit a Pull Request.
229256
4. Push to the branch (`git push origin feature/amazing-feature`)
230257
5. Open a Pull Request
231258

232-
## 📄 License
259+
## License
233260

234261
This project is licensed under the MIT License — see the [LICENSE](LICENSE) file for details.
235262

236263
Copyright (c) 2026 JomsCode21
237264

238-
## 🔗 Links
265+
## Links
239266

240267
- **Repository:** [github.com/JomsCode21/README-auto-scan](https://github.com/JomsCode21/README-auto-scan)
241268
- **Issues:** [github.com/JomsCode21/README-auto-scan/issues](https://github.com/JomsCode21/README-auto-scan/issues)
242269
- **NPM Package:** [npmjs.com/package/readme-autoscan](https://www.npmjs.com/package/readme-autoscan)
243270

244271
---
245272

246-
Made with ❤️ for the JavaScript/TypeScript community
273+
Made for the JavaScript/TypeScript community

package-lock.json

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "readme-autoscan",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "CLI tool that scans JavaScript/TypeScript projects and automatically generates clean, professional README.md files with installation, usage, scripts, environment variables, and publishing checklist.",
55
"main": "dist/cli.js",
66
"types": "dist/cli.d.ts",

src/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ async function run(options: CliOptions): Promise<void> {
7979
});
8080

8181
if (options.dryRun) {
82+
console.log(pc.cyan(`Detected package manager: ${scan.packageManager}`));
8283
console.log(markdown);
8384
console.log(
8485
pc.cyan(
@@ -104,6 +105,7 @@ async function run(options: CliOptions): Promise<void> {
104105
}
105106

106107
const relativePath = path.relative(rootDir, targetPath);
108+
console.log(pc.cyan(`Detected package manager: ${scan.packageManager}`));
107109
console.log(
108110
pc.green(`✓ README.md generated successfully at ${relativePath}`),
109111
);

src/generator.ts

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ScanResult } from "./scanner";
2+
import { getPackageManager } from "./package-manager";
23

34
export interface GenerateOptions {
45
includeChecklist: boolean;
@@ -69,35 +70,27 @@ function getFeatureBullets(scan: ScanResult): string[] {
6970
}
7071

7172
function getInstallationSection(scan: ScanResult): string {
73+
const pm = getPackageManager(scan.packageManager);
7274
const lines = ["## Installation"];
7375

76+
lines.push("");
77+
lines.push("Install dependencies:");
78+
lines.push(["```bash", pm.install, "```"].join("\n"));
79+
7480
if (scan.hasBin) {
7581
lines.push("");
76-
lines.push("Install globally (optional):");
77-
lines.push(
78-
["```bash", `npm install -g ${scan.packageName}`, "```"].join("\n"),
79-
);
80-
lines.push("");
81-
lines.push("Or use with npx (no installation):");
82-
lines.push(["```bash", `npx ${scan.packageName}`, "```"].join("\n"));
83-
} else {
84-
lines.push("");
85-
lines.push(
86-
["```bash", `npm install ${scan.packageName}`, "```"].join("\n"),
87-
);
88-
lines.push("");
89-
lines.push("Or with yarn:");
90-
lines.push(["```bash", `yarn add ${scan.packageName}`, "```"].join("\n"));
82+
lines.push("Run the CLI (if installed globally or linked):");
83+
lines.push(["```bash", scan.binCommands[0] ?? scan.packageName, "```"].join("\n"));
9184
}
9285

9386
lines.push("");
94-
lines.push("For local development:");
87+
lines.push("For local setup from repository:");
9588
lines.push(
9689
[
9790
"```bash",
9891
"git clone <repository-url>",
9992
"cd " + scan.packageName,
100-
"npm install",
93+
pm.install,
10194
"```",
10295
].join("\n"),
10396
);
@@ -106,6 +99,7 @@ function getInstallationSection(scan: ScanResult): string {
10699
}
107100

108101
function getUsageSection(scan: ScanResult): string {
102+
const pm = getPackageManager(scan.packageManager);
109103
const lines = ["## Usage"];
110104

111105
if (scan.hasBin && scan.binCommands.length > 0) {
@@ -139,14 +133,14 @@ function getUsageSection(scan: ScanResult): string {
139133
);
140134
}
141135

142-
// Add npm script usage if available
136+
// Add package manager script usage if available
143137
const devScript = scan.scripts.find(
144138
(s) => s.name === "dev" || s.name === "start",
145139
);
146140
if (devScript) {
147141
lines.push("");
148142
lines.push("For development:");
149-
lines.push(["```bash", `npm run ${devScript.name}`, "```"].join("\n"));
143+
lines.push(["```bash", pm.run(devScript.name), "```"].join("\n"));
150144
}
151145

152146
return lines.join("\n");
@@ -192,18 +186,15 @@ export function generateReadme(
192186

193187
// Available Scripts
194188
if (scan.scripts.length > 0) {
189+
const pm = getPackageManager(scan.packageManager);
195190
sections.push("## Available Scripts");
196191
sections.push("");
197192
sections.push("| Script | Description | Command |");
198193
sections.push("|--------|-------------|---------|");
199194
scan.scripts.forEach((script) => {
200-
const cleanCommand = script.command
201-
.replace(/\|/g, "\\|")
202-
.substring(0, 40);
203-
const displayCmd =
204-
script.command.length > 40 ? cleanCommand + "..." : cleanCommand;
195+
const runCommand = pm.run(script.name);
205196
sections.push(
206-
`| \`${script.name}\` | ${script.description} | \`${displayCmd}\` |`,
197+
`| \`${script.name}\` | ${script.description} | \`${runCommand}\` |`,
207198
);
208199
});
209200
}
@@ -255,24 +246,30 @@ export function generateReadme(
255246
}
256247

257248
// Development
258-
const devScript = scan.scripts.find((s) => s.name === "dev");
259-
const hasDevScript = !!devScript;
249+
const hasCheckScript = scan.scripts.some((s) => s.name === "check");
250+
const hasBuildScript = scan.scripts.some((s) => s.name === "build");
251+
const hasDevScript = scan.scripts.some((s) => s.name === "dev");
252+
const pm = getPackageManager(scan.packageManager);
260253

261254
sections.push("## Development");
262255
sections.push("");
263256
sections.push("```bash");
264257
sections.push("# Install dependencies");
265-
sections.push("npm install");
266-
sections.push("");
267-
sections.push("# Run type checking");
268-
sections.push("npm run check");
269-
sections.push("");
270-
sections.push("# Build the project");
271-
sections.push("npm run build");
258+
sections.push(pm.install);
259+
if (hasCheckScript) {
260+
sections.push("");
261+
sections.push("# Run type checking");
262+
sections.push(pm.run("check"));
263+
}
264+
if (hasBuildScript) {
265+
sections.push("");
266+
sections.push("# Build the project");
267+
sections.push(pm.run("build"));
268+
}
272269
if (hasDevScript) {
273270
sections.push("");
274271
sections.push("# Start development mode");
275-
sections.push("npm run dev");
272+
sections.push(pm.run("dev"));
276273
}
277274
sections.push("```");
278275

0 commit comments

Comments
 (0)