chore: class link generation in release notes (#30324)
This commit is contained in:
parent
15b423106f
commit
01d4293803
|
@ -13,10 +13,14 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @typedef {'Types'|'ReleaseNotesMd'} OutputType */
|
||||||
|
|
||||||
// @ts-check
|
// @ts-check
|
||||||
const toKebabCase = require('lodash/kebabCase.js')
|
const toKebabCase = require('lodash/kebabCase.js')
|
||||||
|
const Documentation = require('./documentation');
|
||||||
|
|
||||||
const createMarkdownLink = (languagePath, member, text) => {
|
function createMarkdownLink(languagePath, member, text) {
|
||||||
const className = toKebabCase(member.clazz.name);
|
const className = toKebabCase(member.clazz.name);
|
||||||
const memberName = toKebabCase(member.name);
|
const memberName = toKebabCase(member.name);
|
||||||
let hash = null;
|
let hash = null;
|
||||||
|
@ -28,18 +32,33 @@ const createMarkdownLink = (languagePath, member, text) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} language
|
* @param {string} languagePath
|
||||||
* @returns {import('../doclint/documentation').Renderer}
|
* @param {Documentation.Class} clazz
|
||||||
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function docsLinkRendererForLanguage(language) {
|
function createClassMarkdownLink(languagePath, clazz) {
|
||||||
|
return `[${clazz.name}](https://playwright.dev${languagePath}/docs/api/class-${clazz.name.toLowerCase()})`;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} language
|
||||||
|
* @param {OutputType} outputType
|
||||||
|
* @returns {Documentation.Renderer}
|
||||||
|
*/
|
||||||
|
function docsLinkRendererForLanguage(language, outputType) {
|
||||||
const languagePath = languageToRelativeDocsPath(language);
|
const languagePath = languageToRelativeDocsPath(language);
|
||||||
return ({ clazz, member, param, option }) => {
|
return ({ clazz, member, param, option }) => {
|
||||||
if (param)
|
if (param)
|
||||||
return `\`${param}\``;
|
return `\`${param}\``;
|
||||||
if (option)
|
if (option)
|
||||||
return `\`${option}\``;
|
return `\`${option}\``;
|
||||||
if (clazz)
|
if (clazz) {
|
||||||
return `{@link ${clazz.name}}`;
|
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)
|
if (!member || !member.clazz)
|
||||||
throw new Error('Internal error');
|
throw new Error('Internal error');
|
||||||
const className = member.clazz.varName === 'playwrightAssertions' ? '' : member.clazz.varName + '.';
|
const className = member.clazz.varName === 'playwrightAssertions' ? '' : member.clazz.varName + '.';
|
||||||
|
@ -92,7 +111,7 @@ function assertionArgument(className) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import('../doclint/documentation').Member[]} args
|
* @param {Documentation.Member[]} args
|
||||||
*/
|
*/
|
||||||
function renderJSSignature(args) {
|
function renderJSSignature(args) {
|
||||||
const tokens = [];
|
const tokens = [];
|
||||||
|
|
|
@ -81,7 +81,7 @@ class TypesGenerator {
|
||||||
* @returns {Promise<string>}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
async generateTypes(overridesFile) {
|
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.setCodeGroupsTransformer('js', tabs => tabs.filter(tab => tab.value === 'ts').map(tab => tab.spec));
|
||||||
this.documentation.generateSourceCodeComments();
|
this.documentation.generateSourceCodeComments();
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ if (language === 'js') {
|
||||||
.mergeWith(parseApi(path.join(documentationRoot, 'test-reporter-api')));
|
.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();
|
const content = fs.readFileSync(path.join(documentationRoot, `release-notes-${language}.md`)).toString();
|
||||||
let nodes = md.parse(content);
|
let nodes = md.parse(content);
|
||||||
documentation.renderLinksInNodes(nodes);
|
documentation.renderLinksInNodes(nodes);
|
||||||
|
|
Loading…
Reference in New Issue