From a8522a9a544a03b10696617a4700765eaebad784 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Mon, 12 Feb 2024 12:15:16 +0100 Subject: [PATCH] fix: add note to readmes about editing index.ts instead (#1465) To prevent people opening PRs that update READMEs when they will be generated, add a comment to the README pointing people in the right direction. --- src/check-project/check-monorepo-readme.js | 5 +++++ src/check-project/check-readme.js | 5 +++++ src/check-project/index.js | 9 ++++++++- src/check-project/manifests/monorepo.js | 14 +++++++++++--- src/check-project/readme/header.js | 2 ++ src/docs/readme-updater-plugin.js | 15 +++++++++++++++ 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/check-project/check-monorepo-readme.js b/src/check-project/check-monorepo-readme.js index 66f09db19..05ced0f74 100644 --- a/src/check-project/check-monorepo-readme.js +++ b/src/check-project/check-monorepo-readme.js @@ -70,6 +70,11 @@ export async function checkMonorepoReadme (projectDir, repoUrl, defaultBranch, p file.children.forEach((child) => { const rendered = writeMarkdown(child).toLowerCase() + if (child.type === 'heading' && rendered.includes(pkg.name)) { + // skip heading + return + } + if (skipBlockHeader > -1 && child.type === 'heading' && child.depth <= skipBlockHeader) { skipBlockHeader = -1 inAboutBlock = false diff --git a/src/check-project/check-readme.js b/src/check-project/check-readme.js index aa159ae0f..e9aa4c531 100644 --- a/src/check-project/check-readme.js +++ b/src/check-project/check-readme.js @@ -74,6 +74,11 @@ export async function checkReadme (projectDir, repoUrl, defaultBranch, ciFile, r file.children.forEach((child) => { const rendered = writeMarkdown(child).toLowerCase() + if (child.type === 'heading' && rendered.includes(pkg.name)) { + // skip heading + return + } + if (skipBlockHeader > -1 && child.type === 'heading' && child.depth <= skipBlockHeader) { skipBlockHeader = -1 inAboutBlock = false diff --git a/src/check-project/index.js b/src/check-project/index.js index 989802925..b7eecc885 100755 --- a/src/check-project/index.js +++ b/src/check-project/index.js @@ -145,7 +145,7 @@ async function processMonorepo (projectDir, manifest, branchName, repoUrl, ciFil await alignMonorepoProjectDependencies(projectDirs) await configureMonorepoProjectReferences(projectDirs) - let proposedManifest = await monorepoManifest(manifest, repoUrl) + let proposedManifest = await monorepoManifest(manifest, repoUrl, repoUrl, branchName) proposedManifest = sortManifest(proposedManifest) await ensureFileHasContents(projectDir, 'package.json', JSON.stringify(proposedManifest, null, 2)) @@ -378,6 +378,7 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag // 5. CJS, no types let untypedCJS = cjs && hasMain + /** @type any */ let proposedManifest = {} if (!typescript && !typedESM && !typedCJS && !untypedCJS) { @@ -429,6 +430,12 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag throw new Error('Cannot determine project type') } + // remove release config from monorepo projects as multi-semantic-release + // wants it defined in the root manifest + if (rootManifest != null) { + proposedManifest.release = undefined + } + proposedManifest = sortManifest(proposedManifest) await ensureFileHasContents(projectDir, 'package.json', JSON.stringify(proposedManifest, null, 2)) diff --git a/src/check-project/manifests/monorepo.js b/src/check-project/manifests/monorepo.js index 8bf8ccc87..8cebd6d0f 100644 --- a/src/check-project/manifests/monorepo.js +++ b/src/check-project/manifests/monorepo.js @@ -1,3 +1,4 @@ +import { semanticReleaseConfig } from '../semantic-release-config.js' import { sortFields, constructManifest @@ -6,11 +7,18 @@ import { /** * @param {any} manifest * @param {string} repoUrl - * @param {string} [homePage] + * @param {string} homePage + * @param {string} branchName */ -export async function monorepoManifest (manifest, repoUrl, homePage = repoUrl) { +export async function monorepoManifest (manifest, repoUrl, homePage, branchName) { let proposedManifest = constructManifest(manifest, { - private: true + private: true, + release: ( + Object.values(manifest.scripts ?? {}) + .some(script => script.includes('semantic-release') || script.includes('aegir release')) + ) + ? semanticReleaseConfig(branchName) + : undefined }, repoUrl, homePage) const rest = { diff --git a/src/check-project/readme/header.js b/src/check-project/readme/header.js index 6b314f54c..d92bcff0d 100644 --- a/src/check-project/readme/header.js +++ b/src/check-project/readme/header.js @@ -34,6 +34,8 @@ const BADGES = { */ export const HEADER = (pkg, repoOwner, repoName, defaultBranch, ciFile) => { return ` +# ${pkg.name} + ${(BADGES[repoOwner] ?? BADGES.default)(repoOwner, repoName, defaultBranch, ciFile).trim()} > ${pkg.description} diff --git a/src/docs/readme-updater-plugin.js b/src/docs/readme-updater-plugin.js index 5ec04ddd0..4f5f16032 100644 --- a/src/docs/readme-updater-plugin.js +++ b/src/docs/readme-updater-plugin.js @@ -108,6 +108,21 @@ function updateModule (comment, manifestPath, readmePath, app) { const about = ` # About + + ${ comment.summary .map(item => item.text)