@@ -6,10 +6,12 @@ const execa = require('execa')
6
6
const fs = require ( 'fs-extra' )
7
7
const path = require ( 'path' )
8
8
const { premove : del } = require ( 'premove/sync' )
9
+ const merge = require ( 'merge-options' )
9
10
const {
10
11
hasTsconfig,
11
12
fromAegir,
12
- fromRoot
13
+ fromRoot,
14
+ readJson
13
15
} = require ( '../utils' )
14
16
const ghPages = require ( 'gh-pages' )
15
17
const { promisify } = require ( 'util' )
@@ -33,40 +35,73 @@ const publishPages = promisify(ghPages.publish)
33
35
* @param {Task } task
34
36
*/
35
37
const docs = async ( ctx , task ) => {
36
- /** @type {Options } */
37
- const opts = {
38
- forwardOptions : ctx [ '--' ] ? ctx [ '--' ] : [ ] ,
39
- entryPoint : ctx . entryPoint
40
- }
41
- if ( ! hasTsconfig ) {
38
+ let userTSConfig = readJson ( fromRoot ( 'tsconfig.json' ) )
39
+ const configPath = fromRoot ( 'tsconfig-docs.aegir.json' )
40
+
41
+ try {
42
+ if ( userTSConfig . extends ) {
43
+ const extendedConf = readJson ( require . resolve ( userTSConfig . extends ) )
44
+
45
+ userTSConfig = merge . apply ( { concatArrays : true } , [
46
+ extendedConf ,
47
+ userTSConfig
48
+ ] )
49
+
50
+ delete userTSConfig . extends
51
+ }
52
+
53
+ const config = {
54
+ ...userTSConfig
55
+ }
56
+
57
+ if ( config . compilerOptions ) {
58
+ // remove config options that cause tsdoc to fail
59
+ delete config . compilerOptions . emitDeclarationOnly
60
+ }
61
+
62
+ fs . writeJsonSync (
63
+ configPath ,
64
+ config
65
+ )
66
+
67
+ /** @type {Options } */
68
+ const opts = {
69
+ forwardOptions : ctx [ '--' ] ? ctx [ '--' ] : [ ] ,
70
+ entryPoint : ctx . entryPoint
71
+ }
72
+ if ( ! hasTsconfig ) {
42
73
// eslint-disable-next-line no-console
43
- console . error ( kleur . yellow ( 'Documentation requires typescript config.\nTry running `aegir ts --preset config > tsconfig.json`' ) )
44
- return
45
- }
46
- // run typedoc
47
- const proc = execa (
48
- 'typedoc' ,
49
- [
50
- fromRoot ( opts . entryPoint ) ,
51
- '--out' , 'docs' ,
52
- '--hideGenerator' ,
53
- '--includeVersion' ,
54
- '--gitRevision' , 'master' ,
55
- '--plugin' , fromAegir ( 'src/ts/typedoc-plugin.js' ) ,
56
- ...opts . forwardOptions
57
- ] ,
58
- {
59
- localDir : path . join ( __dirname , '..' ) ,
60
- preferLocal : true
74
+ console . error ( kleur . yellow ( 'Documentation requires typescript config.\nTry running `aegir ts --preset config > tsconfig.json`' ) )
75
+ return
61
76
}
62
- )
63
- proc . all ?. on ( 'data' , chunk => {
64
- task . output = chunk . toString ( ) . replace ( '\n' , '' )
65
- } )
66
- await proc
77
+ // run typedoc
78
+ const proc = execa (
79
+ 'typedoc' ,
80
+ [
81
+ fromRoot ( opts . entryPoint ) ,
82
+ '--tsconfig' , configPath ,
83
+ '--out' , 'docs' ,
84
+ '--hideGenerator' ,
85
+ '--includeVersion' ,
86
+ '--gitRevision' , 'master' ,
87
+ '--plugin' , fromAegir ( 'src/ts/typedoc-plugin.js' ) ,
88
+ ...opts . forwardOptions
89
+ ] ,
90
+ {
91
+ localDir : path . join ( __dirname , '..' ) ,
92
+ preferLocal : true
93
+ }
94
+ )
95
+ proc . all ?. on ( 'data' , chunk => {
96
+ task . output = chunk . toString ( ) . replace ( '\n' , '' )
97
+ } )
98
+ await proc
67
99
68
- // write .nojekyll file
69
- fs . writeFileSync ( 'docs/.nojekyll' , '' )
100
+ // write .nojekyll file
101
+ fs . writeFileSync ( 'docs/.nojekyll' , '' )
102
+ } finally {
103
+ fs . removeSync ( configPath )
104
+ }
70
105
}
71
106
72
107
const publishDocs = ( ) => {
0 commit comments