Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ jobs:
- name: Install dependencies
run: npm ci

# The store hero render tests need devkit-store-hero's pinned fonts (about 27 MB); without
# them they skip. The key changes whenever the pinned list does.
- name: Cache the store hero fonts
uses: actions/cache@v6
with:
path: ~/.cache/devkit/fonts
key: devkit-fonts-${{ hashFiles('src/store-hero/fonts.mjs') }}

- name: Fetch the store hero fonts
run: node bin/devkit-store-hero.mjs --fetch-fonts

- name: Validate
run: npm run validate

Expand Down
36 changes: 19 additions & 17 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ This repo follows the shared standards at https://github.com/Dynamic-Solutions-C

devkit owns a hostname, port and database per checkout and worktree, the routing proxy, `devkit.config.mjs`, the `devkit` and `devproxy` commands, and development data snapshots. It does not own production deployment, CI, or an app's own dev processes; it may supply templates that are written into an app, but it is never a runtime or production dependency of one.

| Area | Files |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| Command-line entry points | `bin/devkit.mjs`, `bin/devproxy.mjs` |
| Public API (`.` and `./identity` exports) | `src/index.mjs`, `src/checkout-identity.mjs` |
| Checkout lifecycle: prepare, install, run, Compose, cleanup | `src/checkout-*.mjs`, `src/background-runner.mjs` |
| Project config and pinned Node runtime | `src/project-config.mjs`, `src/project-runtime.mjs`, `src/config.mjs` |
| Proxy, host routing and remote preflight | `src/proxy.mjs`, `src/host-routing.mjs`, `src/host-setup.mjs`, `src/preflight.mjs` |
| Databases and baselines | `src/database*.mjs`, `src/data-baseline.mjs` |
| Dependencies on other checkouts | `src/project-dependencies.mjs`, `src/dependency-targets.mjs` |
| Compose definitions installed by bootstrap | `infra/` |
| Test discovery for apps (`devkit-test`) | `src/test-runner.mjs`, `bin/devkit-test.mjs` |
| Generated dev and deploy files for apps (`devkit-init`) | `src/app-templates.mjs`, `templates/`, `bin/devkit-init.mjs` |
| Database wait and Vite server helpers for apps | `src/database-wait.mjs`, `bin/devkit-wait-for-db.mjs`, `src/vite.mjs` (the `./vite` export) |
| Icon generator for apps (`devkit-icons`) | `src/icons/`, `bin/devkit-icons.mjs` |
| Pre-commit check for apps (`devkit-precommit`) | `src/precommit.mjs`, `bin/devkit-precommit.mjs` |
| Third-party notices for apps (`devkit-notices`) | `src/notices/`, `bin/devkit-notices.mjs` |
| VS Code browser bridge | `vscode-extension/`, built by `scripts/build-browser-extension.mjs` |
| Area | Files |
| ----------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| Command-line entry points | `bin/devkit.mjs`, `bin/devproxy.mjs` |
| Public API (`.` and `./identity` exports) | `src/index.mjs`, `src/checkout-identity.mjs` |
| Checkout lifecycle: prepare, install, run, Compose, cleanup | `src/checkout-*.mjs`, `src/background-runner.mjs` |
| Project config and pinned Node runtime | `src/project-config.mjs`, `src/project-runtime.mjs`, `src/config.mjs` |
| Proxy, host routing and remote preflight | `src/proxy.mjs`, `src/host-routing.mjs`, `src/host-setup.mjs`, `src/preflight.mjs` |
| Databases and baselines | `src/database*.mjs`, `src/data-baseline.mjs` |
| Dependencies on other checkouts | `src/project-dependencies.mjs`, `src/dependency-targets.mjs` |
| Compose definitions installed by bootstrap | `infra/` |
| Test discovery for apps (`devkit-test`) | `src/test-runner.mjs`, `bin/devkit-test.mjs` |
| Generated dev and deploy files for apps (`devkit-init`) | `src/app-templates.mjs`, `templates/`, `bin/devkit-init.mjs` |
| Database wait and Vite server helpers for apps | `src/database-wait.mjs`, `bin/devkit-wait-for-db.mjs`, `src/vite.mjs` (the `./vite` export) |
| Icon generator for apps (`devkit-icons`) | `src/icons/`, `bin/devkit-icons.mjs` |
| Pre-commit check for apps (`devkit-precommit`) | `src/precommit.mjs`, `bin/devkit-precommit.mjs` |
| Third-party notices for apps (`devkit-notices`) | `src/notices/`, `bin/devkit-notices.mjs` |
| First Store screenshot for apps (`devkit-store-hero`) | `src/store-hero/`, `bin/devkit-store-hero.mjs`, `src/resvg.mjs`, `docs/examples/store-hero/` |
| VS Code browser bridge | `vscode-extension/`, built by `scripts/build-browser-extension.mjs` |

