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

chore: class link generation in release notes #30324

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
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
31 changes: 25 additions & 6 deletions utils/doclint/linkUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
* 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')
const Documentation = require('./documentation');

const createMarkdownLink = (languagePath, member, text) => {
function createMarkdownLink(languagePath, member, text) {
const className = toKebabCase(member.clazz.name);
const memberName = toKebabCase(member.name);
let hash = null;
Expand All @@ -27,19 +31,34 @@ const createMarkdownLink = (languagePath, member, text) => {
return `[${text}](https://playwright.dev${languagePath}/docs/api/class-${member.clazz.name.toLowerCase()}#${hash})`;
};

/**
* @param {string} languagePath
* @param {Documentation.Class} clazz
* @returns {string}
*/
function createClassMarkdownLink(languagePath, clazz) {
return `[${clazz.name}](https://playwright.dev${languagePath}/docs/api/class-${clazz.name.toLowerCase()})`;
};

/**
* @param {string} language
* @returns {import('../doclint/documentation').Renderer}
* @param {OutputType} outputType
* @returns {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 + '.';
Expand Down Expand Up @@ -92,7 +111,7 @@ function assertionArgument(className) {
}

/**
* @param {import('../doclint/documentation').Member[]} args
* @param {Documentation.Member[]} args
*/
function renderJSSignature(args) {
const tokens = [];
Expand Down
2 changes: 1 addition & 1 deletion utils/generate_types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion utils/render_release_notes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading