Skip to content

Commit

Permalink
fix: doc generator script returns error (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Jan 8, 2025
1 parent 0e1e7ec commit bcfff6d
Showing 1 changed file with 48 additions and 36 deletions.
84 changes: 48 additions & 36 deletions docs-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,64 @@ jsdoc2md
})
.then((res) => {
const categories = res.reduce((acc, current) => {
const category = current.category.toLowerCase();

// Handle multiple categories
if (category.includes(',')) {
const categories = category.split(', ');
categories.forEach((c) => {
if (!acc[c]) {
acc[c] = [];
}

acc[c].push({
...current,
category: c,
try {
const category = current.category.toLowerCase();

// Handle multiple categories
if (category.includes(',')) {
const categories = category.split(', ');
categories.forEach((c) => {
if (!acc[c]) {
acc[c] = [];
}

acc[c].push({
...current,
category: c,
});
});
});
} else {
if (!acc[category]) {
acc[category] = [];
} else {
// verify if the acc is not null and is not an empty object
if (
acc &&
Object.keys(acc).length === 0 &&
acc.constructor === Object
) {
if (!acc[category]) {
acc[category] = [];
}

acc[category].push(current);
}
}

acc[category].push(current);
return acc;
} catch (error) {
//no category found. just exit here
}

return acc;
}, {});

const docsOutputPath = path.join('docs', 'docs', 'auto-generated');
if (!fs.existsSync(docsOutputPath)) {
fs.mkdirSync(docsOutputPath);
}

for (let [category, items] of Object.entries(categories)) {
let md = `---\nslug: /${category.toLowerCase()}\n---\n\n# ${capitalize(
category
)}\n\n`;

md += items
.sort((funcA, funcB) => sortFunctions(funcA, funcB))
.map(getDocsSection)
.join('');

fs.writeFileSync(
path.join(docsOutputPath, `${category.toLowerCase()}.mdx`),
md,
{ encoding: 'utf8' }
);
if (categories) {
for (let [category, items] of Object.entries(categories)) {
let md = `---\nslug: /${category.toLowerCase()}\n---\n\n# ${capitalize(
category
)}\n\n`;

md += items
.sort((funcA, funcB) => sortFunctions(funcA, funcB))
.map(getDocsSection)
.join('');

fs.writeFileSync(
path.join(docsOutputPath, `${category.toLowerCase()}.mdx`),
md,
{ encoding: 'utf8' }
);
}
}

const [falsoESMPath] = glob.sync('dist/packages/falso/index.esm.js');
Expand Down

0 comments on commit bcfff6d

Please sign in to comment.