## Conventions and gotchas

Expand All @@ -37,6 +38,7 @@ devkit owns a hostname, port and database per checkout and worktree, the routing
- `engines.node` is a range, not an exact pin, so apps still on an older Node line can install devkit with `engine-strict=true`. devkit itself is developed and tested on the version in `.nvmrc`.
- `templates/run-dev.mjs`, `templates/deploy-over-ssh.mjs` and `templates/generated-file-guard.mjs` are copied verbatim into every app and checked there by `devkit-init --check`, so any change to them, even whitespace, makes every app regenerate on its next pin bump. Change it only for a reason apps need, and say so in the release notes.
- `templates/deploy-over-ssh.mjs` runs during a deploy, so it must never import devkit (D-045). Its tests run the server script against fake `git` and `docker`, never a real server.
- `devkit-store-hero` draws with fonts pinned by SHA-256 in `src/store-hero/fonts.mjs` and downloaded on first use, never committed or shipped. Changing a font, a layout constant in `src/store-hero/layouts.mjs` or `draw.mjs`, or the resvg pin changes every app's heroes: say so in the release notes, and re-render `docs/examples/store-hero/` (its test fails until you do).
- `src/vite.mjs` is loaded by apps' `vite.config` during production builds, so it must stay import-free and side-effect free.
- Tests that need a private key build its PEM marker at run time, so no tracked file holds one for a scanner, or `devkit-precommit`, to refuse.
- The README is the canonical usage doc that apps link to; change behaviour and its README section together.
Expand Down
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,57 @@ Linux x64 is the canonical platform. Packages that exist for one platform only,

Commit the files and check them in `validate`, or generate them in the build instead (`"build": "devkit-notices && vite build"`) and git-ignore them. A Docker build that runs it needs `devkit.config.mjs` copied in and devkit installed, which `npm ci` does when dev dependencies are installed. Hand-written credits for software that is not an npm package stay in the app.

### Store heroes

`devkit-store-hero` draws a listing's first Store screenshot, the only one Store search shows, as a generated hero in every listing locale, and `devkit-store-hero --check` (for `validate`) fails when a committed hero no longer matches its inputs. It has two layouts:

| Layout | What it shows | For |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------- |
| `split` | a brand-colour panel with the icon, name, accent bar, headline and optional subline on the left; the app's real window or flyout, whole and enlarged, on the right | apps whose main surface is a flyout or popup |
| `brand-card` | icon, name, accent bar, headline and subline over a brand gradient, with the app's window faded in behind on the right when a capture is given | apps whose UI is setup that users rarely see again |

| `split` (`ja-JP`) | `brand-card` (`en-US`) |
| ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| ![Split hero](docs/examples/store-hero/split/store-assets/microsoft/screenshots/ja-JP/00-hero-dark.png) | ![Brand card hero](docs/examples/store-hero/brand-card/store-assets/microsoft/screenshots/en-US/00-hero-dark.png) |

The hero is the first entry of a store's list in `store-assets/manifest.json`, with a `hero` block:

```json
{
"size": "1366x768",
"microsoft": [
{
"file": "screenshots/{locale}/00-hero-dark.png",
"source": "raw/microsoft/00-flyout-dark.png",
"theme": "dark",
"hero": {
"layout": "split",
"icon": "assets/generated/icon-256.png",
"primary": "#2563EB",
"accent": "#10B981"
},
"caption": "...",
"alt": "..."
}
]
}
```

