Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: doc generator script returns error #391

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading