Skip to content

Commit e1aaec7

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

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-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: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
}

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)