- `file` is under `store-assets/<store>/`, like every other entry, and must contain `{locale}`: each locale gets its own image.
- `source` is the raw capture under `store-assets/`, with the capture helper's `<name>.json` sidecar beside it. The hero shows the whole window the sidecar records, never part of it. `hero.crop` (`[x, y, width, height]` in capture pixels) may widen that region, and is refused if it would cut the window. The one exception is a tall flyout in the `split` layout: with `"fade": "bottom"` beside it, `hero.crop` may cut the window's bottom edge (its top and sides stay whole), and the hero fades the UI out toward the cut so it clearly continues. Every other cut is still refused, and `fade` without a crop that really cuts the bottom fails. A capture taken at 200% display scale (sidecar `"scale": 200`) is drawn at its logical size and looks sharper; a plain run says when a 100% capture is enlarged enough to look soft. `split` needs a capture; for `brand-card` it is optional.
- `hero.icon` is repo-relative, a `.png` or `.svg`. `primary` and `accent` are `#RRGGBB`: the panel or gradient is drawn from `primary`, the accent bar runs from `primary` to `accent`.
- The output size is the manifest's `size` (1366 x 768 by default, up to 3840 x 2160, about 16:9), so the hero matches the listing's other screenshots. The PNG is 8-bit RGB without alpha, with unfiltered rows, the format winui-app-kit's screenshot renderer writes.

The text comes from the same store's `listings.json`. Every locale with its own record needs `heroHeadline`, and the command names every locale that lacks one before drawing anything. `heroSubline` is required for `brand-card`, and for `split` is set in every locale or none. A `copyFrom` locale reuses its target's image and needs neither. The app name is the locale's `title`. A `\n` in either field forces a line break; otherwise lines are broken at word boundaries (Japanese and Chinese words too) and balanced. The headline starts large and shrinks in steps until it fits above the bottom third of the image, which Microsoft reserves for overlays; if it still does not fit at the smallest size that reads on a 320 x 180 search card, the command fails and names the locale, so shorten it there.

Text is drawn in Noto Sans, and in Noto Sans CJK JP or SC for Japanese and Simplified Chinese (whose shared characters differ by region), because Segoe UI ships only with Windows and is absent from Linux, CI and containers. Other Chinese scripts and Korean fail until a font is pinned for them. The fonts (about 27 MB, SIL Open Font License) are downloaded from the upstream Noto repositories on first use, checked against pinned SHA-256 hashes, and kept in `~/.cache/devkit/fonts` (`%LOCALAPPDATA%\devkit\fonts` on Windows). Set `DEVKIT_FONTS_DIR` to use another folder, such as a CI cache, and run `devkit-store-hero --fetch-fonts` to fill it without drawing anything. System fonts are never used, so a machine's installed fonts cannot change a hero.

