3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-21 07:32:58 +01:00

Copy the README tagline to the npm description at publish; name Jira and Confluence in it

This commit is contained in:
2026-11-08 10:52:48 +01:00
committed by Lillem4n
parent db243b6d73
commit c3f10b5175
7 changed files with 65 additions and 3 deletions
+12
View File
@@ -0,0 +1,12 @@
const markup = /[`[\]*_<>]/
// The README's first paragraph after the title and the badges.
export function readmeTagline(readme) {
const lines = readme.split('\n').filter((line) => !line.startsWith('# ') && !line.startsWith('[!['))
const start = lines.findIndex((line) => line.trim() !== '')
if (start === -1 || lines[start].startsWith('#')) return { error: 'README.md has no tagline paragraph before its first section', ok: false }
const end = lines.findIndex((line, index) => index > start && line.trim() === '')
const tagline = lines.slice(start, end === -1 ? undefined : end).map((line) => line.trim()).join(' ')
if (markup.test(tagline)) return { error: `the README tagline is plain text, since npm shows it as is: ${tagline}`, ok: false }
return { ok: true, value: tagline }
}
+31
View File
@@ -0,0 +1,31 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { test } from 'node:test'
import { readmeTagline } from './tagline.mjs'
const title = '# @larvit/pkg — a title\n\n[![npm](https://img.example/npm.svg)](https://example.com)\n[![CI](https://img.example/ci.svg)](https://example.com)\n\n'
test('is the first paragraph after the title and the badges', () => {
assert.deepEqual(readmeTagline(`${title}Convert A to B.\n\nFor people who need it.\n\n## Install\n`), { ok: true, value: 'Convert A to B.' })
})
test('joins a paragraph wrapped over lines with single spaces', () => {
assert.deepEqual(readmeTagline(`${title}Convert A to B,\nand back.\n\nMore.\n`), { ok: true, value: 'Convert A to B, and back.' })
})
test('refuses a README with no paragraph before its first section', () => {
assert.equal(readmeTagline(`${title}## Install\n`).ok, false)
})
test('refuses markup, which npm would show as raw characters', () => {
for (const markup of ['`code`', '[link](https://example.com)', '**bold**', '_em_', '<b>x</b>']) {
assert.equal(readmeTagline(`${title}Convert ${markup}.\n`).ok, false, markup)
}
})
test('reads the real README', () => {
const tagline = readmeTagline(readFileSync(new URL('../README.md', import.meta.url), 'utf8'))
assert.ok(tagline.ok, tagline.error)
assert.ok(tagline.value.includes('Jira'))
})
+12
View File
@@ -0,0 +1,12 @@
import { readFileSync, writeFileSync } from 'node:fs'
import { readmeTagline } from './tagline.mjs'
const packagePath = new URL('../package.json', import.meta.url)
const tagline = readmeTagline(readFileSync(new URL('../README.md', import.meta.url), 'utf8'))
if (!tagline.ok) {
console.error(tagline.error)
process.exit(1)
}
const manifest = JSON.parse(readFileSync(packagePath, 'utf8'))
writeFileSync(packagePath, `${JSON.stringify({ ...manifest, description: tagline.value }, null, 2)}\n`)