Skip to content

feat: added init command#1748

Open
separatrixxx wants to merge 2 commits intomasterfrom
yfm-init
Open

feat: added init command#1748
separatrixxx wants to merge 2 commits intomasterfrom
yfm-init

Conversation

@separatrixxx
Copy link
Contributor

An init command has been added to yfm, allowing you to create an empty documentation template.

@separatrixxx separatrixxx requested a review from a team as a code owner March 10, 2026 12:38
@separatrixxx separatrixxx requested review from goldserg and removed request for a team March 10, 2026 12:38
@sonarqubecloud
Copy link

@martyanovandrey
Copy link
Contributor

martyanovandrey commented Mar 11, 2026

  1. The interactive mode is the most important. Currently, it is a pure CLI with flags, but users expect a wizard like npm init for the init command: a series of questions about the name, languages, and default language. Without the interactive mode, the user must know all the flags beforehand.

  2. --force — the command currently fails on a non-empty directory. The --force or --overwrite flag would allow you to reinitialize an existing project.

  3. --dry-run — show what will be created without actually creating the files. This is useful for scripts and CI.

  4. Templates — currently, there is only one hard-coded template. The --template minimal|full|blog etc flag or support for external templates would provide flexibility.

  5. Don't forget to add this to the documentation guide. And in the cli readme, briefly

);
}

function dirname(filePath: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

The dirname function is already available in node:path


async action() {
const {output, langs, defaultLang, name, header} = this.config;
const lang = defaultLang || langs[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

If you pass --langs ru --default-lang en, then .yfm will write lang: en, even though en is not in langs. You need to check:

if (defaultLang && !langs.includes(defaultLang)) {
    throw new Error(`--default-lang "${defaultLang}" is not in --langs [${langs.join(', ')}]`);
}

export function yfmConfig(langs: string[], defaultLang: string): string {
if (langs.length > 1) {
const langList = langs.map((l) => `'${l}'`).join(', ');
return `lang: ${defaultLang}\nlangs: [${langList}]\n`;
Copy link
Contributor

Choose a reason for hiding this comment

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

a comment with a link to documentation for only one language?

header: boolean;
};

export type InitConfig = BaseConfig & {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are InitArgs and InitConfig the same types?

header: boolean;
};

@withConfigDefaults(() => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

default ru? have we had this somewhere before? if not, it's better to en

return `lang: ${defaultLang}\nlangs: [${langList}]\n`;
}

return `# YFM project config\n# Docs: https://diplodoc.com/docs/ru/project/config\n\nlang: ${defaultLang}\n`;
Copy link
Contributor

Choose a reason for hiding this comment

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

a link to the ru doc?

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.

2 participants