Skip to content

Commit 492b06f

Browse files
authoredNov 5, 2021
fix: doc generation (#904)
There's a conflict between the `noEmit` and `emitDeclarationOnly` config directives that causes typedoc to bail. Read the users' config and remove the conflict before generating docs. Fixes #881
1 parent 1bc8bd5 commit 492b06f

File tree

1 file changed

+67
-32
lines changed

1 file changed

+67
-32
lines changed
 

‎src/docs/index.js

+67-32
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ const execa = require('execa')
66
const fs = require('fs-extra')
77
const path = require('path')
88
const { premove: del } = require('premove/sync')
9+
const merge = require('merge-options')
910
const {
1011
hasTsconfig,
1112
fromAegir,
12-
fromRoot
13+
fromRoot,
14+
readJson
1315
} = require('../utils')
1416
const ghPages = require('gh-pages')
1517
const { promisify } = require('util')
@@ -33,40 +35,73 @@ const publishPages = promisify(ghPages.publish)
3335
* @param {Task} task
3436
*/
3537
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) {
4273
// 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
6176
}
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
6799

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+
}
70105
}
71106

72107
const publishDocs = () => {

0 commit comments

Comments
 (0)
Please sign in to comment.