Skip to content

Commit f15af9f

Browse files
clydinfilipesilva
authored andcommitted
build: basic command wiki documentation tool
1 parent 24dc9b0 commit f15af9f

File tree

8 files changed

+6651
-300
lines changed

8 files changed

+6651
-300
lines changed

package-lock.json

Lines changed: 6420 additions & 296 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 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",
@@ -57,6 +58,7 @@
5758
},
5859
"devDependencies": {
5960
"@ngtools/json-schema": "^1.1.0",
61+
"@angular-devkit/build-angular": "github:angular/angular-devkit-build-angular-builds",
6062
"@types/common-tags": "^1.2.4",
6163
"@types/express": "^4.0.32",
6264
"@types/fs-extra": "^4.0.0",

packages/@angular/cli/models/architect-command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export abstract class ArchitectCommand<T = any> extends Command<T> {
221221
private _loadWorkspaceAndArchitect() {
222222
const workspaceLoader = new WorkspaceLoader(this._host);
223223

224-
return workspaceLoader.loadWorkspace().pipe(
224+
return workspaceLoader.loadWorkspace(this.project.root).pipe(
225225
tap((workspace: experimental.workspace.Workspace) => this._workspace = workspace),
226226
concatMap((workspace: experimental.workspace.Workspace) => {
227227
return new Architect(workspace).loadArchitect();

packages/@angular/cli/models/schematic-command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export abstract class SchematicCommand extends Command {
314314
const workspaceLoader = new WorkspaceLoader(this._host);
315315

316316
try {
317-
workspaceLoader.loadWorkspace().pipe(take(1))
317+
workspaceLoader.loadWorkspace(this.project.root).pipe(take(1))
318318
.subscribe(
319319
(workspace: experimental.workspace.Workspace) => this._workspace = workspace,
320320
(err: Error) => {

packages/@angular/cli/models/workspace-loader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export class WorkspaceLoader {
3030
);
3131
}
3232

33-
loadWorkspace(): Observable<experimental.workspace.Workspace | null> {
34-
return this._getProjectWorkspaceFilePath().pipe(
33+
loadWorkspace(projectPath?: string): Observable<experimental.workspace.Workspace | null> {
34+
return this._getProjectWorkspaceFilePath(projectPath).pipe(
3535
concatMap(globalWorkspacePath => this._loadWorkspaceFromPath(globalWorkspacePath))
3636
);
3737
}

tools/publish/fake_root/angular.json

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"docs6": {
7+
"root": "",
8+
"sourceRoot": "/src",
9+
"projectType": "application",
10+
"prefix": "app",
11+
"schematics": {},
12+
"architect": {
13+
"build": {
14+
"builder": "@angular-devkit/build-angular:browser",
15+
"options": {
16+
"outputPath": "dist/docs6",
17+
"index": "src/index.html",
18+
"main": "src/main.ts",
19+
"polyfills": "src/polyfills.ts",
20+
"tsConfig": "src/tsconfig.app.json",
21+
"assets": [
22+
{
23+
"glob": "favicon.ico",
24+
"input": "src",
25+
"output": "/"
26+
},
27+
{
28+
"glob": "**/*",
29+
"input": "src/assets",
30+
"output": "/assets"
31+
}
32+
],
33+
"styles": [
34+
"src/styles.css"
35+
],
36+
"scripts": []
37+
},
38+
"configurations": {
39+
"production": {
40+
"fileReplacements": [
41+
{
42+
"replace": "src/environments/environment.ts",
43+
"with": "src/environments/environment.prod.ts"
44+
}
45+
],
46+
"optimization": true,
47+
"outputHashing": "all",
48+
"sourceMap": false,
49+
"extractCss": true,
50+
"namedChunks": false,
51+
"aot": true,
52+
"extractLicenses": true,
53+
"vendorChunk": false,
54+
"buildOptimizer": true
55+
}
56+
}
57+
},
58+
"serve": {
59+
"builder": "@angular-devkit/build-angular:dev-server",
60+
"options": {
61+
"browserTarget": "docs6:build"
62+
},
63+
"configurations": {
64+
"production": {
65+
"browserTarget": "docs6:build:production"
66+
}
67+
}
68+
},
69+
"extract-i18n": {
70+
"builder": "@angular-devkit/build-angular:extract-i18n",
71+
"options": {
72+
"browserTarget": "docs6:build"
73+
}
74+
},
75+
"test": {
76+
"builder": "@angular-devkit/build-angular:karma",
77+
"options": {
78+
"main": "src/test.ts",
79+
"polyfills": "src/polyfills.ts",
80+
"tsConfig": "src/tsconfig.spec.json",
81+
"karmaConfig": "src/karma.conf.js",
82+
"styles": [
83+
"styles.css"
84+
],
85+
"scripts": [],
86+
"assets": [
87+
{
88+
"glob": "favicon.ico",
89+
"input": "src/",
90+
"output": "/"
91+
},
92+
{
93+
"glob": "**/*",
94+
"input": "src/assets",
95+
"output": "/assets"
96+
}
97+
]
98+
}
99+
},
100+
"lint": {
101+
"builder": "@angular-devkit/build-angular:tslint",
102+
"options": {
103+
"tsConfig": [
104+
"src/tsconfig.app.json",
105+
"src/tsconfig.spec.json"
106+
],
107+
"exclude": [
108+
"**/node_modules/**"
109+
]
110+
}
111+
}
112+
}
113+
},
114+
"docs6-e2e": {
115+
"root": "e2e/",
116+
"projectType": "application",
117+
"architect": {
118+
"e2e": {
119+
"builder": "@angular-devkit/build-angular:protractor",
120+
"options": {
121+
"protractorConfig": "e2e/protractor.conf.js",
122+
"devServerTarget": "docs6:serve"
123+
}
124+
},
125+
"lint": {
126+
"builder": "@angular-devkit/build-angular:tslint",
127+
"options": {
128+
"tsConfig": "e2e/tsconfig.e2e.json",
129+
"exclude": [
130+
"**/node_modules/**"
131+
]
132+
}
133+
}
134+
}
135+
}
136+
},
137+
"defaultProject": "docs6"
138+
}

tools/publish/src/generate-docs.ts

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

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)