(program: commander.Command)
| 84 | } |
| 85 | |
| 86 | export function generateDocumentation(program: commander.Command): void { |
| 87 | if (!fs.existsSync(DOCS_DIR)) { |
| 88 | fs.mkdirSync(DOCS_DIR, { recursive: true }); |
| 89 | } |
| 90 | |
| 91 | const allCommands: any[] = []; |
| 92 | |
| 93 | program.commands.forEach(command => { |
| 94 | const commandData = generateCommandMarkdown(command, program.options, ''); |
| 95 | |
| 96 | allCommands.push({ |
| 97 | name: commandData.name, |
| 98 | description: commandData.description, |
| 99 | fileName: commandData.fileName, |
| 100 | subcommands: commandData.subcommands.map(sub => ({ |
| 101 | name: sub.name(), |
| 102 | description: sub.description() || 'No description available', |
| 103 | fileName: `${commandData.name.replace(/\s+/g, '_')}_${sub.name().replace(/\s+/g, '_')}.md`, |
| 104 | })), |
| 105 | }); |
| 106 | |
| 107 | commandData.subcommands.forEach(sub => { |
| 108 | generateCommandMarkdown(sub, program.options, commandData.name); |
| 109 | }); |
| 110 | }); |
| 111 | |
| 112 | writeMarkdownFile( |
| 113 | 'index.md', |
| 114 | `--- |
| 115 | title: CLI Documentation |
| 116 | --- |
| 117 | |
| 118 | ${generateOptionsMarkdown(program.options, 'Global Flags')} |
| 119 | |
| 120 | ## Commands |
| 121 | |
| 122 | ${allCommands |
| 123 | .map( |
| 124 | ({ |
| 125 | name, |
| 126 | description, |
| 127 | fileName, |
| 128 | }) => `- [\`${name}\`](/inso-cli/reference/${fileName.replace('.md', '')}/{{page.release}}/): ${description} |
| 129 | `, |
| 130 | ) |
| 131 | .join('')} |
| 132 | ${allCommands |
| 133 | .map( |
| 134 | ({ name, subcommands }) => `${generateSubcommandsMarkdown(name, subcommands)} |
| 135 | `, |
| 136 | ) |
| 137 | .join('')}`, |
| 138 | ); |
| 139 | } |
no test coverage detected