Skip to content

Commit

Permalink
chore(docs): remove old generated placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Aug 16, 2022
1 parent 08550f1 commit c38f101
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 531 deletions.
36 changes: 0 additions & 36 deletions docs/lib/tags.js

This file was deleted.

60 changes: 16 additions & 44 deletions docs/lib/transform.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const marked = require('marked-man')
const { join } = require('path')
const TAGS = require('./tags')
const NPM = require('./npm.js')
const transformHTML = require('./transform-html.js')

const TAGS = {
CONFIG: '<!-- AUTOGENERATED CONFIG DESCRIPTIONS -->',
USAGE: '<!-- AUTOGENERATED USAGE DESCRIPTIONS -->',
SHORTHANDS: '<!-- AUTOGENERATED CONFIG SHORTHANDS -->',
}

const assertPlaceholder = (src, path, type) => {
const placeholder = TAGS[type].REPLACE
const placeholder = TAGS[type]
if (!src.includes(placeholder)) {
throw new Error(
`Cannot replace ${type} in ${path} due to missing placeholder`
Expand All @@ -20,15 +25,9 @@ const removePlaceholders = (src) => src.replace(/^<!--.*-->$/gm, '')

const replaceUsage = (src, { path, docExt }) => {
const replacer = assertPlaceholder(src, path, 'USAGE')
const { usage, name, srcName } = NPM.getCommandByDoc(path, docExt)
const { usage, name } = NPM.getCommandByDoc(path, docExt)

const synopsis = [
TAGS.USAGE.START,
TAGS.USAGE.SEP(srcName),
'',
'```bash',
usage,
]
const synopsis = ['```bash', usage]

const cmdAliases = Object.keys(NPM.aliases).reduce((p, c) => {
if (NPM.aliases[c] === name) {
Expand All @@ -45,7 +44,7 @@ const replaceUsage = (src, { path, docExt }) => {
synopsis.push(`aliases: ${cmdAliases.join(', ')}`)
}

synopsis.push('```', '', TAGS.USAGE.SEP(srcName), '', TAGS.USAGE.END)
synopsis.push('```')

return src.replace(replacer, synopsis.join('\n'))
}
Expand All @@ -58,38 +57,18 @@ const replaceParams = (src, { path, docExt }) => {
return src
}

const config = [
TAGS.CONFIG.START,
TAGS.CONFIG.SEP(),
NPM.describeParams(params).join('\n\n' + TAGS.CONFIG.SEP() + '\n\n'),
'',
TAGS.CONFIG.SEP(),
'',
TAGS.CONFIG.END,
].join('\n')

return src.replace(replacer, config)
return src.replace(replacer, NPM.describeParams(params).join('\n\n'))
}

const replaceConfig = (src, { path }) => {
const replacer = assertPlaceholder(src, path, 'CONFIG')

const config = [
TAGS.CONFIG.START,
TAGS.CONFIG.SEP(),
NPM.describeAll(),
'',
TAGS.CONFIG.SEP(),
TAGS.CONFIG.END,
].join('\n')

return src.replace(replacer, config)
return src.replace(replacer, NPM.describeAll())
}

const replaceShorthands = (src, { path }) => {
const replacer = assertPlaceholder(src, path, 'SHORTHANDS')

const sh = Object.entries(NPM.shorthands)
const shorthands = Object.entries(NPM.shorthands)
.sort(([shorta, expansiona], [shortb, expansionb]) => {
// sort by what they're short FOR
return expansiona.join(' ').localeCompare(expansionb.join(' '), 'en') ||
Expand All @@ -98,16 +77,9 @@ const replaceShorthands = (src, { path }) => {
.map(([short, expansion]) => {
const dash = short.length === 1 ? '-' : '--'
return `* \`${dash}${short}\`: \`${expansion.join(' ')}\``
}).join('\n')

return src.replace(replacer, [
TAGS.SHORTHANDS.START,
TAGS.SHORTHANDS.SEP(),
sh,
'',
TAGS.SHORTHANDS.SEP(),
TAGS.SHORTHANDS.END,
].join('\n'))
})

return src.replace(replacer, shorthands.join('\n'))
}

const replaceHelpLinks = (src) => {
Expand Down
5 changes: 1 addition & 4 deletions lib/utils/config/describe-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ const describeAll = () => {
}
return Object.entries(definitions).sort(sort)
.map(([key, def]) => def.describe())
.join(
'\n\n<!-- automatically generated, do not edit manually -->\n' +
'<!-- see lib/utils/config/definitions.js -->\n\n'
)
.join('\n\n')
}
module.exports = describeAll
Loading

0 comments on commit c38f101

Please sign in to comment.