Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: doc generation #904

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 67 additions & 32 deletions src/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 = () => {
Expand Down