Skip to content

Commit

Permalink
fix: use absolute links in generated readme (#1508)
Browse files Browse the repository at this point in the history
To prevent broken links in api docs, use absolute links in generated
readme files.
  • Loading branch information
achingbrain authored Apr 25, 2024
1 parent dc5c226 commit 8974445
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/check-project/check-monorepo-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import {
/**
* @param {string} projectDir
* @param {string} repoUrl
* @param {string} webRoot
* @param {string} defaultBranch
* @param {string[]} projectDirs
* @param {string} ciFile
*/
export async function checkMonorepoReadme (projectDir, repoUrl, defaultBranch, projectDirs, ciFile) {
export async function checkMonorepoReadme (projectDir, repoUrl, webRoot, defaultBranch, projectDirs, ciFile) {
const repoParts = repoUrl.split('/')
const repoName = repoParts.pop()
const repoOwner = repoParts.pop()
Expand Down Expand Up @@ -146,7 +147,7 @@ export async function checkMonorepoReadme (projectDir, repoUrl, defaultBranch, p
other.push(child)
})

const license = parseMarkdown(LICENSE(pkg, repoOwner, repoName, defaultBranch))
const license = parseMarkdown(LICENSE(pkg, repoOwner, repoName, webRoot, defaultBranch))

/** @type {import('mdast').Root} */
let apiDocs = {
Expand Down
5 changes: 3 additions & 2 deletions src/check-project/check-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
/**
* @param {string} projectDir
* @param {string} repoUrl
* @param {string} webRoot
* @param {string} defaultBranch
* @param {string} ciFile
* @param {any} [rootManifest]
*/
export async function checkReadme (projectDir, repoUrl, defaultBranch, ciFile, rootManifest) {
export async function checkReadme (projectDir, repoUrl, webRoot, defaultBranch, ciFile, rootManifest) {
const repoParts = repoUrl.split('/')
const repoName = repoParts.pop()
const repoOwner = repoParts.pop()
Expand Down Expand Up @@ -162,7 +163,7 @@ export async function checkReadme (projectDir, repoUrl, defaultBranch, ciFile, r
apiDocs = parseMarkdown(APIDOCS(pkg, rootManifest))
}

const license = parseMarkdown(LICENSE(pkg, repoOwner, repoName, defaultBranch))
const license = parseMarkdown(LICENSE(pkg, repoOwner, repoName, webRoot, defaultBranch))

readme.children = [
...header,
Expand Down
17 changes: 11 additions & 6 deletions src/check-project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ async function processMonorepo (projectDir, manifest, branchName, repoUrl, ciFil
let proposedManifest = await monorepoManifest(manifest, repoUrl, repoUrl, branchName)
proposedManifest = sortManifest(proposedManifest)

const webRoot = `${repoUrl}/tree/${branchName}`

await ensureFileHasContents(projectDir, 'package.json', JSON.stringify(proposedManifest, null, 2))
await ensureFileHasContents(projectDir, '.gitignore', fs.readFileSync(path.join(__dirname, 'files', 'gitignore'), {
encoding: 'utf-8'
}))
await checkLicenseFiles(projectDir)
await checkBuildFiles(projectDir, branchName, repoUrl)
await checkMonorepoReadme(projectDir, repoUrl, branchName, projectDirs, ciFile)
await checkMonorepoReadme(projectDir, repoUrl, webRoot, branchName, projectDirs, ciFile)
await checkMonorepoFiles(projectDir)
}

Expand Down Expand Up @@ -386,17 +388,20 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag
const { projectType } = await prompt.get({
properties: {
projectType: {
description: 'Project type: typescript | typedESM | typedCJS | untypedESM | untypedCJS',
description: 'Project type: typescript | typedESM | typedCJS | untypedESM | untypedCJS | skip',
required: true,
conform: (value) => {
return ['typescript', 'typedESM', 'typedCJS', 'untypedESM', 'untypedCJS'].includes(value)
return ['typescript', 'typedESM', 'typedCJS', 'untypedESM', 'untypedCJS', 'skip'].includes(value)
},
default: 'typescript'
default: 'skip'
}
}
})

if (projectType === 'typescript') {
if (projectType === 'skip') {
console.info('Skipping', manifest.name)
return
} else if (projectType === 'typescript') {
typescript = true
} else if (projectType === 'typedESM') {
typedESM = true
Expand Down Expand Up @@ -447,7 +452,7 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag
}

await checkLicenseFiles(projectDir)
await checkReadme(projectDir, repoUrl, branchName, ciFile, rootManifest)
await checkReadme(projectDir, repoUrl, homePage, branchName, ciFile, rootManifest)
await checkTypedocFiles(projectDir, typescript)
}

Expand Down
19 changes: 10 additions & 9 deletions src/check-project/readme/license.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* @type {Record<string, (repoOwner: string, repoName: string, defaultBranch: string) => string>}
* @type {Record<string, (repoOwner: string, repoName: string, repoUrl: string, defaultBranch: string) => string>}
*/
const licenses = {
ipfs: (repoOwner, repoName, defaultBranch) => `
ipfs: (repoOwner, repoName, webRoot, defaultBranch) => `
# License
Licensed under either of
* Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
* MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT)
* Apache 2.0, ([LICENSE-APACHE](${webRoot.replace('/tree/', '/blob/')}/LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
* MIT ([LICENSE-MIT](${webRoot.replace('/tree/', '/blob/')}/LICENSE-MIT) / http://opensource.org/licenses/MIT)
# Contribute
Expand All @@ -22,13 +22,13 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
`,
default: (repoOwner, repoName, defaultBranch) => `
default: (repoOwner, repoName, webRoot, defaultBranch) => `
# License
Licensed under either of
* Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
* MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT)
* Apache 2.0, ([LICENSE-APACHE](${webRoot.replace('/tree/', '/blob/')}/LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
* MIT ([LICENSE-MIT](${webRoot.replace('/tree/', '/blob/')}/LICENSE-MIT) / http://opensource.org/licenses/MIT)
# Contribution
Expand All @@ -40,8 +40,9 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
* @param {*} pkg
* @param {string} repoOwner
* @param {string} repoName
* @param {string} webRoot
* @param {string} defaultBranch
*/
export const LICENSE = (pkg, repoOwner, repoName, defaultBranch) => {
return (licenses[repoOwner] ?? licenses.default)(repoOwner, repoName, defaultBranch)
export const LICENSE = (pkg, repoOwner, repoName, webRoot, defaultBranch) => {
return (licenses[repoOwner] ?? licenses.default)(repoOwner, repoName, webRoot, defaultBranch)
}

0 comments on commit 8974445

Please sign in to comment.