Files
twenty/packages/twenty-docs/scripts/generate-navigation-template.ts
github-actions[bot] e02c24bd3a i18n - docs translations (#15904)
Created by Github action

---------

Co-authored-by: Abdul Rahman <ar5438376@gmail.com>
Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
Co-authored-by: github-actions <github-actions@twenty.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
2025-11-18 17:21:48 +01:00

82 lines
1.5 KiB
TypeScript

import fs from 'fs';
import path from 'path';
type BasePage = string | BaseGroup;
type BaseGroup = {
key: string;
label: string;
pages: BasePage[];
};
type BaseTab = {
key: string;
label: string;
groups: BaseGroup[];
};
type BaseStructure = {
tabs: BaseTab[];
};
type TemplateGroup = {
label: string;
groups?: Record<string, TemplateGroup>;
};
type TemplateTab = {
label: string;
groups: Record<string, TemplateGroup>;
};
type TemplateFile = {
tabs: Record<string, TemplateTab>;
};
const baseStructurePath = path.resolve(
__dirname,
'../navigation/base-structure.json',
);
const templatePath = path.resolve(
__dirname,
'../navigation/navigation.template.json',
);
const baseStructure: BaseStructure = JSON.parse(
fs.readFileSync(baseStructurePath, 'utf8'),
);
const buildGroupMap = (
groups: BaseGroup[],
): Record<string, TemplateGroup> =>
groups.reduce<Record<string, TemplateGroup>>((acc, group) => {
const nestedGroups = group.pages.filter(
(page): page is BaseGroup => typeof page !== 'string',
);
acc[group.key] = {
label: group.label,
...(nestedGroups.length > 0
? { groups: buildGroupMap(nestedGroups) }
: {}),
};
return acc;
}, {});
const template: TemplateFile = {
tabs: baseStructure.tabs.reduce<Record<string, TemplateTab>>(
(acc, tab) => ({
...acc,
[tab.key]: {
label: tab.label,
groups: buildGroupMap(tab.groups),
},
}),
{},
),
};
fs.writeFileSync(templatePath, `${JSON.stringify(template, null, 2)}\n`);