From a0da5b1373f68443f994d2ae824b1f0ef40c42ea Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Sat, 30 Sep 2023 11:45:47 +0200 Subject: [PATCH] Add more constraints for README.md and pull_request_template.md --- README.md | 4 ++-- yarn.config.cjs | 63 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 80dc81d..2f83094 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,11 @@ Follow these instructions when using this template. ## Installation -`yarn add @metamask/this-module` +`yarn add @metamask/metamask-module-template` or -`npm install @metamask/this-module` +`npm install @metamask/metamask-module-template` ## Usage diff --git a/yarn.config.cjs b/yarn.config.cjs index 7e41bb6..e349d9f 100644 --- a/yarn.config.cjs +++ b/yarn.config.cjs @@ -123,15 +123,29 @@ function expectWorkspaceDependencies(workspace) { * * @param {Workspace} workspace - The workspace to check. * @param {string} workspaceName - The name of the workspace. + * @returns {Promise} */ async function expectReadme(workspace, workspaceName) { const readme = await getWorkspaceFile(workspace, 'README.md'); - if (workspaceName !== 'metamask-module-template') { - if (readme.includes('## Template Instructions')) { - workspace.error( - 'The README.md contains template instructions. These should be removed.', - ); - } + if ( + workspaceName !== 'metamask-module-template' && + readme.includes('## Template Instructions') + ) { + workspace.error( + 'The README.md contains template instructions. These instructions should be removed.', + ); + } + + if (!readme.includes(`yarn add @metamask/${workspaceName}`)) { + workspace.error( + `The README.md does not contain an example of how to install the package using Yarn (\`yarn add @metamask/${workspaceName}\`). Please add an example.`, + ); + } + + if (!readme.includes(`npm install @metamask/${workspaceName}`)) { + workspace.error( + `The README.md does not contain an example of how to install the package using npm (\`npm install @metamask/${workspaceName}\`). Please add an example.`, + ); } const nvmrc = await getWorkspaceFile(workspace, '.nvmrc'); @@ -145,6 +159,40 @@ async function expectReadme(workspace, workspaceName) { } } +/** + * Expect that the workspace has a pull_request_template.md file, and that it + * is a non-empty string. The pull_request_template.md is expected to: + * + * - Not contain an examples section (unless the workspace is the module + * template itself). + * + * @param {Workspace} workspace - The workspace to check. + * @param {string} workspaceName - The name of the workspace. + * @returns {Promise} + */ +async function expectPullRequestTemplate(workspace, workspaceName) { + if (workspaceName === 'metamask-module-template') { + return; + } + + const pullRequestTemplate = await getWorkspaceFile( + workspace, + '.github/PULL_REQUEST_TEMPLATE.md', + ); + + if (!pullRequestTemplate) { + workspace.error( + 'The pull_request_template.md is missing. This should be added.', + ); + } + + if (pullRequestTemplate.includes('## Examples')) { + workspace.error( + 'The pull_request_template.md contains an examples section. This section should be removed.', + ); + } +} + module.exports = defineConfig({ async constraints({ Yarn }) { const workspace = Yarn.workspace(); @@ -160,6 +208,9 @@ module.exports = defineConfig({ // The package must have a valid README.md file. await expectReadme(workspace, workspaceName); + // The package must have a valid pull request template. + await expectPullRequestTemplate(workspace, workspaceName); + expectWorkspaceDependencies(workspace); // The homepage of the package must match its name.