Skip to content

Commit

Permalink
T
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Dec 24, 2024
1 parent a5b0222 commit bd92510
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions prep/gen-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ async function main() {

const has = (a, b) => a.toLowerCase().indexOf(b.toLowerCase()) !== -1;

const replaceInTag = (src, tag, replacement) =>
src.replace(
const strip = s => s.replace(/^\s+|\s+$/g, '');

const replaceInTag = (s, tag, replacement) =>
s.replace(
makeTagRegex(tag),
(m0, m1, m2, m3) => m1 + '\n' + strip(replacement) + '\n' + m3
);

const getTag = (src, tag) => {
const m = src.match(makeTagRegex(tag));
const getTag = (s, tag) => {
const m = s.match(makeTagRegex(tag));
if (m === null) return '<!-- ' + tag + ':start -->' + '<!-- ' + tag + ':end -->';
return m[0];
};

const coalesce = (m, f) => m === null ? '' : f(m);

const strip = s => s.replace(/^\s+|\s+$/g, '');

const toHeaderCase = str => strip(str)
.toLowerCase()
const toHeaderCase = str =>
strip(str).toLowerCase()
.replace(/(eth|sha|lz|uups|(eip|rip|erc|push|create)\-?[0-9]+i?)/g, m => m.toUpperCase())
.split(/\s+/)
.map(w => w.replace(/^([a-zA-Z])/, c => c.toUpperCase()))
Expand All @@ -44,8 +44,9 @@ async function main() {
m => m[1] + '(' + m[2].split(',').map(x => strip(x).split(/\s+/)[0]) + ')'
);

const cleanNatspecOrNote = s => deindent(strip(s
.replace(/\s+\/\/\/?/g, '\n').replace(/\s?\n\s?/g, ' \n')
const cleanNatspecOrNote = s => deindent(strip(
s.replace(/\s+\/\/\/?/g, '\n')
.replace(/\s?\n\s?/g, ' \n')
.replace(/```([\s\S]+?)```/g, '```solidity$1```')
.replace(/^\/\/\/\s+@[a-z]+\s?/, '')
));
Expand Down Expand Up @@ -182,21 +183,23 @@ async function main() {

const docHeader = '# ' + getTitle(srcPath) + '\n\n' + getNotice(src);
let docChunks = [];
sections.forEach(x => {
let a = getStructsAndEnums(x.src);
if (a.length < 1) a = getCustomErrors(x.src);
if (a.length < 1) a = getFunctionsAndModifiers(x.src);
if (a.length < 1) a = getConstantsAndImmutables(x.src);
if (a.length) {
docChunks.push('## ' + x.h2);
if (x.note) docChunks.push(x.note);
a.forEach(y => docChunks.push(
sections.forEach(x =>
[
getStructsAndEnums,
getCustomErrors,
getFunctionsAndModifiers,
getConstantsAndImmutables
]
.reduce((acc, f) => acc.length ? acc : f(x.src), [])
.forEach((y, i) =>
docChunks.push(
...(i ? [] : ['## ' + x.h2, ...(x.note ? [x.note] : [])]),
'### ' + y.h3,
'```solidity\n' + y.def + '\n```',
y.natspec
));
}
});
)
)
);

if (docChunks.length) {
writeSync(
Expand Down

0 comments on commit bd92510

Please sign in to comment.