From 38f23531fa1bee3342d858b7f59bd24fac79d902 Mon Sep 17 00:00:00 2001 From: DanieCuevas <43822444+DanielCuevas1208@users.noreply.github.com> Date: Mon, 3 Aug 2026 12:24:28 -0700 Subject: [PATCH] feat: extend engineer profile --- .github/workflows/ci.yml | 13 +- .github/workflows/refresh.yml | 2 +- .gitignore | 1 + .nvmrc | 2 +- CONTRIBUTING.md | 6 +- README.md | 104 ++++++-- engineer-profile.config.json | 4 + package-lock.json | 458 ++-------------------------------- package.json | 8 +- src/config/loader.ts | 41 ++- src/deploy/adapters.ts | 84 +++++++ src/deploy/run.ts | 30 +++ src/index.ts | 28 ++- src/publish/site.ts | 98 ++++---- src/refresh/run.ts | 10 +- src/theme/themes.ts | 123 +++++++++ src/types.ts | 17 ++ tests/config.test.ts | 40 +++ tests/deploy.test.ts | 115 +++++++++ tests/refresh.test.ts | 24 ++ tests/theme.test.ts | 117 +++++++++ 21 files changed, 802 insertions(+), 523 deletions(-) create mode 100644 src/deploy/adapters.ts create mode 100644 src/deploy/run.ts create mode 100644 src/theme/themes.ts create mode 100644 tests/deploy.test.ts create mode 100644 tests/theme.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eae27d9..ea60526 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 @@ -44,10 +44,21 @@ jobs: - name: Run fixture demo run: node dist/index.js demo + - name: Deploy demo output with the local adapter + run: node dist/index.js deploy --target deploy-site + - name: Store demo output if: success() uses: actions/upload-artifact@v4 with: name: engineer-profile-demo path: output/ + if-no-files-found: error + + - name: Store deployed site + if: success() + uses: actions/upload-artifact@v4 + with: + name: engineer-profile-deployed + path: deploy-site/ if-no-files-found: error \ No newline at end of file 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/.gitignore b/.gitignore index 6d63646..aef66ee 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ dist/ coverage/ data/ output/ +deploy-site/ *.db *.db-journal *.db-shm 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..e880995 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 @@ -14,9 +14,11 @@ npm test Use fixtures for changes that need repeatable data. Do not add credentials, private repository data, or generated output. +Keep changes to themes and deployment adapters under `src/theme/` and `src/deploy/`. +Add deterministic tests for new behavior in `tests/`. ## Pull requests Explain the user value and the data path. List the checks that you ran. -Keep public claims tied to repository evidence. \ No newline at end of file +Keep public claims tied to repository evidence. diff --git a/README.md b/README.md index f1a2a81..92b8231 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # EngineerProfile -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. +EngineerProfile turns repository activity into an engineering portfolio. +It reads public repository data and stores the facts in SQLite. +It publishes a static site from those records. ## Value @@ -10,6 +10,8 @@ paths in SQLite. It publishes a static site from these records. - Refresh project cards from public GitHub repositories. - Build release notes from releases or conventional commits. - Capture repeatable project previews with Playwright. +- Choose a visual theme for the published site. +- Deploy the site to a local target directory. - Hide projects and redact author emails before publication. - Run one configured refresh from a scheduled workflow. @@ -30,20 +32,24 @@ flowchart LR L --> W[Publisher] P --> W S --> W - W --> O[Static output] + W --> T[Theme] + T --> O[Static output] + O --> A[Deployment adapter] ``` | Area | Responsibility | | --- | --- | -| `engineer-profile.config.json` | Store owner, presentation, refresh, paths, and privacy settings. | +| `engineer-profile.config.json` | Store owner, theme, deployment, refresh, paths, and privacy settings. | | `src/config/` | Validate checked-in JSON and merge safe defaults. | -| `src/refresh/` | Coordinate ingest, best-effort capture, and static publishing. | +| `src/theme/` | Resolve named themes into CSS tokens. | +| `src/refresh/` | Coordinate ingest, capture, publishing, and deployment. | | `src/ingest/` | Fetch public GitHub data and map it to records. | | `src/db/` | Store projects, commits, changelogs, and audit events. | | `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/` | Render themed HTML, changelog files, and preview assets. | +| `src/deploy/` | Copy the published site to a configured target. | | `fixtures/` | Provide deterministic demo data and local preview pages. | The refresh command runs each stage in a fixed order. @@ -51,7 +57,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 @@ -68,7 +74,7 @@ Both directories are ignored by Git. ## Configuration `engineer-profile.config.json` is the checked-in source for scheduled refreshes. -It sets the GitHub owner, site presentation, repository limit, paths, and privacy controls. +It sets the GitHub owner, site presentation, theme, repository limit, paths, and privacy controls. The loader accepts repository limits from 1 through 100. It rejects malformed values before network access. @@ -94,6 +100,68 @@ npm run refresh Do not put a token in repository files. Use `.env.example` as a variable reference. +## Themes + +The `theme` field selects the visual style of the published site. +Set it to the name of a built-in theme. + +| Theme | Look | +| --- | --- | +| `aurora` | Dark blue palette. This is the default. | +| `terminal` | Monochrome green on black. | +| `paper` | Light background with dark ink text. | + +Example: + +```json +{ + "theme": "terminal" +} +``` + +The loader rejects unknown theme names. +Each theme defines the same set of color tokens. +The published page carries a `data-theme` attribute. + +## Deployment + +The `deploy` field selects how the published site reaches a target. +The default adapter is `none`, which does nothing. + +| Adapter | Behavior | +| --- | --- | +| `none` | No deployment. This is the default. | +| `local` | Copy the output directory to a target directory. | + +Example: + +```json +{ + "deploy": { + "adapter": "local", + "targetDir": "docs" + } +} +``` + +Run the deployment step on its own: + +```bash +npm run deploy +``` + +Deploy to a one-off target with a CLI option: + +```bash +node dist/index.js deploy --target public-site +``` + +The refresh command runs deployment after publishing when an adapter is configured. +The local adapter replaces the target contents before copying. +It refuses targets that overlap the output directory. +The deployment is recorded in the audit trail. +New adapters can extend the registry in `src/deploy/adapters.ts`. + ## Sample output The fixture set contains `signal-router` and `metrics-kit`. @@ -104,7 +172,7 @@ The second project uses commit-based notes. Ingested 2 fixture projects. Captured demo-engineer-signal-router. Captured demo-engineer-metrics-kit. -Published 2 projects to output/index.html. +Published 2 projects with the aurora theme to output\index.html. Copied 2 available preview screenshots. Open output/index.html in a browser. ``` @@ -123,7 +191,8 @@ Build before direct CLI commands. | `npm run ingest -- --fixture` | Load fixture records only. | | `npm run capture -- --fixture` | Capture local fixture pages. | | `npm run publish` | Rebuild the site from SQLite. | -| `npm run refresh` | Run configured ingest, capture, and publish stages. | +| `npm run deploy` | Deploy the published site. | +| `npm run refresh` | Run configured ingest, capture, publish, and deploy stages. | | `node dist/index.js status` | Show visibility and recent operations. | | `npm test` | Run deterministic unit and integration tests. | | `npm run typecheck` | Validate TypeScript types. | @@ -153,7 +222,7 @@ Each release keeps its tag, notes, date, and source URL. The site displays visible projects only. It links project cards to repositories. It links release notes to their release pages. -It records local operations in an audit table. +It records local operations, including deployments, in an audit table. ## CI and test status @@ -164,12 +233,14 @@ It uploads the generated site as a workflow artifact. The test suite covers these core behaviors: - Configuration validation and default merging. +- Theme resolution and token completeness. +- Deployment adapter behavior and audit logging. - Conventional commit parsing. - Release-first changelog generation. - SQLite upserts and changelog replacement. - Privacy filtering and email redaction. - Fixture ingestion and static publishing. -- Configured refresh orchestration. +- Configured refresh orchestration and deployment. - Release source links. - Deterministic HTML output. - Playwright screenshot capture. @@ -196,6 +267,8 @@ The fixture pipeline provides deterministic data for repeatable checks. - Changelog quality depends on releases or conventional commits. - External pages can fail during capture. - Capture failures are reported and do not stop publishing. +- The built-in themes are fixed. +- The local deployment adapter copies to a directory only. - Publishing creates local files. It does not deploy them. - Scheduled runs upload artifacts. They do not commit generated output. @@ -205,8 +278,9 @@ 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.4 | Later | Commit-diff summaries and an RSS feed. | +| v0.3 | Complete | Config-driven themes and a local deployment adapter. | +| v0.4 | Next | Commit-diff summaries and an RSS feed. | +| v0.5 | Later | Adapters for external hosts and per-project detail pages. | ## License diff --git a/engineer-profile.config.json b/engineer-profile.config.json index 81008fb..fe88591 100644 --- a/engineer-profile.config.json +++ b/engineer-profile.config.json @@ -5,6 +5,10 @@ "repositoryLimit": 5, "dataDir": "data", "outputDir": "output", + "theme": "aurora", + "deploy": { + "adapter": "none" + }, "privacy": { "hiddenProjects": [], "redactEmails": true, diff --git a/package-lock.json b/package-lock.json index 87f5d51..79af256 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.2.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" } }, "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..3195bd6 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "0.2.0", "description": "Self-maintaining engineering portfolio from repository activity", "type": "module", + "files": [ + "dist" + ], "main": "dist/index.js", "bin": { "engineer-profile": "dist/index.js" @@ -18,10 +21,11 @@ "ingest": "npm run build && node dist/index.js ingest", "publish": "npm run build && node dist/index.js publish", "capture": "npm run build && node dist/index.js capture", + "deploy": "npm run build && node dist/index.js deploy", "refresh": "npm run build && node dist/index.js refresh" }, "engines": { - "node": ">=20" + "node": ">=22" }, "keywords": [ "portfolio", @@ -40,7 +44,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..0271e6d 100644 --- a/src/config/loader.ts +++ b/src/config/loader.ts @@ -1,7 +1,9 @@ import { readFileSync } from "node:fs"; -import type { PortfolioConfig, PrivacyConfig } from "../types.js"; -import { DEFAULT_CONFIG, DEFAULT_PRIVACY } from "../types.js"; +import type { DeploymentConfig, PortfolioConfig, PrivacyConfig } from "../types.js"; +import { DEFAULT_CONFIG, DEFAULT_DEPLOY, DEFAULT_PRIVACY } from "../types.js"; import { mergePrivacy } from "../privacy/controls.js"; +import { isKnownAdapter, listAdapters } from "../deploy/adapters.js"; +import { isKnownTheme, listThemeNames } from "../theme/themes.js"; export const DEFAULT_CONFIG_PATH = "engineer-profile.config.json"; @@ -29,6 +31,39 @@ function readLimit(source: ConfigValue, key: string, fallback: number): number { return value; } +function readTheme(source: ConfigValue, fallback: string): string { + if (!("theme" in source)) return fallback; + const value = source.theme; + if (typeof value !== "string" || value.trim() === "") { + throw new Error('Configuration field "theme" must be a non-empty string.'); + } + const name = value.trim(); + if (!isKnownTheme(name)) { + throw new Error(`Configuration field "theme" must be one of: ${listThemeNames().join(", ")}.`); + } + return name; +} + +function readDeploy(source: ConfigValue): DeploymentConfig { + if (!("deploy" in source)) return DEFAULT_DEPLOY; + if (!isConfigValue(source.deploy)) { + throw new Error('Configuration field "deploy" must be an object.'); + } + + const { adapter, targetDir } = source.deploy; + if (typeof adapter !== "string" || !isKnownAdapter(adapter)) { + throw new Error(`Configuration field "deploy.adapter" must be one of: ${listAdapters().join(", ")}.`); + } + if (targetDir !== undefined && (typeof targetDir !== "string" || targetDir.trim() === "")) { + throw new Error('Configuration field "deploy.targetDir" must be a non-empty string.'); + } + + return { + adapter: adapter as DeploymentConfig["adapter"], + targetDir: targetDir === undefined ? undefined : targetDir.trim(), + }; +} + function readPrivacy(source: ConfigValue): PrivacyConfig { if (!("privacy" in source)) return DEFAULT_PRIVACY; if (!isConfigValue(source.privacy)) { @@ -78,6 +113,8 @@ 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, DEFAULT_CONFIG.theme), + deploy: readDeploy(parsed), privacy: readPrivacy(parsed), clock, }; diff --git a/src/deploy/adapters.ts b/src/deploy/adapters.ts new file mode 100644 index 0000000..28d0158 --- /dev/null +++ b/src/deploy/adapters.ts @@ -0,0 +1,84 @@ +import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs"; +import { isAbsolute, join, relative, resolve } from "node:path"; +import type { DeploymentConfig } from "../types.js"; + +export interface DeployResult { + adapter: string; + target: string | null; + filesCopied: number; +} + +export interface DeploymentAdapter { + readonly name: string; + deploy(sourceDir: string, config: DeploymentConfig): DeployResult; +} + +function countFiles(dir: string): number { + let count = 0; + for (const entry of readdirSync(dir, { withFileTypes: true })) { + const full = join(dir, entry.name); + count += entry.isDirectory() ? countFiles(full) : 1; + } + return count; +} + +function pathsOverlap(a: string, b: string): boolean { + const relativePath = relative(a, b); + return relativePath === "" || (!isAbsolute(relativePath) && !relativePath.startsWith("..")); +} + +const NONE_ADAPTER: DeploymentAdapter = { + name: "none", + deploy() { + return { adapter: "none", target: null, filesCopied: 0 }; + }, +}; + +const LOCAL_ADAPTER: DeploymentAdapter = { + name: "local", + deploy(sourceDir, config) { + const targetDir = config.targetDir?.trim(); + if (!targetDir) { + throw new Error('Local deployment requires a "deploy.targetDir" setting.'); + } + if (!existsSync(sourceDir)) { + throw new Error(`Nothing to deploy: output directory "${sourceDir}" does not exist.`); + } + + const sourceAbs = resolve(sourceDir); + const targetAbs = resolve(targetDir); + if (pathsOverlap(sourceAbs, targetAbs)) { + throw new Error( + `Deployment target "${targetDir}" must not overlap the output directory "${sourceDir}".` + ); + } + + mkdirSync(targetAbs, { recursive: true }); + rmSync(targetAbs, { recursive: true, force: true }); + mkdirSync(targetAbs, { recursive: true }); + cpSync(sourceAbs, targetAbs, { recursive: true }); + + return { adapter: "local", target: targetAbs, filesCopied: countFiles(targetAbs) }; + }, +}; + +const ADAPTERS: Record = { + none: NONE_ADAPTER, + local: LOCAL_ADAPTER, +}; + +export function isKnownAdapter(name: string): boolean { + return Object.prototype.hasOwnProperty.call(ADAPTERS, name); +} + +export function listAdapters(): string[] { + return Object.keys(ADAPTERS); +} + +export function resolveAdapter(name: string): DeploymentAdapter { + const adapter = ADAPTERS[name]; + if (!adapter) { + throw new Error(`Unknown deployment adapter "${name}". Available adapters: ${listAdapters().join(", ")}.`); + } + return adapter; +} diff --git a/src/deploy/run.ts b/src/deploy/run.ts new file mode 100644 index 0000000..5d6e0e2 --- /dev/null +++ b/src/deploy/run.ts @@ -0,0 +1,30 @@ +import { openDatabase } from "../db/client.js"; +import type { PortfolioConfig } from "../types.js"; +import { resolveAdapter, type DeployResult } from "./adapters.js"; + +export interface DeployOptions { + adapter?: string; + targetDir?: string; +} + +export function deployPortfolio(config: PortfolioConfig, options: DeployOptions = {}): DeployResult { + const adapterName = options.adapter ?? config.deploy.adapter; + const deployConfig = { + adapter: adapterName as PortfolioConfig["deploy"]["adapter"], + targetDir: options.targetDir ?? config.deploy.targetDir, + }; + const adapter = resolveAdapter(adapterName); + const result = adapter.deploy(config.outputDir, deployConfig); + + const db = openDatabase(config.dataDir, config.clock); + try { + const detail = result.target + ? `${result.adapter} adapter: ${result.filesCopied} files -> ${result.target}` + : `${result.adapter} adapter: no-op`; + db.logIngest("deploy", detail); + } finally { + db.close(); + } + + return result; +} diff --git a/src/index.ts b/src/index.ts index aea5c27..d29a72c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { Command } from "commander"; import { ingestOwnerRepos, ingestRepository } from "./ingest/orchestrator.js"; import { captureAllProjects, captureLocalHtml, closeBrowser } from "./preview/capture.js"; import { copyScreenshotsToOutput, publishSite } from "./publish/site.js"; +import { deployPortfolio } from "./deploy/run.js"; import { loadAllFixtures } from "./fixtures/loader.js"; import { openDatabase } from "./db/client.js"; import { DEFAULT_CONFIG, type PortfolioConfig } from "./types.js"; @@ -65,7 +66,7 @@ addConfigOption(program const result = publishSite(config); const copied = copyScreenshotsToOutput(config); - console.log(`Published ${result.projectCount} projects to ${result.indexPath}.`); + console.log(`Published ${result.projectCount} projects with the ${result.theme} theme to ${result.indexPath}.`); console.log(`Copied ${copied} available preview screenshots.`); console.log("Open output/index.html in a browser."); })); @@ -129,10 +130,26 @@ addConfigOption(program const config = resolveConfig(options); const result = publishSite(config); const copied = copyScreenshotsToOutput(config); - console.log(`Published ${result.projectCount} projects to ${result.indexPath}.`); + console.log(`Published ${result.projectCount} projects with the ${result.theme} theme to ${result.indexPath}.`); console.log(`Copied ${copied} available preview screenshots.`); })); +addConfigOption(program + .command("deploy") + .description("Copy the published site to a configured deployment target") + .option("-d, --data ", "Data directory") + .option("-o, --output ", "Output directory") + .option("-t, --target ", "Deployment target directory") + .action((options) => { + const config = resolveConfig(options); + const targetDir = options.target ?? config.deploy.targetDir; + const adapter = targetDir && config.deploy.adapter === "none" ? "local" : config.deploy.adapter; + const result = deployPortfolio(config, { adapter, targetDir }); + console.log( + `Deployed ${result.filesCopied} files with the ${result.adapter} adapter${result.target ? ` to ${result.target}` : ""}.` + ); + })); + addConfigOption(program .command("refresh") .description("Ingest, capture, and publish from the checked-in configuration") @@ -144,8 +161,13 @@ addConfigOption(program const result = await refreshPortfolio(config); console.log(`Ingested ${result.ingested} repositories for ${config.owner}.`); console.log(`Captured ${result.captured} project previews.`); - console.log(`Published ${result.published.projectCount} projects to ${result.published.indexPath}.`); + console.log(`Published ${result.published.projectCount} projects with the ${result.published.theme} theme to ${result.published.indexPath}.`); console.log(`Copied ${result.copiedScreenshots} available preview screenshots.`); + if (result.deployed) { + console.log( + `Deployed ${result.deployed.filesCopied} files with the ${result.deployed.adapter} adapter${result.deployed.target ? ` to ${result.deployed.target}` : ""}.` + ); + } for (const error of result.captureErrors) { console.warn(`Skipped ${error.slug}: ${error.message}`); } diff --git a/src/publish/site.ts b/src/publish/site.ts index d382163..9166f44 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 { cssVariables, resolveTheme, type Theme } from "../theme/themes.js"; import type { ChangelogEntry, PortfolioConfig, ProjectRecord } from "../types.js"; function escapeHtml(text: string): string { @@ -124,96 +125,85 @@ function projectCard( `; } -function siteCss(): string { +function siteCss(theme: Theme): string { 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); - font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; + color-scheme: var(--scheme); +${cssVariables(theme)} + font-family: var(--sans); } * { box-sizing: border-box; } html { scroll-behavior: smooth; } -body { margin: 0; min-width: 320px; background: var(--ink); color: var(--text); line-height: 1.5; } +body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); line-height: 1.5; } a { color: inherit; } -.site-shell { min-height: 100vh; background: radial-gradient(circle at 82% -10%, rgba(70, 148, 232, 0.2), transparent 34rem), var(--ink); } +.site-shell { min-height: 100vh; background: radial-gradient(circle at 82% -10%, var(--glow), transparent 34rem), var(--bg); } .container { width: min(1180px, calc(100% - 48px)); margin: 0 auto; } .site-nav { display: flex; justify-content: space-between; align-items: center; padding: 28px 0; border-bottom: 1px solid var(--line); } -.brand { display: inline-flex; align-items: center; gap: 12px; font: 700 0.9rem/1 "SFMono-Regular", Consolas, monospace; letter-spacing: 0.08em; text-decoration: none; text-transform: uppercase; } -.brand-mark { display: grid; width: 30px; height: 30px; place-items: center; border: 1px solid var(--blue); color: var(--blue); border-radius: 8px; font-size: 0.72rem; } -.nav-link { color: var(--muted); font: 0.76rem/1 "SFMono-Regular", Consolas, monospace; letter-spacing: 0.08em; text-decoration: none; text-transform: uppercase; } -.nav-link:hover, .text-link:hover, h2 a:hover { color: var(--blue); } +.brand { display: inline-flex; align-items: center; gap: 12px; font: 700 0.9rem/1 var(--mono); letter-spacing: 0.08em; text-decoration: none; text-transform: uppercase; } +.brand-mark { display: grid; width: 30px; height: 30px; place-items: center; border: 1px solid var(--accent); color: var(--accent); border-radius: 8px; font-size: 0.72rem; } +.nav-link { color: var(--muted); font: 0.76rem/1 var(--mono); letter-spacing: 0.08em; text-decoration: none; text-transform: uppercase; } +.nav-link:hover, .text-link:hover, h2 a:hover { color: var(--accent); } .hero { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(300px, 0.7fr); gap: 80px; align-items: end; padding: 86px 0 70px; } -.kicker, .eyebrow, .visual-label, .card-topline, .section-heading, .source-badge, .audit-label { font: 0.7rem/1.4 "SFMono-Regular", Consolas, monospace; letter-spacing: 0.12em; text-transform: uppercase; } -.kicker { color: var(--mint); margin: 0 0 22px; } +.kicker, .eyebrow, .visual-label, .card-topline, .section-heading, .source-badge, .audit-label { font: 0.7rem/1.4 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; } +.kicker { color: var(--accent-2); 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); } -.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-copy { max-width: 530px; margin: 28px 0 0; color: var(--accent-soft); font-size: 1.12rem; } +.hero-aside { padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(145deg, var(--panel-a), var(--panel-b)); box-shadow: var(--shadow); } +.aside-index { display: flex; justify-content: space-between; color: var(--accent-3); font: 0.68rem/1 var(--mono); 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); } .stat { min-height: 104px; padding: 20px 22px; border-right: 1px solid var(--line); } .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); } +.stat span { color: var(--muted); font: 0.7rem/1.3 var(--mono); 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: var(--panel-tint); } .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; } +.audit-time { color: var(--accent); font: 0.7rem/1.4 var(--mono); 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(--panel-a), var(--panel-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); } +.placeholder { display: flex; min-height: 310px; align-items: center; justify-content: center; flex-direction: column; gap: 7px; color: var(--accent); background: repeating-linear-gradient(135deg, var(--stripe), var(--stripe) 1px, transparent 1px, transparent 14px); } +.placeholder small { color: var(--muted); font: 0.68rem/1 var(--mono); 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(--accent-soft); } .project-body { padding: 30px 34px 32px; } -.card-topline { display: flex; justify-content: space-between; gap: 12px; color: var(--blue); } +.card-topline { display: flex; justify-content: space-between; gap: 12px; color: var(--accent); } .project-body h2 { margin: 18px 0 8px; font-size: 2.1rem; font-weight: 560; letter-spacing: -0.06em; } .project-body h2 a { text-decoration: none; } -.description { max-width: 620px; margin: 0; color: var(--blue-soft); font-size: 0.98rem; } -.facts { display: flex; flex-wrap: wrap; gap: 22px; margin: 24px 0 16px; color: var(--muted); font: 0.76rem/1 "SFMono-Regular", Consolas, monospace; } +.description { max-width: 620px; margin: 0; color: var(--accent-soft); font-size: 0.98rem; } +.facts { display: flex; flex-wrap: wrap; gap: 22px; margin: 24px 0 16px; color: var(--muted); font: 0.76rem/1 var(--mono); } .facts strong { color: var(--text); font-size: 1rem; font-weight: 600; } .tags { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 26px; } -.tag { padding: 5px 9px; border: 1px solid rgba(167, 243, 208, 0.26); border-radius: 999px; color: var(--mint); font: 0.68rem/1 "SFMono-Regular", Consolas, monospace; } +.tag { padding: 5px 9px; border: 1px solid var(--tag-line); border-radius: 999px; color: var(--accent-2); font: 0.68rem/1 var(--mono); } .change-log { padding: 18px 0 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); } -.section-heading { display: flex; justify-content: space-between; color: var(--orange); } +.section-heading { display: flex; justify-content: space-between; color: var(--accent-3); } .source-badge { color: var(--muted); } .change-log h3 { margin: 12px 0 2px; font-size: 1.08rem; font-weight: 550; } -.change-date { margin: 0 0 10px; color: var(--muted); font: 0.7rem/1.3 "SFMono-Regular", Consolas, monospace; } +.change-date { margin: 0 0 10px; color: var(--muted); font: 0.7rem/1.3 var(--mono); } .change-preview { max-height: 130px; overflow: hidden; color: var(--muted); font-size: 0.83rem; } .change-preview h3, .change-preview h4 { margin: 12px 0 4px; color: var(--text); font-size: 0.78rem; font-weight: 600; } .change-preview p { margin: 3px 0; } .change-preview li { margin: 3px 0 3px 18px; } -.change-preview code { padding: 2px 4px; border-radius: 3px; color: var(--mint); background: rgba(167, 243, 208, 0.08); font: 0.76rem "SFMono-Regular", Consolas, monospace; } -.text-link { display: inline-block; margin-top: 14px; color: var(--blue); font: 0.73rem/1 "SFMono-Regular", Consolas, monospace; text-decoration: none; text-transform: uppercase; } +.change-preview code { padding: 2px 4px; border-radius: 3px; color: var(--accent-2); background: var(--code-bg); font: 0.76rem var(--mono); } +.text-link { display: inline-block; margin-top: 14px; color: var(--accent); font: 0.73rem/1 var(--mono); text-decoration: none; text-transform: uppercase; } .card-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; } -.button { display: inline-block; padding: 10px 14px; border-radius: 7px; font: 0.72rem/1 "SFMono-Regular", Consolas, monospace; letter-spacing: 0.04em; text-decoration: none; text-transform: uppercase; } -.button.primary { background: var(--blue); color: var(--ink); } -.button.primary:hover { background: var(--blue-soft); } +.button { display: inline-block; padding: 10px 14px; border-radius: 7px; font: 0.72rem/1 var(--mono); letter-spacing: 0.04em; text-decoration: none; text-transform: uppercase; } +.button.primary { background: var(--accent); color: var(--bg); } +.button.primary:hover { filter: brightness(1.1); } .button.secondary { border: 1px solid var(--line); color: var(--text); } -.button.secondary:hover { border-color: var(--blue); color: var(--blue); } +.button.secondary:hover { border-color: var(--accent); color: var(--accent); } .muted { color: var(--muted); } .source-trail { display: grid; grid-template-columns: 0.8fr 1.2fr; gap: 36px; margin: 80px 0; padding: 26px 0; border-top: 1px solid var(--line); } .source-trail h2 { margin: 0 0 8px; font-size: 1.2rem; font-weight: 550; } .source-trail p { margin: 0; color: var(--muted); font-size: 0.86rem; } .audit-list { margin: 0; padding: 0; list-style: none; } -.audit-list li { display: grid; grid-template-columns: 150px 72px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid rgba(169, 195, 222, 0.1); color: var(--muted); font: 0.72rem/1.4 "SFMono-Regular", Consolas, monospace; } -.audit-list time { color: var(--blue); } -.audit-list strong { color: var(--orange); font-weight: 500; text-transform: uppercase; } -.site-footer { display: flex; justify-content: space-between; gap: 20px; padding: 24px 0 40px; border-top: 1px solid var(--line); color: var(--muted); font: 0.7rem/1.4 "SFMono-Regular", Consolas, monospace; } +.audit-list li { display: grid; grid-template-columns: 150px 72px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); color: var(--muted); font: 0.72rem/1.4 var(--mono); } +.audit-list time { color: var(--accent); } +.audit-list strong { color: var(--accent-3); font-weight: 500; text-transform: uppercase; } +.site-footer { display: flex; justify-content: space-between; gap: 20px; padding: 24px 0 40px; border-top: 1px solid var(--line); color: var(--muted); font: 0.7rem/1.4 var(--mono); } .site-footer p { margin: 0; } @media (max-width: 850px) { .hero { grid-template-columns: 1fr; gap: 34px; padding-top: 58px; } @@ -243,11 +233,13 @@ export interface PublishResult { indexPath: string; projectCount: number; generatedAt: string; + theme: string; } 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 +264,14 @@ export function publishSite(config: PortfolioConfig): PublishResult { : ""; const html = ` - + ${escapeHtml(config.title)} / Portfolio - +
@@ -345,7 +337,7 @@ export function publishSite(config: PortfolioConfig): PublishResult { } db.logIngest("publish", `${projects.length} projects -> ${indexPath}`); - return { indexPath, projectCount: projects.length, generatedAt }; + return { indexPath, projectCount: projects.length, generatedAt, theme: theme.name }; } finally { db.close(); } diff --git a/src/refresh/run.ts b/src/refresh/run.ts index acc9e53..5d8aac5 100644 --- a/src/refresh/run.ts +++ b/src/refresh/run.ts @@ -1,6 +1,8 @@ import { ingestOwnerRepos } from "../ingest/orchestrator.js"; import { captureAllProjects } from "../preview/capture.js"; import { copyScreenshotsToOutput, publishSite, type PublishResult } from "../publish/site.js"; +import { deployPortfolio } from "../deploy/run.js"; +import type { DeployResult } from "../deploy/adapters.js"; import type { FixtureData } from "../ingest/orchestrator.js"; import { DEFAULT_CONFIG, type PortfolioConfig } from "../types.js"; @@ -15,6 +17,7 @@ export interface RefreshResult { copiedScreenshots: number; captureErrors: Array<{ slug: string; message: string }>; published: PublishResult; + deployed: DeployResult | null; } export async function refreshPortfolio( @@ -36,12 +39,17 @@ export async function refreshPortfolio( (slug, error) => captureErrors.push({ slug, message: error.message }) ); const published = publishSite(config); + const copiedScreenshots = copyScreenshotsToOutput(config); + const deployed = config.deploy.adapter === "none" + ? null + : deployPortfolio(config); return { ingested: ingested.length, captured: captured.length, - copiedScreenshots: copyScreenshotsToOutput(config), + copiedScreenshots, captureErrors, published, + deployed, }; } diff --git a/src/theme/themes.ts b/src/theme/themes.ts new file mode 100644 index 0000000..2ccdd82 --- /dev/null +++ b/src/theme/themes.ts @@ -0,0 +1,123 @@ +export interface Theme { + name: string; + label: string; + description: string; + scheme: "dark" | "light"; + variables: Record; +} + +const SANS = + "Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif"; +const MONO = "\"SFMono-Regular\", Consolas, monospace"; + +export const THEMES: Record = { + aurora: { + name: "aurora", + label: "Aurora", + description: "Dark blue palette with teal and amber accents. This is the default theme.", + scheme: "dark", + variables: { + scheme: "dark", + bg: "#08111f", + "panel-tint": "rgba(17, 33, 57, 0.66)", + "panel-a": "rgba(23, 42, 70, 0.98)", + "panel-b": "rgba(13, 26, 45, 0.96)", + line: "rgba(169, 195, 222, 0.18)", + "line-soft": "rgba(169, 195, 222, 0.1)", + text: "#f3f7fb", + muted: "#9db0c7", + accent: "#67b7ff", + "accent-soft": "#b8dcff", + "accent-2": "#a7f3d0", + "accent-3": "#ffb86b", + glow: "rgba(70, 148, 232, 0.2)", + shadow: "0 24px 60px rgba(0, 0, 0, 0.24)", + "visual-bg": "#0a1525", + stripe: "rgba(103, 183, 255, 0.05)", + "tag-line": "rgba(167, 243, 208, 0.26)", + "code-bg": "rgba(167, 243, 208, 0.08)", + sans: SANS, + mono: MONO, + }, + }, + terminal: { + name: "terminal", + label: "Terminal", + description: "Monochrome green on black. Built for low-light reading.", + scheme: "dark", + variables: { + scheme: "dark", + bg: "#050b06", + "panel-tint": "rgba(16, 34, 21, 0.66)", + "panel-a": "rgba(14, 28, 18, 0.98)", + "panel-b": "rgba(6, 14, 9, 0.96)", + line: "rgba(130, 255, 165, 0.18)", + "line-soft": "rgba(130, 255, 165, 0.1)", + text: "#eafff0", + muted: "#8bb39a", + accent: "#66ff8c", + "accent-soft": "#c5ffd4", + "accent-2": "#66ff8c", + "accent-3": "#ffe9a8", + glow: "rgba(102, 255, 140, 0.14)", + shadow: "0 24px 60px rgba(0, 0, 0, 0.6)", + "visual-bg": "#021004", + stripe: "rgba(102, 255, 140, 0.05)", + "tag-line": "rgba(130, 255, 165, 0.26)", + "code-bg": "rgba(130, 255, 165, 0.08)", + sans: SANS, + mono: MONO, + }, + }, + paper: { + name: "paper", + label: "Paper", + description: "Light theme with a paper background and dark ink text.", + scheme: "light", + variables: { + scheme: "light", + bg: "#f6f8fb", + "panel-tint": "rgba(255, 255, 255, 0.72)", + "panel-a": "#ffffff", + "panel-b": "#e9eef5", + line: "rgba(20, 40, 70, 0.12)", + "line-soft": "rgba(20, 40, 70, 0.08)", + text: "#14243a", + muted: "#5a6c82", + accent: "#1d4ed8", + "accent-soft": "#1e3a8a", + "accent-2": "#047857", + "accent-3": "#b45309", + glow: "rgba(29, 78, 216, 0.1)", + shadow: "0 24px 60px rgba(20, 32, 46, 0.14)", + "visual-bg": "#0f1b2e", + stripe: "rgba(29, 78, 216, 0.06)", + "tag-line": "rgba(4, 120, 87, 0.24)", + "code-bg": "rgba(4, 120, 87, 0.08)", + sans: SANS, + mono: MONO, + }, + }, +}; + +export function isKnownTheme(name: string): boolean { + return Object.prototype.hasOwnProperty.call(THEMES, name); +} + +export function listThemeNames(): string[] { + return Object.keys(THEMES); +} + +export function resolveTheme(name: string): Theme { + const theme = THEMES[name]; + if (!theme) { + throw new Error(`Unknown theme "${name}". Available themes: ${listThemeNames().join(", ")}.`); + } + return theme; +} + +export function cssVariables(theme: Theme): string { + return Object.entries(theme.variables) + .map(([key, value]) => ` --${key}: ${value};`) + .join("\n"); +} diff --git a/src/types.ts b/src/types.ts index 92c30da..1f44c86 100644 --- a/src/types.ts +++ b/src/types.ts @@ -78,6 +78,13 @@ export interface PrivacyConfig { maxCommitsPerProject: number; } +export type DeployAdapterName = "none" | "local"; + +export interface DeploymentConfig { + adapter: DeployAdapterName; + targetDir?: string; +} + export interface PortfolioConfig { owner: string; title: string; @@ -85,6 +92,8 @@ export interface PortfolioConfig { repositoryLimit?: number; dataDir: string; outputDir: string; + theme: string; + deploy: DeploymentConfig; privacy: PrivacyConfig; clock: () => string; } @@ -95,6 +104,12 @@ export const DEFAULT_PRIVACY: PrivacyConfig = { maxCommitsPerProject: 50, }; +export const DEFAULT_THEME = "aurora"; + +export const DEFAULT_DEPLOY: DeploymentConfig = { + adapter: "none", +}; + export const DEFAULT_CONFIG = { owner: "demo-engineer", title: "EngineerProfile", @@ -102,6 +117,8 @@ export const DEFAULT_CONFIG = { repositoryLimit: 5, dataDir: "data", outputDir: "output", + theme: DEFAULT_THEME, + deploy: DEFAULT_DEPLOY, privacy: DEFAULT_PRIVACY, clock: () => new Date().toISOString(), } satisfies PortfolioConfig; diff --git a/tests/config.test.ts b/tests/config.test.ts index 44e2720..5697dca 100644 --- a/tests/config.test.ts +++ b/tests/config.test.ts @@ -37,4 +37,44 @@ describe("portfolio configuration", () => { 'Configuration field "repositoryLimit" must be an integer from 1 to 100.' ); }); + + it("applies the default theme and deployment adapter", () => { + 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("aurora"); + expect(config.deploy.adapter).toBe("none"); + }); + + it("loads a configured theme and local deployment adapter", () => { + mkdirSync(TEST_DIR, { recursive: true }); + writeFileSync(TEST_FILE, JSON.stringify({ + theme: "terminal", + deploy: { adapter: "local", targetDir: "docs" }, + })); + + const config = loadPortfolioConfig(TEST_FILE, () => "2026-07-31T00:00:00.000Z"); + expect(config.theme).toBe("terminal"); + expect(config.deploy.adapter).toBe("local"); + expect(config.deploy.targetDir).toBe("docs"); + }); + + it("rejects an unknown theme", () => { + mkdirSync(TEST_DIR, { recursive: true }); + writeFileSync(TEST_FILE, JSON.stringify({ theme: "neon" })); + + expect(() => loadPortfolioConfig(TEST_FILE)).toThrow( + 'Configuration field "theme" must be one of' + ); + }); + + it("rejects an unknown deployment adapter", () => { + mkdirSync(TEST_DIR, { recursive: true }); + writeFileSync(TEST_FILE, JSON.stringify({ deploy: { adapter: "surge" } })); + + expect(() => loadPortfolioConfig(TEST_FILE)).toThrow( + 'Configuration field "deploy.adapter" must be one of' + ); + }); }); diff --git a/tests/deploy.test.ts b/tests/deploy.test.ts new file mode 100644 index 0000000..ecc7e8e --- /dev/null +++ b/tests/deploy.test.ts @@ -0,0 +1,115 @@ +import { describe, expect, it, afterEach } from "vitest"; +import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { deployPortfolio } from "../src/deploy/run.js"; +import { listAdapters, resolveAdapter } from "../src/deploy/adapters.js"; +import { openDatabase } from "../src/db/client.js"; +import { DEFAULT_CONFIG } from "../src/types.js"; + +const TEST_DATA = "data/test-deploy"; +const TEST_OUTPUT = "output/test-deploy"; +const TEST_TARGET = "output/test-deploy-target"; + +function configFor(overrides: Partial = {}) { + return { + ...DEFAULT_CONFIG, + dataDir: TEST_DATA, + outputDir: TEST_OUTPUT, + clock: () => "2026-01-01T00:00:00.000Z", + ...overrides, + }; +} + +afterEach(() => { + for (const path of [TEST_DATA, TEST_OUTPUT, TEST_TARGET]) { + rmSync(path, { recursive: true, force: true }); + } +}); + +describe("deployment adapters", () => { + it("lists the built-in adapters", () => { + expect(listAdapters()).toEqual(["none", "local"]); + }); + + it("resolves known adapter names", () => { + expect(resolveAdapter("local").name).toBe("local"); + expect(resolveAdapter("none").name).toBe("none"); + }); + + it("rejects unknown adapter names", () => { + expect(() => resolveAdapter("surge")).toThrow(/Unknown deployment adapter/); + }); + + it("does nothing with the none adapter", () => { + const result = deployPortfolio(configFor()); + expect(result.adapter).toBe("none"); + expect(result.target).toBeNull(); + expect(result.filesCopied).toBe(0); + }); + + it("mirrors the output directory with the local adapter", () => { + mkdirSync(join(TEST_OUTPUT, "assets", "screenshots"), { recursive: true }); + writeFileSync(join(TEST_OUTPUT, "index.html"), "site"); + writeFileSync(join(TEST_OUTPUT, "assets", "screenshots", "a.png"), "png"); + + const result = deployPortfolio(configFor({ deploy: { adapter: "local", targetDir: TEST_TARGET } })); + + expect(result.adapter).toBe("local"); + expect(result.filesCopied).toBe(2); + expect(existsSync(join(TEST_TARGET, "index.html"))).toBe(true); + expect(readFileSync(join(TEST_TARGET, "index.html"), "utf-8")).toBe("site"); + expect(existsSync(join(TEST_TARGET, "assets", "screenshots", "a.png"))).toBe(true); + }); + + it("replaces the previous target contents", () => { + mkdirSync(TEST_TARGET, { recursive: true }); + writeFileSync(join(TEST_TARGET, "stale.txt"), "old"); + mkdirSync(TEST_OUTPUT, { recursive: true }); + writeFileSync(join(TEST_OUTPUT, "index.html"), "fresh"); + + deployPortfolio(configFor({ deploy: { adapter: "local", targetDir: TEST_TARGET } })); + + expect(existsSync(join(TEST_TARGET, "stale.txt"))).toBe(false); + expect(existsSync(join(TEST_TARGET, "index.html"))).toBe(true); + }); + + it("records the deployment in the audit trail", () => { + mkdirSync(TEST_OUTPUT, { recursive: true }); + writeFileSync(join(TEST_OUTPUT, "index.html"), "site"); + deployPortfolio(configFor({ deploy: { adapter: "local", targetDir: TEST_TARGET } })); + + const db = openDatabase(TEST_DATA, () => "2026-01-01T00:00:00.000Z"); + const log = db.getIngestLog(5); + db.close(); + expect(log.some((entry) => entry.action === "deploy")).toBe(true); + }); + + it("requires a target directory for the local adapter", () => { + mkdirSync(TEST_OUTPUT, { recursive: true }); + expect(() => + deployPortfolio(configFor({ deploy: { adapter: "local" } })) + ).toThrow(/targetDir/); + }); + + it("rejects a target that overlaps the output directory", () => { + mkdirSync(TEST_OUTPUT, { recursive: true }); + expect(() => + deployPortfolio(configFor({ deploy: { adapter: "local", targetDir: TEST_OUTPUT } })) + ).toThrow(/must not overlap/); + }); + + it("rejects a target nested inside the output directory", () => { + mkdirSync(TEST_OUTPUT, { recursive: true }); + expect(() => + deployPortfolio(configFor({ deploy: { adapter: "local", targetDir: join(TEST_OUTPUT, "nested") } })) + ).toThrow(/must not overlap/); + }); + + it("supports a one-off target override with the none adapter", () => { + mkdirSync(TEST_OUTPUT, { recursive: true }); + writeFileSync(join(TEST_OUTPUT, "index.html"), "site"); + const result = deployPortfolio(configFor(), { adapter: "local", targetDir: TEST_TARGET }); + expect(result.adapter).toBe("local"); + expect(existsSync(join(TEST_TARGET, "index.html"))).toBe(true); + }); +}); diff --git a/tests/refresh.test.ts b/tests/refresh.test.ts index d119d9b..b9978f0 100644 --- a/tests/refresh.test.ts +++ b/tests/refresh.test.ts @@ -7,10 +7,12 @@ import { DEFAULT_CONFIG } from "../src/types.js"; const TEST_DATA = join("data", "test-refresh"); const TEST_OUTPUT = join("output", "test-refresh"); +const TEST_TARGET = join("output", "test-refresh-target"); afterEach(() => { rmSync(TEST_DATA, { recursive: true, force: true }); rmSync(TEST_OUTPUT, { recursive: true, force: true }); + rmSync(TEST_TARGET, { recursive: true, force: true }); }); describe("configured refresh", () => { @@ -32,7 +34,29 @@ describe("configured refresh", () => { expect(result.captured).toBe(0); expect(result.captureErrors).toEqual([]); expect(result.published.projectCount).toBe(2); + expect(result.published.theme).toBe("aurora"); + expect(result.deployed).toBeNull(); expect(result.copiedScreenshots).toBe(0); expect(existsSync(join(TEST_OUTPUT, "index.html"))).toBe(true); }); + + it("deploys after publishing when an adapter is configured", async () => { + const config = { + ...DEFAULT_CONFIG, + dataDir: TEST_DATA, + outputDir: TEST_OUTPUT, + repositoryLimit: 2, + deploy: { adapter: "local", targetDir: TEST_TARGET }, + clock: () => "2026-07-31T00:00:00.000Z", + }; + + const result = await refreshPortfolio(config, { + fixtureRepos: loadAllFixtures(), + capture: false, + }); + + expect(result.deployed).not.toBeNull(); + expect(result.deployed!.adapter).toBe("local"); + expect(existsSync(join(TEST_TARGET, "index.html"))).toBe(true); + }); }); diff --git a/tests/theme.test.ts b/tests/theme.test.ts new file mode 100644 index 0000000..8fa0d9e --- /dev/null +++ b/tests/theme.test.ts @@ -0,0 +1,117 @@ +import { describe, expect, it, afterEach } from "vitest"; +import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { ingestOwnerRepos } from "../src/ingest/orchestrator.js"; +import { publishSite } from "../src/publish/site.js"; +import { loadAllFixtures } from "../src/fixtures/loader.js"; +import { loadPortfolioConfig } from "../src/config/loader.js"; +import { resolveTheme, isKnownTheme, listThemeNames } from "../src/theme/themes.js"; +import { DEFAULT_CONFIG } from "../src/types.js"; + +const TEST_DATA = "data/test-theme"; +const TEST_OUTPUT = "output/test-theme"; + +afterEach(() => { + rmSync(TEST_DATA, { recursive: true, force: true }); + rmSync(TEST_OUTPUT, { recursive: true, force: true }); +}); + +describe("theme registry", () => { + it("resolves the default theme by name", () => { + expect(resolveTheme("aurora").name).toBe("aurora"); + }); + + it("recognizes every built-in theme name", () => { + for (const name of listThemeNames()) { + expect(isKnownTheme(name)).toBe(true); + } + }); + + it("rejects unknown theme names", () => { + expect(() => resolveTheme("neon")).toThrow(/Unknown theme/); + }); + + it("defines the same color tokens for every theme", () => { + const required = [ + "scheme", + "bg", + "panel-tint", + "panel-a", + "panel-b", + "line", + "line-soft", + "text", + "muted", + "accent", + "accent-soft", + "accent-2", + "accent-3", + "glow", + "shadow", + "visual-bg", + "stripe", + "tag-line", + "code-bg", + "sans", + "mono", + ]; + for (const name of listThemeNames()) { + const theme = resolveTheme(name); + for (const token of required) { + expect(theme.variables[token], `${name} defines ${token}`).toBeDefined(); + } + } + }); +}); + +describe("theme configuration", () => { + it("loads a valid theme from the configuration file", () => { + const dir = "data/test-theme-config"; + mkdirSync(dir, { recursive: true }); + const file = join(dir, "portfolio.json"); + writeFileSync(file, JSON.stringify({ theme: "terminal" })); + + const config = loadPortfolioConfig(file, () => "2026-01-01T00:00:00.000Z"); + expect(config.theme).toBe("terminal"); + rmSync(dir, { recursive: true, force: true }); + }); + + it("rejects an unknown theme in the configuration file", () => { + const dir = "data/test-theme-config-bad"; + mkdirSync(dir, { recursive: true }); + const file = join(dir, "portfolio.json"); + writeFileSync(file, JSON.stringify({ theme: "neon" })); + + expect(() => loadPortfolioConfig(file)).toThrow(/must be one of/); + rmSync(dir, { recursive: true, force: true }); + }); +}); + +describe("theme publishing", () => { + async function publishWith(theme?: string) { + const config = { + ...DEFAULT_CONFIG, + dataDir: TEST_DATA, + outputDir: TEST_OUTPUT, + theme: theme ?? DEFAULT_CONFIG.theme, + clock: () => "2026-01-01T00:00:00.000Z", + }; + await ingestOwnerRepos(config, config.owner, 2, loadAllFixtures()); + return publishSite(config); + } + + it("publishes the default theme when none is configured", async () => { + const result = await publishWith(); + expect(result.theme).toBe("aurora"); + const html = readFileSync(result.indexPath, "utf-8"); + expect(html).toContain('data-theme="aurora"'); + }); + + it("publishes the configured theme", async () => { + const result = await publishWith("terminal"); + expect(result.theme).toBe("terminal"); + const html = readFileSync(result.indexPath, "utf-8"); + expect(html).toContain('data-theme="terminal"'); + expect(html).toContain("--accent: #66ff8c;"); + }); +});