1
1
import * as fs from 'fs' ;
2
2
import * as path from 'path' ;
3
- import { logging , tags } from '@angular-devkit/core' ;
3
+ import { logging , strings , tags } from '@angular-devkit/core' ;
4
+ import {
5
+ getEngineHost ,
6
+ } from '../../../packages/@angular/cli/utilities/schematics' ;
4
7
5
8
export default async function ( ) {
6
9
const commandsPath = __dirname + '/../../../packages/@angular/cli/commands' ;
@@ -17,70 +20,117 @@ export default async function () {
17
20
continue ;
18
21
}
19
22
20
- try {
21
- await command . initialize ( { } ) ;
22
- } catch ( e ) {
23
- console . log ( `initialize failed [ ${ commandFile } ]: ` + e . toString ( ) ) ;
24
- }
23
+ generateDoc ( command , commandFile ) ;
24
+
25
+ if ( command . name === 'generate' ) {
26
+ const host = getEngineHost ( ) ;
27
+ const collection = host . createCollectionDescription ( '@schematics/angular' ) ;
25
28
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' ) ;
29
+ for ( const schematicName in collection . schematics ) {
30
+ const schematic = collection . schematics [ schematicName ] ;
31
+ if ( schematic . hidden || schematic . private ) {
32
+ continue ;
33
+ }
34
+ const generateCommand = new commandConstructor (
35
+ { project : { root : path . join ( __dirname , '../fake_root/' ) } } ,
36
+ new logging . NullLogger ( ) ,
37
+ ) ;
38
+ generateDoc (
39
+ generateCommand ,
40
+ commandFile ,
41
+ { _ : [ `${ collection . name } :${ schematicName } ` ] } ,
42
+ {
43
+ name : strings . dasherize ( schematicName ) ,
44
+ description : schematic . description ,
45
+ postfix : '-' + schematicName ,
46
+ } ,
47
+ ) ;
48
+ }
57
49
}
50
+ }
51
+ }
52
+
53
+ interface DocInfo {
54
+ name : string ;
55
+ description : string ;
56
+ postfix : string ;
57
+ }
58
+ async function generateDoc (
59
+ command : any ,
60
+ commandFile : string ,
61
+ options : any = { } ,
62
+ info ?: Partial < DocInfo > ,
63
+ ) {
64
+ const docInfo = {
65
+ name : command . name ,
66
+ description : command . description ,
67
+ postfix : '' ,
68
+ ...info ,
69
+ } ;
58
70
59
- const docFile = path . join (
60
- __dirname ,
61
- '../../../docs/documentation/' ,
62
- path . basename ( commandFile , '.ts' ) + '.md' ) ;
71
+ try {
72
+ await command . initialize ( options ) ;
73
+ } catch ( e ) {
74
+ console . log ( `initialize failed [${ commandFile } ]: ` + e ) ;
75
+ }
63
76
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. -->
77
+ let optionText ;
78
+ if ( ! command . options ) {
79
+ optionText = '' ;
80
+ } else {
81
+ optionText = ( command . options as any [ ] )
82
+ . filter ( option => ! option . hidden )
83
+ . map ( option => {
84
+ let defaultText = '' ;
85
+ if ( option . default ) {
86
+ defaultText = ` <em>default value: ${ option . default } </em>` ;
87
+ }
88
+ let aliasText = '' ;
89
+ if ( option . aliases && option . aliases . length > 0 ) {
90
+ aliasText = ( option . aliases as string [ ] )
91
+ . map ( alias => '<code>' + ( alias . length === 1 ? '-' : '--' ) + alias + '</code>' )
92
+ . join ( ',' ) ;
93
+ aliasText = ` (alias: ${ aliasText } )` ;
94
+ }
72
95
73
- # ng ${ command . name }
96
+ return tags . stripIndent `
97
+ <details>
98
+ <summary>${ option . name } </summary>
99
+ <p>
100
+ <code>--${ option . name } </code>${ aliasText } ${ defaultText }
101
+ </p>
102
+ <p>
103
+ ${ option . description }
104
+ </p>
105
+ </details>
106
+ ` ;
107
+ } ) . join ( '\n' ) ;
108
+ }
74
109
75
- ## Overview
76
- ${ command . description }
110
+ const docFile = path . join (
111
+ __dirname ,
112
+ '../../../docs/documentation/' ,
113
+ path . basename ( commandFile , '.ts' ) + docInfo . postfix + '.md' ) ;
77
114
78
- ## Options
79
- ` ;
80
- // tslint:enable:max-line-length
81
- }
115
+ let docText ;
116
+ if ( fs . existsSync ( docFile ) ) {
117
+ docText = fs . readFileSync ( docFile , 'utf8' ) ;
118
+ docText = docText . slice ( 0 , docText . indexOf ( '## Options' ) + 10 ) ;
119
+ } else {
120
+ // tslint:disable:max-line-length
121
+ docText = tags . stripIndent `
122
+ <!-- Links in /docs/documentation should NOT have \`.md\` at the end, because they end up in our wiki at release. -->
82
123
83
- const finalText = docText + '\n' + ( optionText ? optionText : 'None.' ) + '\n' ;
84
- fs . writeFileSync ( docFile , finalText ) ;
124
+ # ng ${ docInfo . name }
125
+
126
+ ## Overview
127
+ ${ docInfo . description }
128
+
129
+ ## Options
130
+ ` ;
131
+ // tslint:enable:max-line-length
85
132
}
133
+
134
+ const finalText = docText + '\n' + ( optionText ? optionText : 'None.' ) + '\n' ;
135
+ fs . writeFileSync ( docFile , finalText ) ;
86
136
}
0 commit comments