From cf8154c5802b15cb71f1b70275fc6ea6aa17a6b2 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 5 Nov 2021 11:47:09 +0000 Subject: [PATCH] fix: doc generation 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 --- src/docs/index.js | 99 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 32 deletions(-) diff --git a/src/docs/index.js b/src/docs/index.js index 5ec99d2db..28b2f8678 100644 --- a/src/docs/index.js +++ b/src/docs/index.js @@ -6,10 +6,12 @@ const execa = require('execa') const fs = require('fs-extra') const path = require('path') const { premove: del } = require('premove/sync') +const merge = require('merge-options') const { hasTsconfig, fromAegir, - fromRoot + fromRoot, + readJson } = require('../utils') const ghPages = require('gh-pages') const { promisify } = require('util') @@ -33,40 +35,73 @@ const publishPages = promisify(ghPages.publish) * @param {Task} task */ const docs = async (ctx, task) => { - /** @type {Options} */ - const opts = { - forwardOptions: ctx['--'] ? ctx['--'] : [], - entryPoint: ctx.entryPoint - } - if (!hasTsconfig) { + let userTSConfig = readJson(fromRoot('tsconfig.json')) + const configPath = fromRoot('tsconfig-docs.aegir.json') + + try { + if (userTSConfig.extends) { + const extendedConf = readJson(require.resolve(userTSConfig.extends)) + + userTSConfig = merge.apply({ concatArrays: true }, [ + extendedConf, + userTSConfig + ]) + + delete userTSConfig.extends + } + + const config = { + ...userTSConfig + } + + if (config.compilerOptions) { + // remove config options that cause tsdoc to fail + delete config.compilerOptions.emitDeclarationOnly + } + + fs.writeJsonSync( + configPath, + config + ) + + /** @type {Options} */ + const opts = { + forwardOptions: ctx['--'] ? ctx['--'] : [], + entryPoint: ctx.entryPoint + } + if (!hasTsconfig) { // eslint-disable-next-line no-console - console.error(kleur.yellow('Documentation requires typescript config.\nTry running `aegir ts --preset config > tsconfig.json`')) - return - } - // run typedoc - const proc = execa( - 'typedoc', - [ - fromRoot(opts.entryPoint), - '--out', 'docs', - '--hideGenerator', - '--includeVersion', - '--gitRevision', 'master', - '--plugin', fromAegir('src/ts/typedoc-plugin.js'), - ...opts.forwardOptions - ], - { - localDir: path.join(__dirname, '..'), - preferLocal: true + console.error(kleur.yellow('Documentation requires typescript config.\nTry running `aegir ts --preset config > tsconfig.json`')) + return } - ) - proc.all?.on('data', chunk => { - task.output = chunk.toString().replace('\n', '') - }) - await proc + // run typedoc + const proc = execa( + 'typedoc', + [ + fromRoot(opts.entryPoint), + '--tsconfig', configPath, + '--out', 'docs', + '--hideGenerator', + '--includeVersion', + '--gitRevision', 'master', + '--plugin', fromAegir('src/ts/typedoc-plugin.js'), + ...opts.forwardOptions + ], + { + localDir: path.join(__dirname, '..'), + preferLocal: true + } + ) + proc.all?.on('data', chunk => { + task.output = chunk.toString().replace('\n', '') + }) + await proc - // write .nojekyll file - fs.writeFileSync('docs/.nojekyll', '') + // write .nojekyll file + fs.writeFileSync('docs/.nojekyll', '') + } finally { + fs.removeSync(configPath) + } } const publishDocs = () => {