2021-10-06 12:49:04 +02:00
|
|
|
/**
|
|
|
|
* This script generates API documentation files in the target folder.
|
|
|
|
* Usage: `$ yarn build:api-docs <path>` creates the .md files in <path>.
|
|
|
|
* Example: `$ yarn build:api-docs path/to/theatre-docs/docs/api/`
|
|
|
|
*
|
|
|
|
* Usually <path> is https://github.com/AriaMinaei/theatre-docs/tree/main/docs/api
|
|
|
|
*/
|
2021-10-02 13:48:02 +02:00
|
|
|
import path from 'path'
|
2021-10-04 10:39:12 +02:00
|
|
|
import {parse as parseJsonC} from 'jsonc-parser'
|
2021-10-02 13:48:02 +02:00
|
|
|
;(async function () {
|
|
|
|
// better quote function from https://github.com/google/zx/pull/167
|
|
|
|
$.quote = function quote(arg) {
|
|
|
|
if (/^[a-z0-9/_.-]+$/i.test(arg)) {
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
`$'` +
|
|
|
|
arg
|
|
|
|
.replace(/\\/g, '\\\\')
|
|
|
|
.replace(/'/g, "\\'")
|
|
|
|
.replace(/\f/g, '\\f')
|
|
|
|
.replace(/\n/g, '\\n')
|
|
|
|
.replace(/\r/g, '\\r')
|
|
|
|
.replace(/\t/g, '\\t')
|
|
|
|
.replace(/\v/g, '\\v')
|
|
|
|
.replace(/\0/g, '\\0') +
|
|
|
|
`'`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-10-04 10:39:12 +02:00
|
|
|
const outputPathArg = argv._[argv._.length - 1]
|
|
|
|
if (outputPathArg.trim().length === 0) {
|
|
|
|
console.error(
|
|
|
|
`You must provide a path to create the markdown files in. Eg. $ yarn build:api-docs /path/to/docs-site/docs/api`,
|
|
|
|
)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
const outputPath = path.resolve(outputPathArg)
|
|
|
|
|
|
|
|
const pathToApiJsonFiles = path.dirname(
|
|
|
|
path.resolve(
|
|
|
|
'./devEnv',
|
|
|
|
parseJsonC(
|
|
|
|
fs.readFileSync('./devEnv/api-extractor-base.json', {
|
|
|
|
encoding: 'utf-8',
|
|
|
|
}),
|
|
|
|
).docModel.apiJsonFilePath,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2021-10-02 13:48:02 +02:00
|
|
|
await $`yarn build:ts`
|
|
|
|
await Promise.all(
|
|
|
|
['@theatre/dataverse', '@theatre/react', 'theatre'].map(
|
|
|
|
(pkg) => $`yarn workspace ${pkg} run build:api-json`,
|
|
|
|
),
|
|
|
|
)
|
2022-01-19 13:06:13 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
We replace the Pointer name with a similar-looking one so that that shitty
|
|
|
|
api-documenter generates two different pages for Pointer and pointer, instead
|
|
|
|
of overwriting one with the other.
|
|
|
|
|
|
|
|
Apparently any non-english character, including this one will break links,
|
|
|
|
probably due to some overzealous regex. Didn't find any replacement that doesn't
|
|
|
|
change the look of the name AND doesn't break links, however the below code does
|
|
|
|
replace links too, in case we find something in the future. For now, we shouldn't
|
|
|
|
@link to the Pointer type in TSDoc comments.
|
|
|
|
*/
|
|
|
|
const replacement = 'Pointer\u200E'
|
|
|
|
|
|
|
|
fs.writeFileSync('./.temp/api/dataverse.api.json', fs.readFileSync('./.temp/api/dataverse.api.json', {
|
|
|
|
encoding: 'utf-8',
|
|
|
|
}).replaceAll('"name": "Pointer"', `"name": "${replacement}"`).replaceAll('{@link Pointer}', `{@link ${replacement}}`))
|
|
|
|
|
2021-10-04 10:39:12 +02:00
|
|
|
await $`api-documenter markdown --input-folder ${pathToApiJsonFiles} --output-folder ${outputPath}`
|
2021-10-02 13:48:02 +02:00
|
|
|
})()
|