chore: class link generation in release notes
This commit is contained in:
parent
b2ded9fed1
commit
b44dc1cde4
|
|
@ -13,6 +13,9 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/** @typedef {'Types'|'ReleaseNotesMd'} OutputType */
|
||||
|
||||
// @ts-check
|
||||
const toKebabCase = require('lodash/kebabCase.js')
|
||||
|
||||
|
|
@ -27,19 +30,34 @@ const createMarkdownLink = (languagePath, member, text) => {
|
|||
return `[${text}](https://playwright.dev${languagePath}/docs/api/class-${member.clazz.name.toLowerCase()}#${hash})`;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} languagePath
|
||||
* @param {import('../doclint/documentation').Class} clazz
|
||||
* @returns {string}
|
||||
*/
|
||||
const createClassMarkdownLink = (languagePath, clazz) => {
|
||||
return `[${clazz.name}](https://playwright.dev${languagePath}/docs/api/class-${clazz.name.toLowerCase()})`;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} language
|
||||
* @param {OutputType} outputType
|
||||
* @returns {import('../doclint/documentation').Renderer}
|
||||
*/
|
||||
function docsLinkRendererForLanguage(language) {
|
||||
function docsLinkRendererForLanguage(language, outputType) {
|
||||
const languagePath = languageToRelativeDocsPath(language);
|
||||
return ({ clazz, member, param, option }) => {
|
||||
if (param)
|
||||
return `\`${param}\``;
|
||||
if (option)
|
||||
return `\`${option}\``;
|
||||
if (clazz)
|
||||
return `{@link ${clazz.name}}`;
|
||||
if (clazz) {
|
||||
if (outputType === 'Types')
|
||||
return `{@link ${clazz.name}}`;
|
||||
if (outputType === 'ReleaseNotesMd')
|
||||
return createClassMarkdownLink(languagePath, clazz);
|
||||
throw new Error(`Unexpected output type ${outputType}`);
|
||||
}
|
||||
if (!member || !member.clazz)
|
||||
throw new Error('Internal error');
|
||||
const className = member.clazz.varName === 'playwrightAssertions' ? '' : member.clazz.varName + '.';
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class TypesGenerator {
|
|||
* @returns {Promise<string>}
|
||||
*/
|
||||
async generateTypes(overridesFile) {
|
||||
this.documentation.setLinkRenderer(docsLinkRendererForLanguage('js'));
|
||||
this.documentation.setLinkRenderer(docsLinkRendererForLanguage('js', 'Types'));
|
||||
this.documentation.setCodeGroupsTransformer('js', tabs => tabs.filter(tab => tab.value === 'ts').map(tab => tab.spec));
|
||||
this.documentation.generateSourceCodeComments();
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ if (language === 'js') {
|
|||
.mergeWith(parseApi(path.join(documentationRoot, 'test-reporter-api')));
|
||||
}
|
||||
|
||||
documentation.setLinkRenderer(docsLinkRendererForLanguage(language));
|
||||
documentation.setLinkRenderer(docsLinkRendererForLanguage(language, 'ReleaseNotesMd'));
|
||||
const content = fs.readFileSync(path.join(documentationRoot, `release-notes-${language}.md`)).toString();
|
||||
let nodes = md.parse(content);
|
||||
documentation.renderLinksInNodes(nodes);
|
||||
|
|
|
|||
Loading…
Reference in a new issue