Skip to content

Commit

Permalink
normalise line endings in each function
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkav committed Oct 23, 2024
1 parent 4da51ae commit 7618803
Showing 1 changed file with 23 additions and 37 deletions.
60 changes: 23 additions & 37 deletions packages/insomnia-inso/src/scripts/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,39 @@ function writeMarkdownFile(fileName: string, content: string): void {
}

function generateOptionsMarkdown(options: readonly commander.Option[], title: string): string {
if (options.length === 0) {
return '';
}

return `
## ${title}
return options.length ? `## ${title}
${options.map(option => `- \`${option.flags}\`: ${option.description}\n`).join('')}`;
${options.map(option => `- \`${option.flags}\`: ${option.description}
`).join('')}
` : '';
}

function generateSubcommandsMarkdown(commandName: string, subcommands: { name: string; description: string }[]): string {
if (subcommands.length === 0) {
return '';
}
return subcommands.length ? `## Subcommands
return `
## Subcommands
${subcommands.map(sub => `- [\`${commandName} ${sub.name}\`](/insomnia-inso/${commandName.replace(/\s+/g, '_')}_${sub.name.replace(/\s+/g, '_')}/): ${sub.description}`).join('\n')}`;
${subcommands.map(sub => `- [\`${commandName} ${sub.name}\`](/insomnia-inso/${commandName.replace(/\s+/g, '_')}_${sub.name.replace(/\s+/g, '_')}/): ${sub.description}
`).join('')}
` : '';
}

function generateCommandMarkdownContent(command: commander.Command, programOptions: readonly commander.Option[], parentName?: string): string {
export function generateCommandMarkdown(command: commander.Command, programOptions: readonly commander.Option[], parentName?: string): { name: string; fileName: string; description: string; subcommands: readonly commander.Command[] } {
const commandName = parentName ? `${parentName} ${command.name()}` : command.name();
const usage = command.usage() || '[options]';
const fileName = `${commandName.replace(/\s+/g, '_')}.md`;

let commandMarkdown = `# ${commandName}\n\n`;
commandMarkdown += `## Command Description\n\n${command.description()}\n\n`;
commandMarkdown += `## Syntax\n\n\`${commandName} ${usage}\`\n`;
writeMarkdownFile(fileName, `# ${commandName}
if (command.options.length > 0) {
commandMarkdown += generateOptionsMarkdown(command.options, 'Local Flags');
}
## Command Description
commandMarkdown += generateOptionsMarkdown(programOptions, 'Global Flags');
commandMarkdown += generateSubcommandsMarkdown(commandName, command.commands.map(sub => ({
name: sub.name(),
description: sub.description() || 'No description available',
})));
${command.description()}
return commandMarkdown;
}
## Syntax
export function generateCommandMarkdown(command: commander.Command, programOptions: readonly commander.Option[], parentName?: string): { name: string; fileName: string; description: string; subcommands: readonly commander.Command[] } {
const commandName = parentName ? `${parentName} ${command.name()}` : command.name();
const fileName = `${commandName.replace(/\s+/g, '_')}.md`;
\`${commandName} ${command.usage() || '[options]'}\`
const commandMarkdown = generateCommandMarkdownContent(command, programOptions, parentName);
writeMarkdownFile(fileName, commandMarkdown);
${command.options.length > 0 ? generateOptionsMarkdown(command.options, 'Local Flags') : ''}${generateOptionsMarkdown(programOptions, 'Global Flags')}${generateSubcommandsMarkdown(commandName, command.commands.map(sub => ({
name: sub.name(),
description: sub.description() || 'No description available',
})))}`);

return {
name: commandName,
Expand Down Expand Up @@ -100,7 +85,8 @@ export function generateDocumentation(program: commander.Command): void {
${generateOptionsMarkdown(program.options, 'Global Flags')}
## Commands
${allCommands.map(({ name, description, fileName }) => `- [\`${name}\`](/insomnia-inso/${fileName.replace('.md', '')}/): ${description}`).join('\n')}
${allCommands.map(({ name, subcommands }) => generateSubcommandsMarkdown(name, subcommands)).join('\n')}
`);
${allCommands.map(({ name, description, fileName }) => `- [\`${name}\`](/insomnia-inso/${fileName.replace('.md', '')}/): ${description}
`).join('')}
${allCommands.map(({ name, subcommands }) => `${generateSubcommandsMarkdown(name, subcommands)}
`).join('')}`);
}

0 comments on commit 7618803

Please sign in to comment.