Rendering uses `@resvg/resvg-js`, found the same way as for [icons](#icons), including `DEVKIT_ICONS_RENDERER_DIR`. `--check` draws every hero in memory and compares its pixels with the committed file, so it needs the same renderer version and the fonts, but not Docker. It also fails on a hero file for a locale the listing no longer has, which a plain run only names. `--assets <dir>` reads a store-assets folder other than `store-assets/` at the repo root.

The renderer and fonts are pinned so that `--check` redraws the same pixels anywhere, but that is so far shown only on Linux x64 (WSL and CI); `check:icons` has relied on the same property for shapes, and a hero adds text, blur and image scaling. Japanese and Chinese line breaks come from the ICU data built into Node, so a Node update that changes ICU can move a break; `--check` then reports the hero, and a plain run redraws it.

Two complete examples, with synthetic captures, are in `docs/examples/store-hero/`.

### Refusing secrets and oversized files at commit time

`devkit-precommit` is the shared pre-commit check. It refuses staged:
Expand Down Expand Up @@ -404,6 +455,7 @@ Host-side tools that need only the database can call `prepareDatabase({ repoRoot
| `devkit-init [--check]` | write or check the generated dev files; see [Generated dev files](#generated-dev-files) |
| `devkit-wait-for-db` | wait until `DATABASE_URL` accepts connections; see [Waiting for the database](#waiting-for-the-database-and-the-vite-server-block) |
| `devkit-icons [--check]` | write or check every icon size from the SVG masters; see [Icons](#icons) |
| `devkit-store-hero [--check] [--assets <dir>]` | write or check the generated first Store screenshot in every listing locale; see [Store heroes](#store-heroes) |
| `devkit-precommit [--allow <path>] [--max-size <n>]` | refuse staged secrets, keys and oversized files; see [Refusing secrets](#refusing-secrets-and-oversized-files-at-commit-time) |

`devkit` with no command prints the full option list.
Expand Down
84 changes: 84 additions & 0 deletions bin/devkit-store-hero.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env node
/**
* `devkit-store-hero [--check] [--assets <dir>]`: writes, or checks, the generated first Store
* screenshot (D-123) in every listing locale, from `store-assets/manifest.json` and each store's
* `listings.json`.
*
* `--check` writes nothing and fails when a hero is missing, differs from what its inputs draw,
* or was saved by another tool, for the repo's `validate` gate. Both modes name hero files left
* from a locale the listing no longer has; `--check` fails on them. `--assets` names the
* store-assets folder when it is not `store-assets/` at the repo root. `--fetch-fonts` only
* downloads the pinned fonts, for a CI cache step.
*
* Like the other `devkit-*` commands it needs no bootstrapped machine. It needs `@resvg/resvg-js`
* (as `devkit-icons` does) and downloads its fonts once (see "Store heroes" in the README).
*/
import {
checkHeroes,
orphanedHeroes,
writeHeroes,
} from '../src/store-hero/index.mjs'
import { ensureFonts, fontsDir } from '../src/store-hero/fonts.mjs'

const root = process.cwd()
const args = process.argv.slice(2)
const log = (message) => console.error(message)

/** The value after `--assets`, if given. */
function assetsDir() {
const index = args.indexOf('--assets')
if (index === -1) return undefined
const value = args[index + 1]
if (!value || value.startsWith('--'))
throw new Error('devkit-store-hero: --assets needs a folder')
return value
}

/** Lists hero files for removed locales on stderr; returns true when there were any. */
function reportOrphans(options) {
const orphans = orphanedHeroes(root, options)
if (orphans.length === 0) return false

console.error(
'devkit-store-hero: remove these heroes; their locale is no longer in the listing:',
)
for (const file of orphans) console.error(` ${file}`)
return true
}

try {
const known = new Set(['--check', '--assets', '--fetch-fonts'])
const unknown = args.find(
(arg, index) =>
arg.startsWith('--') && !known.has(arg) && args[index - 1] !== '--assets',
)
if (unknown) throw new Error(`devkit-store-hero: unknown option ${unknown}`)

const options = { assetsDir: assetsDir(), log }
if (args.includes('--fetch-fonts')) {
await ensureFonts({ log })
console.log(`devkit-store-hero: fonts are in ${fontsDir()}`)
} else if (args.includes('--check')) {
const stale = await checkHeroes(root, options)
if (stale.length > 0) {
console.error(
'devkit-store-hero: these heroes do not match their inputs:',
)
for (const { path, reason } of stale)
console.error(` ${path}: ${reason}`)
console.error('Run `devkit-store-hero` and commit the result.')
}
const hasOrphans = reportOrphans(options)

if (stale.length > 0 || hasOrphans) process.exitCode = 1
else console.log('devkit-store-hero: every hero matches its inputs')
} else {
const { written, advice } = await writeHeroes(root, options)
console.log(`devkit-store-hero: wrote ${written.length} files`)
for (const line of advice) console.error(`devkit-store-hero: note: ${line}`)
reportOrphans(options)
}
} catch (error) {
console.error(error.message)
process.exitCode = 1
}
1 change: 1 addition & 0 deletions docs/examples/store-hero/brand-card/assets/brand/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading