Skip to content

Commit b6f5438

Browse files
committed
build: basic command wiki documentation tool
1 parent 0bd1f61 commit b6f5438

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"scripts": {
1212
"crazy2e": "echo This is crazy! Youre INSANE; npm run test:e2e -- --noproject ''; npm run test:e2e -- --nb-shards=4 --shard=0 --nobuild --nolink & npm run test:e2e -- --nb-shards=4 --shard=1 --nobuild --nolink & npm run test:e2e -- --nb-shards=4 --shard=2 --nobuild --nolink & npm run test:e2e -- --nb-shards=4 --shard=3 --nobuild --nolink & wait",
1313
"build": "node scripts/run-tool.js publish build",
14+
"docs": "node scripts/run-tool.js publish docs",
1415
"test": "npm-run-all -c test:packages test:cli test:deps test:licenses test:messages",
1516
"e2e": "npm run test:e2e",
1617
"e2e:nightly": "node tests/run_e2e.js --nightly",

tools/publish/src/generate-docs.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
if (command.scope == 0 || command.scope == 2) {
18+
await command.initialize({});
19+
}
20+
21+
let optionText;
22+
if (!command.options) {
23+
optionText = '';
24+
} else {
25+
optionText = (command.options as any[])
26+
.filter(option => !option.hidden)
27+
.map(option => {
28+
let defaultText = '';
29+
if (option.default) {
30+
defaultText = `<em>default value: ${option.default}</em>`;
31+
}
32+
let aliasText = '';
33+
if (option.aliases && option.aliases.length > 0) {
34+
aliasText = (option.aliases as string[])
35+
.map(alias => '<code>' + (alias.length === 1 ? '-' : '--') + alias + '</code>')
36+
.join(',');
37+
aliasText = ` (aliases: ${aliasText})`;
38+
}
39+
40+
return tags.stripIndent`
41+
<details>
42+
<summary>${option.name}</summary>
43+
<p>
44+
<code>--${option.name}</code>${aliasText} ${defaultText}
45+
</p>
46+
<p>
47+
${option.description}
48+
</p>
49+
</details>
50+
`;
51+
}).join('\n');
52+
}
53+
54+
const docFile = path.join(
55+
__dirname,
56+
'../../../docs/documentation/',
57+
path.basename(commandFile, '.ts') + '.md');
58+
59+
let docText;
60+
if (fs.existsSync(docFile)) {
61+
docText = fs.readFileSync(docFile, 'utf8');
62+
docText = docText.slice(0, docText.indexOf('## Options') + 10);
63+
} else {
64+
docText = tags.stripIndent`
65+
<!-- Links in /docs/documentation should NOT have \`.md\` at the end, because they end up in our wiki at release. -->
66+
67+
# ng ${command.name}
68+
69+
## Overview
70+
${command.description}
71+
72+
## Options
73+
`;
74+
}
75+
76+
const finalText = docText + '\n' + (optionText ? optionText : 'None.') + '\n';
77+
fs.writeFileSync(docFile, finalText);
78+
}
79+
}

tools/publish/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ switch (command) {
4343
case 'build-schema': commandFn = require('./build-schema').default; break;
4444
case 'update-version': commandFn = require('./update-version').default; break;
4545
case 'changelog': commandFn = require('./changelog').default; break;
46+
case 'docs': commandFn = require('./generate-docs').default; break;
4647
}
4748

4849
if (commandFn) {

0 commit comments

Comments
 (0)