Skip to content

Commit

Permalink
Add more constraints for README.md and pull_request_template.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Sep 30, 2023
1 parent d59c486 commit a0da5b1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
63 changes: 57 additions & 6 deletions yarn.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,29 @@ function expectWorkspaceDependencies(workspace) {
*
* @param {Workspace} workspace - The workspace to check.
* @param {string} workspaceName - The name of the workspace.
* @returns {Promise<void>}
*/
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');
Expand All @@ -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<void>}
*/
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();
Expand All @@ -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.
Expand Down

0 comments on commit a0da5b1

Please sign in to comment.