diff --git a/apps/design-system/src/app/not-found.tsx b/apps/design-system/src/app/not-found.old similarity index 100% rename from apps/design-system/src/app/not-found.tsx rename to apps/design-system/src/app/not-found.old diff --git a/apps/design-system/src/components/navigation/use-side-navigation-items.tsx b/apps/design-system/src/components/navigation/use-side-navigation-items.tsx index abf7d5239..429404ce5 100644 --- a/apps/design-system/src/components/navigation/use-side-navigation-items.tsx +++ b/apps/design-system/src/components/navigation/use-side-navigation-items.tsx @@ -62,6 +62,10 @@ export function useSideNavigationItems() { const allDocumentIds = documents.getAll().map((document) => document.id); const documentHierarchy = getDocumentHierarchy(allDocumentIds); + if (!documentHierarchy) { + return []; + } + const topLevelHierarchy = documentHierarchy.children.find( (child) => child.slug === slug[0] ); diff --git a/apps/design-system/src/lib/documents/document-hierarchy.ts b/apps/design-system/src/lib/documents/document-hierarchy.ts index 1a10ef88c..763b82c1a 100644 --- a/apps/design-system/src/lib/documents/document-hierarchy.ts +++ b/apps/design-system/src/lib/documents/document-hierarchy.ts @@ -14,9 +14,11 @@ export type DocumentHierarchy = { children: DocumentHierarchy[]; }; -function getDocumentHierarchyInternal(paths: string[]): DocumentHierarchy { +function getDocumentHierarchyInternal( + paths: string[] +): DocumentHierarchy | undefined { if (!paths || paths.length === 0) { - throw new Error(`Invalid paths.`); + return; } const hierarchy: DocumentHierarchy = { @@ -86,9 +88,15 @@ function cleanSlugs(value: DocumentHierarchy): DocumentHierarchy { }; } -export function getDocumentHierarchy(paths: string[]): DocumentHierarchy { +export function getDocumentHierarchy( + paths: string[] +): DocumentHierarchy | undefined { const hierarchy = getDocumentHierarchyInternal(paths); + if (!hierarchy) { + return; + } + return cloneDeepWith(hierarchy, (value) => { if (isDocumentHierarchy(value)) { return cleanSlugs(value); diff --git a/package.json b/package.json index 2a1ee7fbc..b6a468fc9 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "design-system": "nx run @govie-ds/design-system:dev", "design-system:build": "nx run @govie-ds/design-system:build", + "design-system:build:prod": "cross-env CI=true && nx run @govie-ds/design-system:build", "build": "nx run-many --target=build --all", "test": "nx run-many --target=test --all --verbose", "tokens:build": "nx run @govie-ds/tokens:build", @@ -16,6 +17,7 @@ "components:storybook": "nx run @govie-ds/design-components:storybook" }, "devDependencies": { + "cross-env": "^7.0.3", "nx": "^18.1.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb8738094..aaec42af5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: devDependencies: + cross-env: + specifier: ^7.0.3 + version: 7.0.3 nx: specifier: ^18.1.3 version: 18.1.3 @@ -3338,6 +3341,11 @@ packages: core-util-is@1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} + cross-env@7.0.3: + resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==} + engines: {node: '>=10.14', npm: '>=6', yarn: '>=1'} + hasBin: true + cross-spawn@7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -10191,6 +10199,10 @@ snapshots: core-util-is@1.0.3: {} + cross-env@7.0.3: + dependencies: + cross-spawn: 7.0.3 + cross-spawn@7.0.3: dependencies: path-key: 3.1.1