From 344d280734ecac974310bd8cc610fccfcc18e4a0 Mon Sep 17 00:00:00 2001 From: DanieCuevas <43822444+DanielCuevas1208@users.noreply.github.com> Date: Mon, 3 Aug 2026 15:10:21 -0700 Subject: [PATCH] feat: extend engineer profile --- .github/workflows/ci.yml | 2 +- .github/workflows/refresh.yml | 2 +- .nvmrc | 2 +- CONTRIBUTING.md | 2 +- README.md | 34 ++- engineer-profile.config.json | 1 + package-lock.json | 462 ++-------------------------------- package.json | 6 +- src/config/loader.ts | 13 + src/index.ts | 27 +- src/publish/site.ts | 33 +-- src/publish/themes.ts | 98 ++++++++ src/types.ts | 2 + tests/themes.test.ts | 131 ++++++++++ 14 files changed, 331 insertions(+), 484 deletions(-) create mode 100644 src/publish/themes.ts create mode 100644 tests/themes.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eae27d9..1870978 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: "20" + node-version: "22" cache: npm - name: Install dependencies diff --git a/.github/workflows/refresh.yml b/.github/workflows/refresh.yml index 360cd31..cb2d121 100644 --- a/.github/workflows/refresh.yml +++ b/.github/workflows/refresh.yml @@ -24,7 +24,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: "20" + node-version: "22" cache: npm - name: Install dependencies diff --git a/.nvmrc b/.nvmrc index 209e3ef..2bd5a0a 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -20 +22 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7802f1c..b5f825b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ ## Local checks -Use Node.js 20 or newer. +Use Node.js 22 or newer. ```bash npm ci diff --git a/README.md b/README.md index f1a2a81..ee9b15c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ EngineerProfile builds a local engineering portfolio from public repository data. It stores repository metadata, commits, releases, privacy settings, and preview -paths in SQLite. It publishes a static site from these records. +paths in SQLite. It publishes a static site from these records with a named theme. ## Value @@ -43,7 +43,8 @@ flowchart LR | `src/changelog/` | Prefer release notes and fall back to commit groups. | | `src/privacy/` | Hide projects and block sensitive commit messages. | | `src/preview/` | Capture fixed viewport screenshots with Playwright. | -| `src/publish/` | Render HTML, changelog files, and preview assets. | +| `src/publish/site.ts` | Render HTML, changelog files, and preview assets. | +| `src/publish/themes.ts` | Register named themes and resolve presentation settings. | | `fixtures/` | Provide deterministic demo data and local preview pages. | The refresh command runs each stage in a fixed order. @@ -51,7 +52,7 @@ If a preview fails, the command reports the skip and keeps the rest of the snaps ## Setup -Use Node.js 20 or newer. +Use Node.js 22 or newer. ```bash npm ci @@ -74,6 +75,10 @@ The loader accepts repository limits from 1 through 100. It rejects malformed values before network access. CLI `--config`, `--data`, and `--output` options override file values. +The `theme` field selects a named presentation. +Valid names are `default` and `light`. +Omit the field to use the default theme. + Run a network-backed refresh with the checked-in settings: ```bash @@ -94,6 +99,22 @@ npm run refresh Do not put a token in repository files. Use `.env.example` as a variable reference. +## Themes + +Each theme defines the color scheme and CSS variables for the published site. +The `default` theme uses a dark palette with blue accents. +The `light` theme uses pale panels with dark text. + +Build the demo in the light theme: + +```bash +npm run demo -- --theme light +``` + +The `--theme` option works on the `demo`, `publish`, and `refresh` commands. +It overrides the theme from the configuration file. +An unknown theme name fails the command before any output is written. + ## Sample output The fixture set contains `signal-router` and `metrics-kit`. @@ -119,6 +140,7 @@ Build before direct CLI commands. | Command | Result | | --- | --- | | `npm run demo` | Run the complete fixture pipeline. | +| `npm run demo -- --theme light` | Run the demo with the light theme. | | `npm run ingest -- octocat --limit 3` | Load public repository evidence. | | `npm run ingest -- --fixture` | Load fixture records only. | | `npm run capture -- --fixture` | Capture local fixture pages. | @@ -172,6 +194,7 @@ The test suite covers these core behaviors: - Configured refresh orchestration. - Release source links. - Deterministic HTML output. +- Theme resolution and deterministic themed publishing. - Playwright screenshot capture. Run the local checks: @@ -205,9 +228,12 @@ The fixture pipeline provides deterministic data for repeatable checks. | --- | --- | --- | | v0.1 | Complete | Fixture demo, GitHub ingest, changelog, capture, publish, and privacy controls. | | v0.2 | Complete | Checked-in configuration, coordinated refresh command, and scheduled artifact workflow. | -| v0.3 | Next | Custom themes and deployment adapters. | +| v0.3 | In progress | Named themes shipped. Deployment adapters remain. | | v0.4 | Later | Commit-diff summaries and an RSS feed. | +v0.3 ships the `default` and `light` themes. +Deployment adapters are the remaining part of v0.3. + ## License MIT. See [LICENSE](LICENSE). diff --git a/engineer-profile.config.json b/engineer-profile.config.json index 81008fb..6c64b9b 100644 --- a/engineer-profile.config.json +++ b/engineer-profile.config.json @@ -5,6 +5,7 @@ "repositoryLimit": 5, "dataDir": "data", "outputDir": "output", + "theme": "default", "privacy": { "hiddenProjects": [], "redactEmails": true, diff --git a/package-lock.json b/package-lock.json index 87f5d51..44eb7fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "engineer-profile", - "version": "0.2.0", + "version": "0.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "engineer-profile", - "version": "0.2.0", + "version": "0.3.0", "license": "MIT", "dependencies": { - "better-sqlite3": "^11.8.1", + "better-sqlite3": "^13.0.2", "commander": "^15.0.0" }, "bin": { @@ -25,7 +25,7 @@ "vitest": "^3.0.5" }, "engines": { - "node": ">=20" + "node": ">=22.12.0" } }, "node_modules/@esbuild/aix-ppc64": { @@ -1353,79 +1353,16 @@ "node": ">=12" } }, - "node_modules/base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, "node_modules/better-sqlite3": { - "version": "11.10.0", - "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.10.0.tgz", - "integrity": "sha512-EwhOpyXiOEL/lKzHz9AW1msWFNzGc/z+LzeB3/jnFJpxu+th2yqvzsSWas1v9jgs9+xiXJcD5A8CJxAG2TaghQ==", - "hasInstallScript": true, + "version": "13.0.2", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-13.0.2.tgz", + "integrity": "sha512-jW6oufeDhXZaiX9Lw5A+oerVClx4iFrI6uDj1zu7SqUAjak9vbJvA0NEcKLNxHiQHb6kYCoFzzXYV0YOauhV3g==", "license": "MIT", "dependencies": { - "bindings": "^1.5.0", - "prebuild-install": "^7.1.1" - } - }, - "node_modules/bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "license": "MIT", - "dependencies": { - "file-uri-to-path": "1.0.0" - } - }, - "node_modules/bl": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", - "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", - "license": "MIT", - "dependencies": { - "buffer": "^5.5.0", - "inherits": "^2.0.4", - "readable-stream": "^3.4.0" - } - }, - "node_modules/buffer": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", - "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT", - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.1.13" + "node-addon-api": "^8.0.0" + }, + "engines": { + "node": ">=22" } }, "node_modules/cac": { @@ -1465,12 +1402,6 @@ "node": ">= 16" } }, - "node_modules/chownr": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", - "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", - "license": "ISC" - }, "node_modules/commander": { "version": "15.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-15.0.0.tgz", @@ -1498,21 +1429,6 @@ } } }, - "node_modules/decompress-response": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", - "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", - "license": "MIT", - "dependencies": { - "mimic-response": "^3.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/deep-eql": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz", @@ -1523,33 +1439,6 @@ "node": ">=6" } }, - "node_modules/deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", - "license": "MIT", - "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/detect-libc": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", - "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", - "license": "Apache-2.0", - "engines": { - "node": ">=8" - } - }, - "node_modules/end-of-stream": { - "version": "1.4.5", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", - "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==", - "license": "MIT", - "dependencies": { - "once": "^1.4.0" - } - }, "node_modules/es-module-lexer": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz", @@ -1609,15 +1498,6 @@ "@types/estree": "^1.0.0" } }, - "node_modules/expand-template": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", - "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==", - "license": "(MIT OR WTFPL)", - "engines": { - "node": ">=6" - } - }, "node_modules/expect-type": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", @@ -1646,18 +1526,6 @@ } } }, - "node_modules/file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "license": "MIT" - }, - "node_modules/fs-constants": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", - "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", - "license": "MIT" - }, "node_modules/fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", @@ -1673,44 +1541,6 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, - "node_modules/github-from-package": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", - "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==", - "license": "MIT" - }, - "node_modules/ieee754": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "BSD-3-Clause" - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "license": "ISC" - }, - "node_modules/ini": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", - "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", - "license": "ISC" - }, "node_modules/js-tokens": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-9.0.1.tgz", @@ -1735,33 +1565,6 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, - "node_modules/mimic-response": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", - "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", - "license": "MIT", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/minimist": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", - "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/mkdirp-classic": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", - "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", - "license": "MIT" - }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -1788,31 +1591,13 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, - "node_modules/napi-build-utils": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-2.0.0.tgz", - "integrity": "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==", - "license": "MIT" - }, - "node_modules/node-abi": { - "version": "3.94.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.94.0.tgz", - "integrity": "sha512-W5ZNO5KRPB5TkYmGVD9F6YqhsglXJzE6etpbmT+f6EQElhiX/UTG551cnsRGvLG3fyZEg9HwaDmNmj5nwJ4z9g==", + "node_modules/node-addon-api": { + "version": "8.9.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.9.1.tgz", + "integrity": "sha512-4eUQWVPCUUUiBjLnHS3cXWeC6ryoPUc0U3rP7IuzapoGbzMqd/r6KKO0clr0b+snQhsrueFEhCZDdK+LK7hxKg==", "license": "MIT", - "dependencies": { - "semver": "^7.3.5" - }, "engines": { - "node": ">=10" - } - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "license": "ISC", - "dependencies": { - "wrappy": "1" + "node": "^18 || ^20 || >= 21" } }, "node_modules/pathe": { @@ -1845,6 +1630,7 @@ "integrity": "sha512-RvwwcruNjI1ncT5xRakeyS9Lf8lcItv34KD+aif+VH9kduAyfYBipGh12274xtenIPZ119/R9BdTBa8gAwSh0A==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -1913,72 +1699,6 @@ "node": "^10 || ^12 || >=14" } }, - "node_modules/prebuild-install": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz", - "integrity": "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==", - "deprecated": "No longer maintained. Please contact the author of the relevant native addon; alternatives are available.", - "license": "MIT", - "dependencies": { - "detect-libc": "^2.0.0", - "expand-template": "^2.0.3", - "github-from-package": "0.0.0", - "minimist": "^1.2.3", - "mkdirp-classic": "^0.5.3", - "napi-build-utils": "^2.0.0", - "node-abi": "^3.3.0", - "pump": "^3.0.0", - "rc": "^1.2.7", - "simple-get": "^4.0.0", - "tar-fs": "^2.0.0", - "tunnel-agent": "^0.6.0" - }, - "bin": { - "prebuild-install": "bin.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/pump": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz", - "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==", - "license": "MIT", - "dependencies": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, - "node_modules/rc": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", - "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", - "license": "(BSD-2-Clause OR MIT OR Apache-2.0)", - "dependencies": { - "deep-extend": "^0.6.0", - "ini": "~1.3.0", - "minimist": "^1.2.0", - "strip-json-comments": "~2.0.1" - }, - "bin": { - "rc": "cli.js" - } - }, - "node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "license": "MIT", - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/rollup": { "version": "4.62.3", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.62.3.tgz", @@ -2024,38 +1744,6 @@ "fsevents": "~2.3.2" } }, - "node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, - "node_modules/semver": { - "version": "7.8.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", - "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", - "license": "ISC", - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/siginfo": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", @@ -2063,51 +1751,6 @@ "dev": true, "license": "ISC" }, - "node_modules/simple-concat": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", - "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, - "node_modules/simple-get": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz", - "integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT", - "dependencies": { - "decompress-response": "^6.0.0", - "once": "^1.3.1", - "simple-concat": "^1.0.0" - } - }, "node_modules/source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", @@ -2132,24 +1775,6 @@ "dev": true, "license": "MIT" }, - "node_modules/string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "license": "MIT", - "dependencies": { - "safe-buffer": "~5.2.0" - } - }, - "node_modules/strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/strip-literal": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-3.1.0.tgz", @@ -2163,34 +1788,6 @@ "url": "https://github.com/sponsors/antfu" } }, - "node_modules/tar-fs": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.5.tgz", - "integrity": "sha512-OboTd8mmMhZDNPV+UjQcK9yKAatXu2aJ+r1w4im1Otd4M4fl2hwvdoXUxIYHFTHWK/3y3FarBP70v3vwmGlOxw==", - "license": "MIT", - "dependencies": { - "chownr": "^1.1.1", - "mkdirp-classic": "^0.5.2", - "pump": "^3.0.0", - "tar-stream": "^2.1.4" - } - }, - "node_modules/tar-stream": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", - "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", - "license": "MIT", - "dependencies": { - "bl": "^4.0.3", - "end-of-stream": "^1.4.1", - "fs-constants": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^3.1.1" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/tinybench": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", @@ -2286,18 +1883,6 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, - "node_modules/tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", - "license": "Apache-2.0", - "dependencies": { - "safe-buffer": "^5.0.1" - }, - "engines": { - "node": "*" - } - }, "node_modules/typescript": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz", @@ -2340,18 +1925,13 @@ "dev": true, "license": "MIT" }, - "node_modules/util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "license": "MIT" - }, "node_modules/vite": { "version": "7.3.6", "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.6.tgz", "integrity": "sha512-4XP60spRGjSZFf1qYH+dJIkK2znL3zQfl9KkOV9MkkRR/3Dls0dxaBsQPTloEc5BLXWPL9vsOxopxyKoMmDueg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.27.0 || ^0.28.0", "fdir": "^6.5.0", @@ -2548,12 +2128,6 @@ "engines": { "node": ">=8" } - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "license": "ISC" } } } diff --git a/package.json b/package.json index d36edbe..64a939e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "engineer-profile", - "version": "0.2.0", + "version": "0.3.0", "description": "Self-maintaining engineering portfolio from repository activity", "type": "module", "main": "dist/index.js", @@ -21,7 +21,7 @@ "refresh": "npm run build && node dist/index.js refresh" }, "engines": { - "node": ">=20" + "node": ">=22.12.0" }, "keywords": [ "portfolio", @@ -40,7 +40,7 @@ }, "homepage": "https://github.com/DanielCuevas1208/engineer-profile#readme", "dependencies": { - "better-sqlite3": "^11.8.1", + "better-sqlite3": "^13.0.2", "commander": "^15.0.0" }, "devDependencies": { diff --git a/src/config/loader.ts b/src/config/loader.ts index 406896b..1e0912d 100644 --- a/src/config/loader.ts +++ b/src/config/loader.ts @@ -2,6 +2,7 @@ import { readFileSync } from "node:fs"; import type { PortfolioConfig, PrivacyConfig } from "../types.js"; import { DEFAULT_CONFIG, DEFAULT_PRIVACY } from "../types.js"; import { mergePrivacy } from "../privacy/controls.js"; +import { availableThemeNames, isKnownTheme } from "../publish/themes.js"; export const DEFAULT_CONFIG_PATH = "engineer-profile.config.json"; @@ -29,6 +30,17 @@ function readLimit(source: ConfigValue, key: string, fallback: number): number { return value; } +function readTheme(source: ConfigValue, key: string, fallback: string): string { + if (!(key in source)) return fallback; + const value = source[key]; + if (typeof value !== "string" || value.trim() === "" || !isKnownTheme(value.trim())) { + throw new Error( + `Configuration field "${key}" must be one of: ${availableThemeNames().join(", ")}.` + ); + } + return value.trim(); +} + function readPrivacy(source: ConfigValue): PrivacyConfig { if (!("privacy" in source)) return DEFAULT_PRIVACY; if (!isConfigValue(source.privacy)) { @@ -78,6 +90,7 @@ export function loadPortfolioConfig( repositoryLimit: readLimit(parsed, "repositoryLimit", DEFAULT_CONFIG.repositoryLimit), dataDir: readString(parsed, "dataDir", DEFAULT_CONFIG.dataDir), outputDir: readString(parsed, "outputDir", DEFAULT_CONFIG.outputDir), + theme: readTheme(parsed, "theme", DEFAULT_CONFIG.theme ?? "default"), privacy: readPrivacy(parsed), clock, }; diff --git a/src/index.ts b/src/index.ts index aea5c27..a34000d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import { loadAllFixtures } from "./fixtures/loader.js"; import { openDatabase } from "./db/client.js"; import { DEFAULT_CONFIG, type PortfolioConfig } from "./types.js"; import { DEFAULT_CONFIG_PATH, loadPortfolioConfig } from "./config/loader.js"; +import { resolveTheme } from "./publish/themes.js"; import { refreshPortfolio } from "./refresh/run.js"; const program = new Command(); @@ -16,9 +17,14 @@ const program = new Command(); program .name("engineer-profile") .description("Build a local engineering portfolio from public repository evidence") - .version("0.2.0"); + .version("0.3.0"); -function resolveConfig(options: { config?: string; data?: string; output?: string }): PortfolioConfig { +function resolveConfig(options: { + config?: string; + data?: string; + output?: string; + theme?: string; +}): PortfolioConfig { const base = options.config ? loadPortfolioConfig(options.config) : existsSync(DEFAULT_CONFIG_PATH) @@ -28,6 +34,7 @@ function resolveConfig(options: { config?: string; data?: string; output?: strin ...base, dataDir: options.data ?? base.dataDir, outputDir: options.output ?? base.outputDir, + theme: options.theme ? resolveTheme(options.theme).name : base.theme, }; } @@ -35,7 +42,11 @@ function addConfigOption(command: Command): Command { return command.option("-c, --config ", "Configuration file"); } -addConfigOption(program +function addThemeOption(command: Command): Command { + return command.option("-t, --theme ", "Presentation theme name"); +} + +addThemeOption(addConfigOption(program .command("demo") .description("Run the complete fixture pipeline without network access") .option("-d, --data ", "Data directory") @@ -68,7 +79,7 @@ addConfigOption(program console.log(`Published ${result.projectCount} projects to ${result.indexPath}.`); console.log(`Copied ${copied} available preview screenshots.`); console.log("Open output/index.html in a browser."); - })); + }))); addConfigOption(program .command("ingest") @@ -120,7 +131,7 @@ addConfigOption(program console.log(`Captured ${paths.length} screenshots.`); })); -addConfigOption(program +addThemeOption(addConfigOption(program .command("publish") .description("Generate the static portfolio from SQLite") .option("-d, --data ", "Data directory") @@ -131,9 +142,9 @@ addConfigOption(program const copied = copyScreenshotsToOutput(config); console.log(`Published ${result.projectCount} projects to ${result.indexPath}.`); console.log(`Copied ${copied} available preview screenshots.`); - })); + }))); -addConfigOption(program +addThemeOption(addConfigOption(program .command("refresh") .description("Ingest, capture, and publish from the checked-in configuration") .option("-d, --data ", "Data directory") @@ -149,7 +160,7 @@ addConfigOption(program for (const error of result.captureErrors) { console.warn(`Skipped ${error.slug}: ${error.message}`); } - })); + }))); addConfigOption(program .command("status") diff --git a/src/publish/site.ts b/src/publish/site.ts index d382163..bb1fc12 100644 --- a/src/publish/site.ts +++ b/src/publish/site.ts @@ -2,6 +2,7 @@ import { cpSync, existsSync, mkdirSync, writeFileSync } from "node:fs"; import { join } from "node:path"; import { formatChangelogMarkdown } from "../changelog/generator.js"; import { openDatabase } from "../db/client.js"; +import { resolveTheme, themeCss } from "./themes.js"; import type { ChangelogEntry, PortfolioConfig, ProjectRecord } from "../types.js"; function escapeHtml(text: string): string { @@ -124,22 +125,11 @@ function projectCard( `; } -function siteCss(): string { +function siteCss(themeName: string): string { + const theme = resolveTheme(themeName); return ` :root { - color-scheme: dark; - --ink: #08111f; - --ink-soft: #0d1a2d; - --panel: #112139; - --panel-strong: #172a46; - --line: rgba(169, 195, 222, 0.18); - --text: #f3f7fb; - --muted: #9db0c7; - --blue: #67b7ff; - --blue-soft: #b8dcff; - --mint: #a7f3d0; - --orange: #ffb86b; - --shadow: 0 24px 60px rgba(0, 0, 0, 0.24); +${themeCss(theme)} font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; } * { box-sizing: border-box; } @@ -158,7 +148,7 @@ a { color: inherit; } .kicker { color: var(--mint); margin: 0 0 22px; } h1 { max-width: 760px; margin: 0; font-size: clamp(3.2rem, 8vw, 6.4rem); font-weight: 650; letter-spacing: -0.08em; line-height: 0.94; } .hero-copy { max-width: 530px; margin: 28px 0 0; color: var(--blue-soft); font-size: 1.12rem; } -.hero-aside { padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(145deg, rgba(23, 42, 70, 0.92), rgba(13, 26, 45, 0.72)); box-shadow: var(--shadow); } +.hero-aside { padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(145deg, var(--panel-grad-a), var(--panel-grad-b)); box-shadow: var(--shadow); } .aside-index { display: flex; justify-content: space-between; color: var(--orange); font: 0.68rem/1 "SFMono-Regular", Consolas, monospace; letter-spacing: 0.12em; text-transform: uppercase; } .hero-aside p { margin: 24px 0 4px; color: var(--text); font-size: 1rem; } .stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); } @@ -166,19 +156,19 @@ h1 { max-width: 760px; margin: 0; font-size: clamp(3.2rem, 8vw, 6.4rem); font-we .stat:last-child { border-right: 0; } .stat strong { display: block; color: var(--text); font-size: 1.8rem; font-weight: 600; letter-spacing: -0.04em; } .stat span { color: var(--muted); font: 0.7rem/1.3 "SFMono-Regular", Consolas, monospace; letter-spacing: 0.08em; text-transform: uppercase; } -.audit-panel { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center; margin: 26px 0 80px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 10px; background: rgba(17, 33, 57, 0.66); } +.audit-panel { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center; margin: 26px 0 80px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); } .audit-copy { color: var(--muted); font-size: 0.88rem; } .audit-copy strong { color: var(--text); font-weight: 500; } .audit-time { color: var(--blue); font: 0.7rem/1.4 "SFMono-Regular", Consolas, monospace; text-align: right; } .index-header { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 24px; } .index-header h2 { margin: 0; font-size: 2rem; font-weight: 550; letter-spacing: -0.05em; } .index-header p { max-width: 350px; margin: 0; color: var(--muted); font-size: 0.88rem; text-align: right; } -.project-card { display: grid; grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.2fr); overflow: hidden; margin-bottom: 24px; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(135deg, rgba(23, 42, 70, 0.98), rgba(13, 26, 45, 0.96)); box-shadow: var(--shadow); } -.project-visual { position: relative; min-height: 310px; background: #0a1525; } +.project-card { display: grid; grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.2fr); overflow: hidden; margin-bottom: 24px; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(135deg, var(--card-grad-a), var(--card-grad-b)); box-shadow: var(--shadow); } +.project-visual { position: relative; min-height: 310px; background: var(--visual-bg); } .screenshot { display: block; width: 100%; height: 100%; min-height: 310px; object-fit: cover; opacity: 0.9; } .placeholder { display: flex; min-height: 310px; align-items: center; justify-content: center; flex-direction: column; gap: 7px; color: var(--blue); background: repeating-linear-gradient(135deg, rgba(103, 183, 255, 0.05), rgba(103, 183, 255, 0.05) 1px, transparent 1px, transparent 14px); } .placeholder small { color: var(--muted); font: 0.68rem/1 "SFMono-Regular", Consolas, monospace; text-transform: uppercase; } -.visual-label { position: absolute; right: 16px; bottom: 16px; padding: 7px 9px; border: 1px solid rgba(255,255,255,0.18); border-radius: 5px; background: rgba(8, 17, 31, 0.72); color: var(--blue-soft); } +.visual-label { position: absolute; right: 16px; bottom: 16px; padding: 7px 9px; border: 1px solid var(--visual-chip-line); border-radius: 5px; background: var(--visual-chip); color: var(--blue-soft); } .project-body { padding: 30px 34px 32px; } .card-topline { display: flex; justify-content: space-between; gap: 12px; color: var(--blue); } .project-body h2 { margin: 18px 0 8px; font-size: 2.1rem; font-weight: 560; letter-spacing: -0.06em; } @@ -248,6 +238,7 @@ export interface PublishResult { export function publishSite(config: PortfolioConfig): PublishResult { const db = openDatabase(config.dataDir, config.clock); try { + const theme = resolveTheme(config.theme); const projects = db.listProjects(true); const generatedAt = config.clock(); const views = projects.map((project) => ({ @@ -272,14 +263,14 @@ export function publishSite(config: PortfolioConfig): PublishResult { : ""; const html = ` - + ${escapeHtml(config.title)} / Portfolio - +
diff --git a/src/publish/themes.ts b/src/publish/themes.ts new file mode 100644 index 0000000..19937d3 --- /dev/null +++ b/src/publish/themes.ts @@ -0,0 +1,98 @@ +export type ColorScheme = "dark" | "light"; + +export interface ThemeDefinition { + name: string; + label: string; + description: string; + colorScheme: ColorScheme; + css: Record; +} + +const DEFAULT_CSS: Record = { + "--ink": "#08111f", + "--ink-soft": "#0d1a2d", + "--panel": "#112139", + "--panel-strong": "#172a46", + "--line": "rgba(169, 195, 222, 0.18)", + "--text": "#f3f7fb", + "--muted": "#9db0c7", + "--blue": "#67b7ff", + "--blue-soft": "#b8dcff", + "--mint": "#a7f3d0", + "--orange": "#ffb86b", + "--shadow": "0 24px 60px rgba(0, 0, 0, 0.24)", + "--panel-soft": "rgba(17, 33, 57, 0.66)", + "--panel-grad-a": "rgba(23, 42, 70, 0.92)", + "--panel-grad-b": "rgba(13, 26, 45, 0.72)", + "--card-grad-a": "rgba(23, 42, 70, 0.98)", + "--card-grad-b": "rgba(13, 26, 45, 0.96)", + "--visual-bg": "#0a1525", + "--visual-chip": "rgba(8, 17, 31, 0.72)", + "--visual-chip-line": "rgba(255, 255, 255, 0.18)", +}; + +export const THEMES: Record = { + default: { + name: "default", + label: "Night signal", + description: "A dark theme with blue accents. This is the default presentation.", + colorScheme: "dark", + css: {}, + }, + light: { + name: "light", + label: "Daylight paper", + description: "A light theme with dark text on pale panels.", + colorScheme: "light", + css: { + "--ink": "#f4f6fa", + "--ink-soft": "#e7ecf3", + "--panel": "#ffffff", + "--panel-strong": "#eef3fa", + "--line": "rgba(13, 26, 45, 0.16)", + "--text": "#0d1a2d", + "--muted": "#4d5d74", + "--blue": "#1563c4", + "--blue-soft": "#1d4f8f", + "--mint": "#0d7a4f", + "--orange": "#9a5a00", + "--shadow": "0 24px 60px rgba(13, 26, 45, 0.16)", + "--panel-soft": "rgba(255, 255, 255, 0.72)", + "--panel-grad-a": "rgba(255, 255, 255, 0.96)", + "--panel-grad-b": "rgba(238, 243, 250, 0.92)", + "--card-grad-a": "#ffffff", + "--card-grad-b": "#eef3fa", + "--visual-bg": "#dde5ef", + "--visual-chip": "rgba(255, 255, 255, 0.86)", + "--visual-chip-line": "rgba(13, 26, 45, 0.18)", + }, + }, +}; + +export function availableThemeNames(): string[] { + return Object.keys(THEMES); +} + +export function isKnownTheme(name: string): boolean { + return Object.prototype.hasOwnProperty.call(THEMES, name); +} + +export function resolveTheme(name?: string): ThemeDefinition { + if (name === undefined || name === "default") return THEMES.default; + const theme = THEMES[name]; + if (!theme) { + throw new Error( + `Unknown theme "${name}". Available themes: ${availableThemeNames().join(", ")}.` + ); + } + return theme; +} + +export function themeCss(theme: ThemeDefinition): string { + const variables = { ...DEFAULT_CSS, ...theme.css }; + const lines = [` color-scheme: ${theme.colorScheme};`]; + for (const [key, value] of Object.entries(variables)) { + lines.push(` ${key}: ${value};`); + } + return lines.join("\n"); +} diff --git a/src/types.ts b/src/types.ts index 92c30da..b11cb60 100644 --- a/src/types.ts +++ b/src/types.ts @@ -85,6 +85,7 @@ export interface PortfolioConfig { repositoryLimit?: number; dataDir: string; outputDir: string; + theme?: string; privacy: PrivacyConfig; clock: () => string; } @@ -102,6 +103,7 @@ export const DEFAULT_CONFIG = { repositoryLimit: 5, dataDir: "data", outputDir: "output", + theme: "default", privacy: DEFAULT_PRIVACY, clock: () => new Date().toISOString(), } satisfies PortfolioConfig; diff --git a/tests/themes.test.ts b/tests/themes.test.ts new file mode 100644 index 0000000..8bcb712 --- /dev/null +++ b/tests/themes.test.ts @@ -0,0 +1,131 @@ +import { afterEach, describe, expect, it } from "vitest"; +import { mkdirSync, rmSync, readFileSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { loadPortfolioConfig } from "../src/config/loader.js"; +import { ingestOwnerRepos } from "../src/ingest/orchestrator.js"; +import { publishSite } from "../src/publish/site.js"; +import { + THEMES, + availableThemeNames, + isKnownTheme, + resolveTheme, +} from "../src/publish/themes.js"; +import { loadAllFixtures } from "../src/fixtures/loader.js"; +import { DEFAULT_CONFIG } from "../src/types.js"; + +const TEST_DIR = join("data", "test-themes"); +const TEST_FILE = join(TEST_DIR, "portfolio.json"); +const DATA_A = join("data", "test-themes-a"); +const DATA_B = join("data", "test-themes-b"); +const OUTPUT_A = join("output", "test-themes-a"); +const OUTPUT_B = join("output", "test-themes-b"); + +function fixedConfig(dataDir: string, outputDir: string, theme: string) { + return { + ...DEFAULT_CONFIG, + dataDir, + outputDir, + theme, + clock: () => "2026-07-31T00:00:00.000Z", + }; +} + +afterEach(() => { + rmSync(TEST_DIR, { recursive: true, force: true }); + rmSync(DATA_A, { recursive: true, force: true }); + rmSync(DATA_B, { recursive: true, force: true }); + rmSync(OUTPUT_A, { recursive: true, force: true }); + rmSync(OUTPUT_B, { recursive: true, force: true }); +}); + +describe("theme registry", () => { + it("ships a default theme", () => { + const theme = resolveTheme(); + expect(theme.name).toBe("default"); + expect(theme.colorScheme).toBe("dark"); + }); + + it("exposes named themes", () => { + expect(isKnownTheme("light")).toBe(true); + expect(availableThemeNames()).toContain("light"); + }); + + it("rejects unknown theme names", () => { + expect(() => resolveTheme("neon")).toThrow(/Unknown theme "neon"/); + }); +}); + +describe("theme configuration", () => { + it("accepts a known theme name", () => { + mkdirSync(TEST_DIR, { recursive: true }); + writeFileSync(TEST_FILE, JSON.stringify({ theme: "light" })); + const config = loadPortfolioConfig(TEST_FILE, () => "2026-07-31T00:00:00.000Z"); + expect(config.theme).toBe("light"); + }); + + it("defaults to the default theme when omitted", () => { + mkdirSync(TEST_DIR, { recursive: true }); + writeFileSync(TEST_FILE, JSON.stringify({ owner: "owner" })); + const config = loadPortfolioConfig(TEST_FILE, () => "2026-07-31T00:00:00.000Z"); + expect(config.theme).toBe("default"); + }); + + it("rejects unknown theme names", () => { + mkdirSync(TEST_DIR, { recursive: true }); + writeFileSync(TEST_FILE, JSON.stringify({ theme: "neon" })); + expect(() => loadPortfolioConfig(TEST_FILE)).toThrow( + 'Configuration field "theme" must be one of' + ); + }); +}); + +describe("theme publishing", () => { + it("marks the page with the resolved theme", async () => { + const config = fixedConfig(DATA_A, OUTPUT_A, "light"); + await ingestOwnerRepos(config, config.owner, 2, loadAllFixtures()); + const result = publishSite(config); + const html = readFileSync(result.indexPath, "utf-8"); + expect(html).toContain('data-theme="light"'); + }); + + it("applies light color variables", async () => { + const config = fixedConfig(DATA_A, OUTPUT_A, "light"); + await ingestOwnerRepos(config, config.owner, 2, loadAllFixtures()); + publishSite(config); + const html = readFileSync(join(OUTPUT_A, "index.html"), "utf-8"); + expect(html).toContain("color-scheme: light;"); + expect(html).toContain("--ink: #f4f6fa;"); + }); + + it("keeps the default theme on the page by default", async () => { + const config = fixedConfig(DATA_A, OUTPUT_A, "default"); + await ingestOwnerRepos(config, config.owner, 2, loadAllFixtures()); + publishSite(config); + const html = readFileSync(join(OUTPUT_A, "index.html"), "utf-8"); + expect(html).toContain('data-theme="default"'); + }); + + it("publishes identical HTML across runs for the same theme", async () => { + const outputs = []; + const runs = [ + [DATA_A, OUTPUT_A], + [DATA_B, OUTPUT_B], + ]; + for (const [dataDir, outputDir] of runs) { + const config = fixedConfig(dataDir, outputDir, "light"); + await ingestOwnerRepos(config, config.owner, 2, loadAllFixtures()); + const result = publishSite(config); + outputs.push(readFileSync(result.indexPath, "utf-8")); + } + expect(outputs[0]).toBe(outputs[1]); + }); +}); + +describe("theme metadata", () => { + it("defines a label and description for each theme", () => { + for (const theme of Object.values(THEMES)) { + expect(theme.label.length).toBeGreaterThan(0); + expect(theme.description.length).toBeGreaterThan(0); + } + }); +});