Skip to content

feat: added init command#1748

Merged
separatrixxx merged 5 commits intomasterfrom
yfm-init
Apr 6, 2026
Merged

feat: added init command#1748
separatrixxx merged 5 commits intomasterfrom
yfm-init

Conversation

@separatrixxx
Copy link
Copy Markdown
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
@martyanovandrey
Copy link
Copy Markdown
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

Comment thread src/commands/init/index.ts Outdated
);
}

function dirname(filePath: string): string {
Copy link
Copy Markdown
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

Comment thread src/commands/init/index.ts Outdated

async action() {
const {output, langs, defaultLang, name, header} = this.config;
const lang = defaultLang || langs[0];
Copy link
Copy Markdown
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(', ')}]`);
}

Comment thread src/commands/init/templates.ts Outdated
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
Copy Markdown
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?

Comment thread src/commands/init/index.ts Outdated
header: boolean;
};

export type InitConfig = BaseConfig & {
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread src/commands/init/templates.ts Outdated
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
Copy Markdown
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?

Comment thread src/commands/init/templates.ts Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can do without \n here, because there is already a line break, and there is no \n in the toc and index templates below

@separatrixxx separatrixxx marked this pull request as draft April 3, 2026 09:02
@separatrixxx separatrixxx marked this pull request as ready for review April 6, 2026 14:25
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 6, 2026

@separatrixxx separatrixxx merged commit 16a26b7 into master Apr 6, 2026
11 of 12 checks passed
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.

4 participants