Skip to content

feat(auto-readme): add generate subcommand for default config#290

Open
stephansama wants to merge 2 commits into
mainfrom
stephansama/ste-13-create-config-generator-for-auto-readme
Open

feat(auto-readme): add generate subcommand for default config#290
stephansama wants to merge 2 commits into
mainfrom
stephansama/ste-13-create-config-generator-for-auto-readme

Conversation

@stephansama

Copy link
Copy Markdown
Owner

Closes STE-13

Adds an auto-readme generate [filename] subcommand that writes a fully-populated default config file. Output format is detected from the filename extension:

  • .json (default) → pretty-printed JSON
  • .yaml / .yml → YAML via the yaml package
  • .toml → TOML via smol-toml

Defaults are derived by passing an empty seed through configSchema (with empty arrays for the two top-level fields that have no schema default — affectedRegexes, collapseHeadings).

Refuses to overwrite an existing file unless --force / -f is passed.

Acceptance criteria

  • auto-readme generate writes .autoreadmerc.json with all defaults
  • auto-readme generate .autoreadmerc.yaml writes YAML
  • auto-readme generate .autoreadmerc.toml writes TOML
  • Errors (with clear message) if the file already exists and --force is not passed
  • The generated file passes back through configSchema.parse() without errors (round-trip safe by construction)

@vercel

vercel Bot commented May 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
packages Ready Ready Preview, Comment May 18, 2026 3:34am

@changeset-bot

changeset-bot Bot commented May 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 802e2a1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@stephansama has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 58 minutes and 30 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d28880fa-d3da-4706-a76b-3df68fbb6f1b

📥 Commits

Reviewing files that changed from the base of the PR and between 9a84b42 and 802e2a1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • core/auto-readme/package.json
  • core/auto-readme/src/cli.ts
  • core/auto-readme/src/generate.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch stephansama/ste-13-create-config-generator-for-auto-readme

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new generate subcommand to the CLI, allowing users to create default configuration files in JSON, TOML, or YAML formats. Feedback suggests using dynamic imports in the CLI entry point to optimize startup time by deferring the loading of heavy dependencies like yaml and smol-toml. Additionally, it is recommended to use the project's internal logging and error utilities for consistency and to remove an unused type definition in the new module.

Comment thread core/auto-readme/src/cli.ts Outdated
Comment on lines +3 to +8
import { generate } from "./generate";
import { run } from "./index";
await run();

const [subcommand, ...rest] = process.argv.slice(2);

await (subcommand === "generate" ? generate(rest) : run());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Importing the generate module at the top level causes heavy dependencies like yaml and smol-toml to be loaded even when the generate subcommand is not used. This increases the startup time for the main run command. Using a dynamic import for the generate subcommand will improve the CLI's responsiveness for the primary use case.

import { run } from "./index";

const [subcommand, ...rest] = process.argv.slice(2);

if (subcommand === "generate") {
	const { generate } = await import("./generate");
	await generate(rest);
} else {
	await run();
}

Comment on lines +1 to +32
import * as fsp from "node:fs/promises";
import path from "node:path";
import { stringify as stringifyToml } from "smol-toml";
import yaml from "yaml";

import { configSchema } from "./schema";

export type GenerateOptions = {
filename?: string;
force?: boolean;
};

const DEFAULT_FILENAME = ".autoreadmerc.json";

export async function generate(argv: readonly string[]): Promise<void> {
const force = argv.includes("--force") || argv.includes("-f");
const positional = argv.find((argument) => !argument.startsWith("-"));
const filename = positional || DEFAULT_FILENAME;

if (!force && (await fileExists(filename))) {
throw new Error(
`Refusing to overwrite existing file: ${filename}. Pass --force to overwrite.`,
);
}

const defaults = buildDefaults();
const contents = serialize(filename, defaults);

await fsp.writeFile(filename, contents, "utf8");
// eslint-disable-next-line no-console
console.log(`Wrote ${filename}`);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This refactor improves the generate module by:

  1. Removing the unused GenerateOptions type to keep the codebase clean.
  2. Adhering to the project's established logging and error handling patterns by using INFO and ERROR from ./log instead of console.log and raw Error throws. This ensures that the output respects verbosity settings and follows the consistent UI style of the tool.
import * as fsp from "node:fs/promises";
import path from "node:path";
import { stringify as stringifyToml } from "smol-toml";
import yaml from "yaml";

import { ERROR, INFO } from "./log";
import { configSchema } from "./schema";

const DEFAULT_FILENAME = ".autoreadmerc.json";

export async function generate(argv: readonly string[]): Promise<void> {
	const force = argv.includes("--force") || argv.includes("-f");
	const positional = argv.find((argument) => !argument.startsWith("-"));
	const filename = positional || DEFAULT_FILENAME;

	if (!force && (await fileExists(filename))) {
		return ERROR(
			`Refusing to overwrite existing file: ${filename}. Pass --force to overwrite.`,
		);
	}

	const defaults = buildDefaults();
	const contents = serialize(filename, defaults);

	await fsp.writeFile(filename, contents, "utf8");
	INFO(`Wrote ${filename}`);
}

@codecov

codecov Bot commented May 18, 2026

Copy link
Copy Markdown

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant