|
| 1 | +import * as fs from 'fs'; |
| 2 | +import * as path from 'path'; |
| 3 | +import { logging, tags } from '@angular-devkit/core'; |
| 4 | + |
| 5 | +export default async function () { |
| 6 | + const commandsPath = __dirname + '/../../../packages/@angular/cli/commands'; |
| 7 | + const commandFiles = fs.readdirSync(commandsPath); |
| 8 | + |
| 9 | + for (const commandFile of commandFiles) { |
| 10 | + const commandConstructor = require(path.join(commandsPath, commandFile)).default; |
| 11 | + const command = new commandConstructor(undefined, new logging.NullLogger()); |
| 12 | + |
| 13 | + if (command.hidden) { |
| 14 | + continue; |
| 15 | + } |
| 16 | + |
| 17 | + try { |
| 18 | + await command.initialize({}); |
| 19 | + } catch { |
| 20 | + console.log('initialize failed: ' + commandFile); |
| 21 | + } |
| 22 | + |
| 23 | + let optionText; |
| 24 | + if (!command.options) { |
| 25 | + optionText = ''; |
| 26 | + } else { |
| 27 | + optionText = (command.options as any[]) |
| 28 | + .filter(option => !option.hidden) |
| 29 | + .map(option => { |
| 30 | + let defaultText = ''; |
| 31 | + if (option.default) { |
| 32 | + defaultText = `<em>default value: ${option.default}</em>`; |
| 33 | + } |
| 34 | + let aliasText = ''; |
| 35 | + if (option.aliases && option.aliases.length > 0) { |
| 36 | + aliasText = (option.aliases as string[]) |
| 37 | + .map(alias => '<code>' + (alias.length === 1 ? '-' : '--') + alias + '</code>') |
| 38 | + .join(','); |
| 39 | + aliasText = ` (aliases: ${aliasText})`; |
| 40 | + } |
| 41 | + |
| 42 | + return tags.stripIndent` |
| 43 | + <details> |
| 44 | + <summary>${option.name}</summary> |
| 45 | + <p> |
| 46 | + <code>--${option.name}</code>${aliasText} ${defaultText} |
| 47 | + </p> |
| 48 | + <p> |
| 49 | + ${option.description} |
| 50 | + </p> |
| 51 | + </details> |
| 52 | + `; |
| 53 | + }).join('\n'); |
| 54 | + } |
| 55 | + |
| 56 | + const docFile = path.join( |
| 57 | + __dirname, |
| 58 | + '../../../docs/documentation/', |
| 59 | + path.basename(commandFile, '.ts') + '.md'); |
| 60 | + |
| 61 | + let docText; |
| 62 | + if (fs.existsSync(docFile)) { |
| 63 | + docText = fs.readFileSync(docFile, 'utf8'); |
| 64 | + docText = docText.slice(0, docText.indexOf('## Options') + 10); |
| 65 | + } else { |
| 66 | + // tslint:disable:max-line-length |
| 67 | + docText = tags.stripIndent` |
| 68 | + <!-- Links in /docs/documentation should NOT have \`.md\` at the end, because they end up in our wiki at release. --> |
| 69 | +
|
| 70 | + # ng ${command.name} |
| 71 | +
|
| 72 | + ## Overview |
| 73 | + ${command.description} |
| 74 | +
|
| 75 | + ## Options |
| 76 | + `; |
| 77 | + // tslint:enable:max-line-length |
| 78 | + } |
| 79 | + |
| 80 | + const finalText = docText + '\n' + (optionText ? optionText : 'None.') + '\n'; |
| 81 | + fs.writeFileSync(docFile, finalText); |
| 82 | + } |
| 83 | +} |
0 commit comments