Skip to content

Commit 7e2c5c2

Browse files
jonphippsclaude
andcommitted
feat: implement environment-based configuration refactor
- Created shared-config library with factory functions for Docusaurus configuration - Implemented environment-based configuration using .env files for different deployment targets - Updated portal to use new environment configuration system with legacy compatibility - Replaced hardcoded site configurations with dynamic environment loading - Added proper workspace dependencies and module resolution - Updated unit tests to use new shared-config system with mock environment configurations - Ensured Nx caching compatibility with pure functions - Added TypeScript path mappings and vite config aliases for proper module resolution - Maintained backward compatibility with existing regression tests All tests passing with complete coverage of URL generation and cross-site navigation functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 14bc19c commit 7e2c5c2

35 files changed

+2467
-514
lines changed

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

libs/shared-config/.swcrc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"tsx": false,
6+
"decorators": false,
7+
"dynamicImport": true
8+
},
9+
"target": "es2020",
10+
"loose": false,
11+
"externalHelpers": false
12+
},
13+
"module": {
14+
"type": "commonjs"
15+
},
16+
"exclude": [
17+
"jest.config.ts",
18+
".*\\.spec.tsx?$",
19+
".*\\.test.tsx?$",
20+
"./src/jest-setup.ts$"
21+
]
22+
}

libs/shared-config/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# shared-config
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Building
6+
7+
Run `nx build shared-config` to build the library.
8+
9+
## Running unit tests
10+
11+
Run `nx test shared-config` to execute the unit tests via [Vitest](https://vitest.dev/).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import baseConfig from '../../eslint.config.mjs';
2+
3+
export default [
4+
...baseConfig,
5+
{
6+
files: ['**/*.json'],
7+
rules: {
8+
'@nx/dependency-checks': [
9+
'error',
10+
{
11+
ignoredFiles: [
12+
'{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}',
13+
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
14+
],
15+
},
16+
],
17+
},
18+
languageOptions: {
19+
parser: await import('jsonc-eslint-parser'),
20+
},
21+
},
22+
];

libs/shared-config/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@ifla/shared-config",
3+
"version": "0.0.1",
4+
"private": true,
5+
"type": "commonjs",
6+
"main": "./dist/index.cjs.js",
7+
"types": "./dist/index.d.ts",
8+
"exports": {
9+
".": {
10+
"require": "./dist/index.cjs.js",
11+
"import": "./dist/index.esm.js",
12+
"types": "./dist/index.d.ts"
13+
}
14+
},
15+
"dependencies": {
16+
"tslib": "^2.3.0"
17+
}
18+
}

libs/shared-config/project.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "shared-config",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/shared-config/src",
5+
"projectType": "library",
6+
"tags": [],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/rollup:rollup",
10+
"outputs": ["{options.outputPath}"],
11+
"options": {
12+
"outputPath": "libs/shared-config/dist",
13+
"main": "libs/shared-config/src/index.ts",
14+
"tsConfig": "libs/shared-config/tsconfig.lib.json",
15+
"project": "libs/shared-config/package.json",
16+
"compiler": "tsc",
17+
"format": ["cjs", "esm"],
18+
"generateExportsField": false,
19+
"assets": [
20+
{
21+
"input": "libs/shared-config/src/lib",
22+
"glob": "defaults.json",
23+
"output": "lib"
24+
}
25+
]
26+
}
27+
}
28+
}
29+
}

libs/shared-config/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Main exports for shared-config library
2+
export * from './lib/createBaseConfig';
3+
export * from './lib/createThemeConfig';
4+
export * from './lib/createPluginConfig';
5+
export * from './lib/createFooterConfig';
6+
export * from './lib/utils/loadEnvConfig';
7+
export * from './lib/utils/getSiteUrl';
8+
export * from './lib/types';
9+
export { default as defaults } from './lib/defaults.json';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { BaseConfigOptions } from './types';
2+
import defaults from './defaults.json';
3+
4+
/**
5+
* Factory function to create base Docusaurus configuration
6+
* This is a pure function that returns a consistent configuration object
7+
*/
8+
export function createBaseConfig(options: BaseConfigOptions) {
9+
return {
10+
title: options.title,
11+
tagline: options.tagline,
12+
url: options.url,
13+
baseUrl: options.baseUrl,
14+
projectName: options.projectName,
15+
16+
// Static values from defaults
17+
organizationName: defaults.organizationName,
18+
favicon: defaults.favicon,
19+
trailingSlash: defaults.trailingSlash,
20+
onBrokenLinks: defaults.onBrokenLinks as 'warn',
21+
onBrokenMarkdownLinks: defaults.onBrokenMarkdownLinks as 'warn',
22+
onBrokenAnchors: defaults.onBrokenAnchors as 'warn',
23+
onDuplicateRoutes: defaults.onDuplicateRoutes as 'warn',
24+
25+
// Future flags for Docusaurus v4
26+
future: defaults.future,
27+
28+
// i18n configuration
29+
i18n: defaults.i18n,
30+
};
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { FooterConfigOptions } from './types';
2+
3+
/**
4+
* Factory function to create footer configuration
5+
* This is a pure function that returns a consistent footer configuration
6+
*/
7+
export function createFooterConfig(options: FooterConfigOptions) {
8+
const { links = [], copyright } = options;
9+
10+
return {
11+
style: 'dark',
12+
links,
13+
copyright: copyright || `Copyright © ${new Date().getFullYear()} International Federation of Library Associations and Institutions (IFLA)`,
14+
};
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { PluginConfigOptions } from './types';
2+
3+
/**
4+
* Factory function to create plugin configuration
5+
* This is a pure function that returns a consistent plugin configuration
6+
*/
7+
export function createPluginConfig(options: PluginConfigOptions) {
8+
const { docsPath = './docs', editUrl, showReadingTime = true, customCss = './src/css/custom.css' } = options;
9+
10+
return {
11+
docs: {
12+
path: docsPath,
13+
sidebarPath: './sidebars.ts',
14+
editUrl,
15+
remarkPlugins: [],
16+
},
17+
blog: showReadingTime ? {
18+
showReadingTime: true,
19+
editUrl,
20+
} : false,
21+
theme: {
22+
customCss,
23+
},
24+
};
25+
}

0 commit comments

Comments
 (0)