diff --git a/dist/transformers/preview/component/api.d.ts b/dist/transformers/preview/component/api.d.ts index 2560053b..5badbed7 100644 --- a/dist/transformers/preview/component/api.d.ts +++ b/dist/transformers/preview/component/api.d.ts @@ -14,5 +14,5 @@ export declare const writeComponentMetadataApi: (id: string, summary: ComponentL * @param handoff * @param componentData */ -export declare const updateComponentSummaryApi: (handoff: Handoff, componentData: ComponentListObject[]) => Promise; +export declare const updateComponentSummaryApi: (handoff: Handoff, componentData: ComponentListObject[], isFullRebuild?: boolean) => Promise; export default writeComponentSummaryAPI; diff --git a/dist/transformers/preview/component/api.js b/dist/transformers/preview/component/api.js index d3bac558..c2a976b6 100644 --- a/dist/transformers/preview/component/api.js +++ b/dist/transformers/preview/component/api.js @@ -76,8 +76,13 @@ exports.writeComponentMetadataApi = writeComponentMetadataApi; * @param handoff * @param componentData */ -const updateComponentSummaryApi = (handoff, componentData // Partial list (may be empty) -) => __awaiter(void 0, void 0, void 0, function* () { +const updateComponentSummaryApi = (handoff_1, componentData_1, ...args_1) => __awaiter(void 0, [handoff_1, componentData_1, ...args_1], void 0, function* (handoff, componentData, isFullRebuild = false) { + if (isFullRebuild) { + // Full rebuild: replace the entire file + yield writeComponentSummaryAPI(handoff, componentData); + return; + } + // Partial update: merge with existing data const apiPath = path_1.default.resolve(handoff.workingPath, 'public/api/components.json'); let existingData = []; if (fs_extra_1.default.existsSync(apiPath)) { diff --git a/dist/transformers/preview/component/builder.js b/dist/transformers/preview/component/builder.js index d37d460a..fd695fb7 100644 --- a/dist/transformers/preview/component/builder.js +++ b/dist/transformers/preview/component/builder.js @@ -125,7 +125,8 @@ function processComponents(handoff, id, segmentToProcess) { } } // Always merge and write summary file, even if no components processed - yield (0, api_1.updateComponentSummaryApi)(handoff, result); + const isFullRebuild = !id; + yield (0, api_1.updateComponentSummaryApi)(handoff, result, isFullRebuild); return result; }); } diff --git a/src/app/components/util/index.ts b/src/app/components/util/index.ts index 699e399e..909997cf 100644 --- a/src/app/components/util/index.ts +++ b/src/app/components/util/index.ts @@ -252,7 +252,7 @@ export const staticBuildMenu = () => { // The user wants to inject the component menu here return { title: sub.title, - menu: staticBuildComponentMenu(sub.components), + menu: staticBuildComponentMenu(), }; } if (sub.tokens) { @@ -281,16 +281,13 @@ export const staticBuildMenu = () => { return sections.concat(custom).sort((a: SectionLink, b: SectionLink) => a.weight - b.weight); }; -const staticBuildComponentMenu = (type?: string) => { +const staticBuildComponentMenu = () => { let menu = []; let components = fetchComponents(); - if (type) { - components = components.filter((c) => c.type === type); - } // Build the submenu of exportables (components) const groupedComponents = groupBy(components, (e) => e.group ?? ''); Object.keys(groupedComponents).forEach((group) => { - const menuGroup = { title: group, menu: [] }; + const menuGroup = { title: group || 'Uncategorized', menu: [] }; groupedComponents[group].forEach((component) => { const docs = fetchDocPageMetadataAndContent('docs/components/', component.id); let title = startCase(component.id); diff --git a/src/transformers/preview/component/api.ts b/src/transformers/preview/component/api.ts index 2b068a5b..1ce19fe2 100644 --- a/src/transformers/preview/component/api.ts +++ b/src/transformers/preview/component/api.ts @@ -3,6 +3,7 @@ import path from 'path'; import Handoff from '../../../index'; import { ComponentListObject, TransformComponentTokensResult } from '../types'; + function updateObject(target: T, source: Partial): T { return Object.entries(source).reduce( (acc, [key, value]) => { @@ -80,8 +81,16 @@ export const writeComponentMetadataApi = async (id: string, summary: ComponentLi */ export const updateComponentSummaryApi = async ( handoff: Handoff, - componentData: ComponentListObject[] // Partial list (may be empty) + componentData: ComponentListObject[], + isFullRebuild: boolean = false ) => { + if (isFullRebuild) { + // Full rebuild: replace the entire file + await writeComponentSummaryAPI(handoff, componentData); + return; + } + + // Partial update: merge with existing data const apiPath = path.resolve(handoff.workingPath, 'public/api/components.json'); let existingData: ComponentListObject[] = []; diff --git a/src/transformers/preview/component/builder.ts b/src/transformers/preview/component/builder.ts index f311004a..92f038b1 100644 --- a/src/transformers/preview/component/builder.ts +++ b/src/transformers/preview/component/builder.ts @@ -120,7 +120,8 @@ export async function processComponents( } // Always merge and write summary file, even if no components processed - await updateComponentSummaryApi(handoff, result); + const isFullRebuild = !id; + await updateComponentSummaryApi(handoff, result, isFullRebuild); return result; }