@zero2webmaster/starter-kit 0.18.4 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/scaffolders/nextjs.d.ts +13 -0
- package/dist/scaffolders/nextjs.js +355 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# z2w-starter-kit
|
|
2
2
|
|
|
3
|
-
**Version:** 0.
|
|
3
|
+
**Version:** 0.19.1 | **Framework:** 2.18.0
|
|
4
4
|
|
|
5
5
|
> Node CLI to scaffold new Z2W projects from canonical Templates + AGENTS.md.
|
|
6
6
|
|
|
@@ -83,7 +83,9 @@ The Claude Code skill at `~/.claude/skills/instantiate-z2w-project/SKILL.md` and
|
|
|
83
83
|
|
|
84
84
|
## Status
|
|
85
85
|
|
|
86
|
-
- **v0.
|
|
86
|
+
- **v0.19.1 (current)** emits a `:disabled` rule for **buttons** in `app/globals.css`, so a disabled button still looks disabled after the author gives buttons a brand fill. The scaffold ships no button styling of its own, so today the browser's grey rendering still applies — the trap opens on the author's first `background`/`color`, which overrides that grey and leaves `:disabled` a state with no appearance: the button looks pressable, the click does nothing, and the user concludes the app is broken. A sibling Z2W app shipped exactly that across ~50 screens behind a clean typecheck, a green build and 1,051 passing tests, because it is a rendered-pixel property no unit test holds. Includes the `:hover` cancel people forget — a `filter: brightness()` hover happily re-brightens a dimmed button at the moment the user is deciding to click. Verified on real pixels via CDP with `:hover` forced, and canary-verified by stripping the rule from a live scaffold.
|
|
87
|
+
- **v0.19.0** emits the **PWA baseline** for `nextjs` projects with a web UI — `public/manifest.json`, `public/icon.svg`, `public/sw.js` and `components/ServiceWorker.tsx`, wired into `app/layout.tsx` — so a scaffolded app installs on a phone. Three decisions run against the original design note and are documented in place: `app/icon.svg` is NOT emitted (a static icon file in that segment would silently retire the generated `app/icon.tsx` favicon), `theme_color` comes from the brand primary so it agrees with the layout's `viewport.themeColor`, and the glyph is a path rather than text because no font is guaranteed where the OS rasterises an icon. The service worker is network-first, never caches `/api/`, and evicts only its own cache prefix — that last clause fixed a real defect found by **executing** the emitted worker in tests rather than grepping it: an origin-wide sweep meant one Z2W app's deploy wiped a neighbouring app's offline cache under `/path` routing.
|
|
88
|
+
- **v0.18.4** points the writer's cross-cutting placeholder check at EVERY emitted file. It had run against `CLAUDE.md` alone since Step 6 — one of the ~42 files a Next.js scaffold emits — so `sentry.shared.ts` shipped a literal `{{project_name}}`, a key that has never existed in the substitution map. Found by dogfooding a real scaffold, not by the suite. A per-project-type sweep now covers all eight types.
|
|
87
89
|
- **v0.18.3** makes every emitted `.gitignore` refuse a downloaded cloud service-account key. The Google Cloud console names a private key `<project-id>-<12 hex>.json`, which matched nothing in the scaffolded ignore file and, unlike a stray `.env.production`, carries no hint in its filename that it is a credential. Found when a live Gmail delegation key for two SAVE THE FROGS! mailboxes landed in a repo this CLI had emitted.
|
|
88
90
|
- **v0.18.2** bumps the emitted Agent Coordination fingerprint to **v0.1.26**, matching what `z2w-agent-coordination` currently publishes. Every scaffold emitted while the constant said `v0.1.25` carries a stale fingerprint, which is precisely the drift the fingerprint exists to detect.
|
|
89
91
|
- **v0.18.1** returns the audience gate's findings as **data** (`ScaffoldResult.audienceGate`) rather than only printing them. v0.18.0 wrote its dangling-reference warning to the terminal, but `previewScaffold()` discards its output stream by design — and that is the entry point a web UI uses — so the report had no receiver on the one path where an external audience actually occurs. No emitted file changes by a byte.
|
|
@@ -125,4 +127,4 @@ Inquiries: kerry@zero2webmaster.com.
|
|
|
125
127
|
---
|
|
126
128
|
|
|
127
129
|
*Scaffolded 2026-05-28 via the [[instantiate-z2w-project]] Claude Code skill v1; reconciled against the consolidated skill v1.1.0 (brief-first + Agent Coordination block) on 2026-05-29.*
|
|
128
|
-
*Version: 0.
|
|
130
|
+
*Version: 0.19.1 | Last Updated: 2026-08-17*
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { ScaffoldInputs } from "../index.js";
|
|
2
2
|
import { type ScaffoldFile, type ScaffolderOptions } from "./common.js";
|
|
3
|
+
/**
|
|
4
|
+
* The root layout with the PWA wiring spliced in.
|
|
5
|
+
*
|
|
6
|
+
* Splicing rather than a second full copy of the template: two layout
|
|
7
|
+
* templates would drift the moment somebody edits the SEO half, and the SEO
|
|
8
|
+
* half is the one with the expensive, hard-won comments in it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function withPwaWiring(layout: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Exported so tests can assert the PWA file set from one place rather than
|
|
13
|
+
* restating four paths per assertion — same job as NEXTJS_SEO_BASELINE_PATHS.
|
|
14
|
+
*/
|
|
15
|
+
export declare const NEXTJS_PWA_PATHS: readonly ["public/manifest.json", "public/icon.svg", "public/sw.js", "components/ServiceWorker.tsx"];
|
|
3
16
|
export declare function scaffoldNextjs(inputs: ScaffoldInputs, opts?: ScaffolderOptions): ScaffoldFile[];
|
|
4
17
|
/**
|
|
5
18
|
* Exported for tests + the eventual standards-conflict resolver in Step 5 so
|
|
@@ -815,6 +815,67 @@ body {
|
|
|
815
815
|
border-radius: 4px;
|
|
816
816
|
font-size: 15px;
|
|
817
817
|
}
|
|
818
|
+
|
|
819
|
+
/* --- Disabled buttons -------------------------------------------------------
|
|
820
|
+
*
|
|
821
|
+
* This scaffold ships no button styling of its own, so today a disabled button
|
|
822
|
+
* still gets the browser's own greyed-out rendering and looks disabled. THE TRAP
|
|
823
|
+
* OPENS THE MOMENT YOU GIVE A BUTTON ITS OWN \`background\` and \`color\`, which
|
|
824
|
+
* every branded design system does within its first week: your fill overrides
|
|
825
|
+
* the user agent's grey, and \`:disabled\` becomes a state with no appearance.
|
|
826
|
+
* The button then looks completely pressable, the click does nothing, and the
|
|
827
|
+
* user concludes the app is broken rather than that the control is unavailable.
|
|
828
|
+
* That is not hypothetical — a sibling Z2W app shipped fully-pressable-looking
|
|
829
|
+
* disabled buttons across ~50 screens from its first commit, behind a clean
|
|
830
|
+
* typecheck, a green production build and 1,051 passing tests, because this is a
|
|
831
|
+
* rendered-pixel property that no type system or unit test can hold.
|
|
832
|
+
*
|
|
833
|
+
* So the rule is emitted BEFORE the first branded button exists, and it is
|
|
834
|
+
* written as element/attribute selectors rather than a \`.btn\` class, so it
|
|
835
|
+
* applies to whatever you style later whatever you end up calling it.
|
|
836
|
+
*
|
|
837
|
+
* THE \`:hover\` HALF IS THE ONE PEOPLE FORGET. A \`filter: brightness(1.08)\`
|
|
838
|
+
* hover — the most common way to add a hover state — happily re-brightens a
|
|
839
|
+
* dimmed button at exactly the moment the user is deciding to click it, undoing
|
|
840
|
+
* the signal precisely when it is being read. Same for a \`transform\` lift.
|
|
841
|
+
*
|
|
842
|
+
* Deliberately NOT a bare \`[disabled]\` selector: that also matches
|
|
843
|
+
* \`input\`/\`textarea\`/\`select\`, whose disabled palette above was chosen for
|
|
844
|
+
* measured contrast, and layering \`opacity\` on top of it would undo that. It
|
|
845
|
+
* would also dim a whole \`<fieldset disabled>\` twice over. Disabled TEXT INPUTS
|
|
846
|
+
* and disabled BUTTONS are different problems and get different rules.
|
|
847
|
+
*
|
|
848
|
+
* \`aria-disabled="true"\` is covered alongside \`:disabled\` because a button that
|
|
849
|
+
* must stay focusable (so a screen-reader user can find it and hear why it is
|
|
850
|
+
* unavailable) is marked that way and is NOT matched by \`:disabled\`.
|
|
851
|
+
*/
|
|
852
|
+
button:disabled,
|
|
853
|
+
button[aria-disabled="true"],
|
|
854
|
+
input[type="submit"]:disabled,
|
|
855
|
+
input[type="button"]:disabled,
|
|
856
|
+
input[type="reset"]:disabled,
|
|
857
|
+
[role="button"][aria-disabled="true"] {
|
|
858
|
+
opacity: 0.45;
|
|
859
|
+
cursor: not-allowed;
|
|
860
|
+
filter: none;
|
|
861
|
+
box-shadow: none;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/* Cancels a hover effect declared on the enabled button. Kept as a separate rule
|
|
865
|
+
rather than folded above because the pseudo-class raises specificity, which is
|
|
866
|
+
what lets it beat a later \`.btn:hover\`. It does NOT beat a two-class hover
|
|
867
|
+
such as \`.btn.is-primary:hover\` — if your design system gets that specific,
|
|
868
|
+
add \`:not(:disabled)\` to the hover selector at the source, which is the fix
|
|
869
|
+
that scales. */
|
|
870
|
+
button:disabled:hover,
|
|
871
|
+
button[aria-disabled="true"]:hover,
|
|
872
|
+
input[type="submit"]:disabled:hover,
|
|
873
|
+
input[type="button"]:disabled:hover,
|
|
874
|
+
input[type="reset"]:disabled:hover,
|
|
875
|
+
[role="button"][aria-disabled="true"]:hover {
|
|
876
|
+
filter: none;
|
|
877
|
+
transform: none;
|
|
878
|
+
}
|
|
818
879
|
`;
|
|
819
880
|
}
|
|
820
881
|
/* --- Card-path bot protection (acceptsCards) -------------------------------- */
|
|
@@ -2448,6 +2509,275 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
2448
2509
|
);
|
|
2449
2510
|
}
|
|
2450
2511
|
`;
|
|
2512
|
+
// --- PWA baseline: manifest + maskable icon + service worker ---------------
|
|
2513
|
+
//
|
|
2514
|
+
// Emitted for `nextjs` when `hasWebUi` is true. Kerry runs several of these
|
|
2515
|
+
// apps (org-hq, the command center) from his phone, and phone-installability
|
|
2516
|
+
// is otherwise a thing nobody retrofits.
|
|
2517
|
+
//
|
|
2518
|
+
// 🔴 THREE DEVIATIONS FROM THE ROADMAP CANDIDATE NOTE, each with a reason —
|
|
2519
|
+
// read them before "restoring" the note's version:
|
|
2520
|
+
//
|
|
2521
|
+
// 1. The note says emit `app/icon.svg` "so Next.js auto-serves the favicon".
|
|
2522
|
+
// We do NOT. This scaffold already ships `app/icon.tsx`, whose own comment
|
|
2523
|
+
// records that a STATIC icon file in the same segment TAKES PRECEDENCE over
|
|
2524
|
+
// the route. Emitting `app/icon.svg` would therefore silently retire the
|
|
2525
|
+
// generated favicon — a regression dressed as an addition. The manifest
|
|
2526
|
+
// reads `public/icon.svg`; the tab keeps reading `app/icon.tsx`.
|
|
2527
|
+
//
|
|
2528
|
+
// 2. The note says `theme_color` comes from the brand ACCENT. It comes from
|
|
2529
|
+
// the brand PRIMARY here, because `app/layout.tsx` already exports
|
|
2530
|
+
// `viewport.themeColor = "{{primary_color}}"`. Two different theme colours
|
|
2531
|
+
// for one app is a defect, not a palette.
|
|
2532
|
+
//
|
|
2533
|
+
// 3. The glyph is a geometric path, not the brand initial as `<text>`. A
|
|
2534
|
+
// manifest icon is rasterised by the OS/browser installer, where no
|
|
2535
|
+
// particular font is guaranteed; a `<text>` glyph can land as a fallback
|
|
2536
|
+
// face or as nothing. Paths render identically everywhere.
|
|
2537
|
+
const PWA_MANIFEST_TEMPLATE = `{
|
|
2538
|
+
"name": "{{brand_name}} — {{slug}}",
|
|
2539
|
+
"short_name": "{{slug}}",
|
|
2540
|
+
"description": "{{description}}",
|
|
2541
|
+
"id": "/",
|
|
2542
|
+
"start_url": "/",
|
|
2543
|
+
"scope": "/",
|
|
2544
|
+
"display": "standalone",
|
|
2545
|
+
"orientation": "any",
|
|
2546
|
+
"background_color": "#ffffff",
|
|
2547
|
+
"theme_color": "{{primary_color}}",
|
|
2548
|
+
"icons": [
|
|
2549
|
+
{
|
|
2550
|
+
"src": "/icon.svg",
|
|
2551
|
+
"sizes": "any",
|
|
2552
|
+
"type": "image/svg+xml",
|
|
2553
|
+
"purpose": "any"
|
|
2554
|
+
},
|
|
2555
|
+
{
|
|
2556
|
+
"src": "/icon.svg",
|
|
2557
|
+
"sizes": "any",
|
|
2558
|
+
"type": "image/svg+xml",
|
|
2559
|
+
"purpose": "maskable"
|
|
2560
|
+
}
|
|
2561
|
+
]
|
|
2562
|
+
}
|
|
2563
|
+
`;
|
|
2564
|
+
// One SVG listed twice in the manifest — once `purpose: "any"`, once
|
|
2565
|
+
// `purpose: "maskable"`. They are different jobs, not a duplicate: an icon with
|
|
2566
|
+
// no `maskable` entry gets a white plate drawn behind it on Android, and an
|
|
2567
|
+
// icon with ONLY a `maskable` entry is padded again everywhere else.
|
|
2568
|
+
//
|
|
2569
|
+
// The sizing transform is the load-bearing line and it is not arbitrary.
|
|
2570
|
+
// Lucide's 24×24 glyphs draw inside x/y 3→21, so
|
|
2571
|
+
// `translate(256 256) scale(15) translate(-12 -12)` centres 18 units × 15 =
|
|
2572
|
+
// 270px of artwork in a 512px frame — 53%. Android's adaptive-icon mask crops
|
|
2573
|
+
// roughly the outer 16.7%, leaving a safe circle of ~410px, so the glyph
|
|
2574
|
+
// survives the crop with room to spare. Scale it up and the mask starts eating
|
|
2575
|
+
// corners on exactly the devices you cannot test on.
|
|
2576
|
+
const PWA_ICON_SVG_TEMPLATE = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512" role="img" aria-label="{{brand_name}}">
|
|
2577
|
+
<!-- Generated placeholder, not a design. Replace with real artwork before
|
|
2578
|
+
launch; keep the 512×512 frame and the rounded-rect field, and keep the
|
|
2579
|
+
artwork inside the central ~80% so the Android maskable crop is safe. -->
|
|
2580
|
+
<rect width="512" height="512" rx="96" fill="{{primary_color}}" />
|
|
2581
|
+
<g transform="translate(256 256) scale(15) translate(-12 -12)" fill="#ffffff">
|
|
2582
|
+
<rect x="3" y="3" width="7" height="7" rx="1" />
|
|
2583
|
+
<rect x="14" y="3" width="7" height="7" rx="1" />
|
|
2584
|
+
<rect x="14" y="14" width="7" height="7" rx="1" />
|
|
2585
|
+
<rect x="3" y="14" width="7" height="7" rx="1" />
|
|
2586
|
+
</g>
|
|
2587
|
+
</svg>
|
|
2588
|
+
`;
|
|
2589
|
+
const PWA_SERVICE_WORKER_TEMPLATE = `// Service worker for {{brand_name}} — {{slug}}.
|
|
2590
|
+
//
|
|
2591
|
+
// NETWORK-FIRST with a cache fallback, deliberately. Cache-first is faster and
|
|
2592
|
+
// is the wrong default for an app whose content changes: it serves yesterday's
|
|
2593
|
+
// HTML to a user who is online and has no way to ask for today's. Here the
|
|
2594
|
+
// cache only answers when the network has already failed, so the worst case is
|
|
2595
|
+
// "you saw the last version you loaded" rather than "the app is stuck".
|
|
2596
|
+
//
|
|
2597
|
+
// The cache name is namespaced per app because two Z2W apps can share an
|
|
2598
|
+
// origin (rootdomain.com/app-a, rootdomain.com/app-b — see
|
|
2599
|
+
// [[subdomain-vs-subdirectory]]) and a shared cache name would have them
|
|
2600
|
+
// evicting each other's entries on every activate.
|
|
2601
|
+
//
|
|
2602
|
+
// To ship a breaking change to the caching rules, bump the version suffix. The
|
|
2603
|
+
// activate handler deletes this app's OTHER versions and nothing else.
|
|
2604
|
+
const CACHE_PREFIX = "{{slug}}-";
|
|
2605
|
+
const CACHE = CACHE_PREFIX + "v1";
|
|
2606
|
+
|
|
2607
|
+
self.addEventListener("install", () => {
|
|
2608
|
+
// Take over immediately rather than waiting for every tab to close. Paired
|
|
2609
|
+
// with clients.claim() below, this means a fix to this file reaches users on
|
|
2610
|
+
// their next load instead of on their next browser restart.
|
|
2611
|
+
self.skipWaiting();
|
|
2612
|
+
});
|
|
2613
|
+
|
|
2614
|
+
self.addEventListener("activate", (event) => {
|
|
2615
|
+
event.waitUntil(
|
|
2616
|
+
caches
|
|
2617
|
+
.keys()
|
|
2618
|
+
// 🔴 Scoped to OUR prefix, not "everything that is not the current
|
|
2619
|
+
// cache". caches.keys() returns every cache on the ORIGIN, and two Z2W
|
|
2620
|
+
// apps routinely share one — the standing guidance is to put
|
|
2621
|
+
// SEO-important apps at rootdomain.com/path behind a Cloudflare front
|
|
2622
|
+
// door rather than on a subdomain ([[subdomain-vs-subdirectory]]). An
|
|
2623
|
+
// unscoped sweep means deploying app B silently wipes app A's offline
|
|
2624
|
+
// cache, which nothing reports and nobody would think to look for.
|
|
2625
|
+
.then((keys) =>
|
|
2626
|
+
Promise.all(
|
|
2627
|
+
keys
|
|
2628
|
+
.filter((key) => key.startsWith(CACHE_PREFIX) && key !== CACHE)
|
|
2629
|
+
.map((key) => caches.delete(key)),
|
|
2630
|
+
),
|
|
2631
|
+
)
|
|
2632
|
+
.then(() => self.clients.claim()),
|
|
2633
|
+
);
|
|
2634
|
+
});
|
|
2635
|
+
|
|
2636
|
+
self.addEventListener("fetch", (event) => {
|
|
2637
|
+
const request = event.request;
|
|
2638
|
+
|
|
2639
|
+
// Non-GET is never cacheable, and intercepting it buys nothing. Returning
|
|
2640
|
+
// without calling respondWith() hands the request straight back to the
|
|
2641
|
+
// browser, which is what we want — it is not a silent drop.
|
|
2642
|
+
if (request.method !== "GET") return;
|
|
2643
|
+
|
|
2644
|
+
const url = new URL(request.url);
|
|
2645
|
+
|
|
2646
|
+
// Cross-origin (fonts, Fathom, Sentry) belongs to whoever serves it. We have
|
|
2647
|
+
// no way to know their freshness rules, so we do not hold their bytes.
|
|
2648
|
+
if (url.origin !== self.location.origin) return;
|
|
2649
|
+
|
|
2650
|
+
// 🔴 NEVER the API. An API response is per-user and often per-second; a stale
|
|
2651
|
+
// one replayed from cache is not a degraded experience, it is wrong data
|
|
2652
|
+
// presented as current. Offline support for API reads, if this app ever
|
|
2653
|
+
// wants it, belongs in the app's own data layer where it can be reasoned
|
|
2654
|
+
// about per endpoint.
|
|
2655
|
+
if (url.pathname === "/api" || url.pathname.startsWith("/api/")) return;
|
|
2656
|
+
|
|
2657
|
+
event.respondWith(networkFirst(request));
|
|
2658
|
+
});
|
|
2659
|
+
|
|
2660
|
+
async function networkFirst(request) {
|
|
2661
|
+
const cache = await caches.open(CACHE);
|
|
2662
|
+
try {
|
|
2663
|
+
const response = await fetch(request);
|
|
2664
|
+
// Only same-origin, genuinely-successful responses are stored. Caching a
|
|
2665
|
+
// 404 or a redirect would make the failure sticky, which is worse than the
|
|
2666
|
+
// failure.
|
|
2667
|
+
if (response && response.ok && response.type === "basic") {
|
|
2668
|
+
cache.put(request, response.clone());
|
|
2669
|
+
}
|
|
2670
|
+
return response;
|
|
2671
|
+
} catch (networkError) {
|
|
2672
|
+
const cached = await cache.match(request);
|
|
2673
|
+
if (cached) return cached;
|
|
2674
|
+
// Nothing cached and no network: let the browser show its own offline
|
|
2675
|
+
// error rather than inventing one. Swallowing this would present an empty
|
|
2676
|
+
// page as a successful load.
|
|
2677
|
+
throw networkError;
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
`;
|
|
2681
|
+
const PWA_REGISTER_TEMPLATE = `"use client";
|
|
2682
|
+
|
|
2683
|
+
// Registers public/sw.js. Mounted once from app/layout.tsx; renders nothing.
|
|
2684
|
+
//
|
|
2685
|
+
// Client component on purpose — the root layout is a Server Component and
|
|
2686
|
+
// navigator.serviceWorker only exists in the browser.
|
|
2687
|
+
|
|
2688
|
+
import { useEffect } from "react";
|
|
2689
|
+
|
|
2690
|
+
export function ServiceWorker() {
|
|
2691
|
+
useEffect(() => {
|
|
2692
|
+
// 🔴 Production only. \`next dev\` serves uncompiled, uncached assets and a
|
|
2693
|
+
// service worker sitting in front of them produces the single most
|
|
2694
|
+
// confusing class of local bug there is: an edit that does not appear, on
|
|
2695
|
+
// a dev server that reports a successful rebuild.
|
|
2696
|
+
if (process.env.NODE_ENV !== "production") return;
|
|
2697
|
+
if (typeof navigator === "undefined" || !("serviceWorker" in navigator)) return;
|
|
2698
|
+
|
|
2699
|
+
const register = () => {
|
|
2700
|
+
void navigator.serviceWorker.register("/sw.js", { scope: "/" }).catch(() => {
|
|
2701
|
+
// Installability is a progressive enhancement. A registration failure
|
|
2702
|
+
// (private mode, an unsupported browser, a blocked scope) must never
|
|
2703
|
+
// surface to the user or break the page they came for.
|
|
2704
|
+
});
|
|
2705
|
+
};
|
|
2706
|
+
|
|
2707
|
+
// Register after load so the worker install never competes with the first
|
|
2708
|
+
// paint for bandwidth.
|
|
2709
|
+
if (document.readyState === "complete") {
|
|
2710
|
+
register();
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2713
|
+
window.addEventListener("load", register);
|
|
2714
|
+
return () => window.removeEventListener("load", register);
|
|
2715
|
+
}, []);
|
|
2716
|
+
|
|
2717
|
+
return null;
|
|
2718
|
+
}
|
|
2719
|
+
`;
|
|
2720
|
+
const PWA_CHECKLIST_BLOCK = `
|
|
2721
|
+
## PWA / installability (wired at instantiation)
|
|
2722
|
+
|
|
2723
|
+
Not SEO, but it is a pre-launch check and this is the pre-launch file.
|
|
2724
|
+
|
|
2725
|
+
- ✅ \`public/manifest.json\` — \`display: "standalone"\`, \`start_url: "/"\`, \`theme_color\` matching \`viewport.themeColor\` in \`app/layout.tsx\`
|
|
2726
|
+
- ✅ \`public/icon.svg\` — 512×512, listed twice in the manifest (\`purpose: "any"\` **and** \`purpose: "maskable"\`)
|
|
2727
|
+
- ✅ \`public/sw.js\` — network-first with cache fallback; never caches \`/api/\`; skips non-GET and cross-origin
|
|
2728
|
+
- ✅ \`components/ServiceWorker.tsx\` — registers the worker in **production only**, mounted from \`app/layout.tsx\`
|
|
2729
|
+
- [ ] **Verify installability on the deployed site, not locally** — the worker does not register under \`next dev\` by design. Chrome DevTools → Application → Manifest should list the manifest with no errors and both icon purposes; Application → Service Workers should show \`sw.js\` activated
|
|
2730
|
+
- [ ] **Confirm \`/api/\` is not being cached** — DevTools → Application → Cache Storage → \`{{slug}}-v1\`, and check no API path appears
|
|
2731
|
+
- [ ] Replace \`public/icon.svg\` with real artwork; keep the 512×512 frame and keep the mark inside the central ~80% (Android crops the rest)
|
|
2732
|
+
- [ ] Shorten \`short_name\` if \`{{slug}}\` is over ~12 characters — longer names are truncated under the home-screen icon
|
|
2733
|
+
`;
|
|
2734
|
+
/**
|
|
2735
|
+
* Replace exactly one occurrence of `needle`, and throw if that is not what
|
|
2736
|
+
* happened.
|
|
2737
|
+
*
|
|
2738
|
+
* 🔴 This exists because `String.prototype.replace` is a SILENT NO-OP on a
|
|
2739
|
+
* miss: it returns the input unchanged and raises nothing. This project lost
|
|
2740
|
+
* time to that twice in one session (2026-08-15) editing markdown, and the
|
|
2741
|
+
* failure is worse here — a missed anchor would emit a layout with no manifest
|
|
2742
|
+
* link or no service-worker mount, which builds clean, typechecks clean, and
|
|
2743
|
+
* is only visible to someone who opens DevTools on a phone.
|
|
2744
|
+
*
|
|
2745
|
+
* Ambiguity is an error too. Two matches means the anchor stopped identifying
|
|
2746
|
+
* one place, and picking the first is a coin flip nobody documented.
|
|
2747
|
+
*/
|
|
2748
|
+
function replaceOnce(source, needle, replacement) {
|
|
2749
|
+
const first = source.indexOf(needle);
|
|
2750
|
+
if (first === -1) {
|
|
2751
|
+
throw new Error(`replaceOnce: anchor not found, so the emitted file would be silently wrong. Anchor: ${JSON.stringify(needle)}`);
|
|
2752
|
+
}
|
|
2753
|
+
if (source.indexOf(needle, first + needle.length) !== -1) {
|
|
2754
|
+
throw new Error(`replaceOnce: anchor matched more than once and is no longer unique. Anchor: ${JSON.stringify(needle)}`);
|
|
2755
|
+
}
|
|
2756
|
+
return source.slice(0, first) + replacement + source.slice(first + needle.length);
|
|
2757
|
+
}
|
|
2758
|
+
/**
|
|
2759
|
+
* The root layout with the PWA wiring spliced in.
|
|
2760
|
+
*
|
|
2761
|
+
* Splicing rather than a second full copy of the template: two layout
|
|
2762
|
+
* templates would drift the moment somebody edits the SEO half, and the SEO
|
|
2763
|
+
* half is the one with the expensive, hard-won comments in it.
|
|
2764
|
+
*/
|
|
2765
|
+
export function withPwaWiring(layout) {
|
|
2766
|
+
let out = replaceOnce(layout, `import { Analytics } from "@/lib/analytics/Analytics";`, `import { Analytics } from "@/lib/analytics/Analytics";\nimport { ServiceWorker } from "@/components/ServiceWorker";`);
|
|
2767
|
+
out = replaceOnce(out, ` description: "{{description}}",\n openGraph: {`, ` description: "{{description}}",\n // Installability. Next.js emits <link rel="manifest"> from this key; do not\n // also hand-write the tag in <head>, it would be emitted twice.\n manifest: "/manifest.json",\n openGraph: {`);
|
|
2768
|
+
out = replaceOnce(out, ` <Analytics />\n`, ` <Analytics />\n {/* Registers public/sw.js in production. Renders nothing. */}\n <ServiceWorker />\n`);
|
|
2769
|
+
return out;
|
|
2770
|
+
}
|
|
2771
|
+
/**
|
|
2772
|
+
* Exported so tests can assert the PWA file set from one place rather than
|
|
2773
|
+
* restating four paths per assertion — same job as NEXTJS_SEO_BASELINE_PATHS.
|
|
2774
|
+
*/
|
|
2775
|
+
export const NEXTJS_PWA_PATHS = [
|
|
2776
|
+
"public/manifest.json",
|
|
2777
|
+
"public/icon.svg",
|
|
2778
|
+
"public/sw.js",
|
|
2779
|
+
"components/ServiceWorker.tsx",
|
|
2780
|
+
];
|
|
2451
2781
|
// --- Fathom analytics: the three-file canonical pattern ---------------------
|
|
2452
2782
|
// Per [[fathom-analytics]] §2 (single-tenant). data-auto="false" alone records
|
|
2453
2783
|
// ZERO pageviews — it MUST be paired with the RouteTracker that calls
|
|
@@ -2958,6 +3288,17 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
2958
3288
|
// the emitted comments say so plainly rather than implying a guarantee that
|
|
2959
3289
|
// isn't there — an in-memory limiter's real ceiling is `limit × instances`.
|
|
2960
3290
|
const durableLimit = acceptsCards && inputs.dbStrategy === "neon-postgres";
|
|
3291
|
+
// The PWA baseline. Gated on `hasWebUi` — the existing input that already
|
|
3292
|
+
// records "this project has pages a person looks at" — and NOT on a new
|
|
3293
|
+
// ScaffoldInputs field, following the v0.9.0 FormBits precedent. A new
|
|
3294
|
+
// optional input needs FOUR touch points (the interface, the scaffolder,
|
|
3295
|
+
// `parseScaffoldInputs` in src/writer.ts, and confirm/wizard/parse-brief),
|
|
3296
|
+
// and `hostRoutedTenancy` shipped with two of them, so the real CLI silently
|
|
3297
|
+
// dropped it while 783 tests passed.
|
|
3298
|
+
//
|
|
3299
|
+
// There is nothing to install on an API-only Next.js app, so an unconditional
|
|
3300
|
+
// manifest there would be an install prompt for a blank page.
|
|
3301
|
+
const pwa = inputs.hasWebUi === true;
|
|
2961
3302
|
let packageJson = sub(PACKAGE_JSON_TEMPLATE, inputs, opts, spec);
|
|
2962
3303
|
if (sendsEmail)
|
|
2963
3304
|
packageJson = withEmailDeps(packageJson);
|
|
@@ -3016,7 +3357,10 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
3016
3357
|
},
|
|
3017
3358
|
]
|
|
3018
3359
|
: []),
|
|
3019
|
-
{
|
|
3360
|
+
{
|
|
3361
|
+
path: "app/layout.tsx",
|
|
3362
|
+
content: sub(pwa ? withPwaWiring(APP_LAYOUT_TEMPLATE) : APP_LAYOUT_TEMPLATE, inputs, opts, spec),
|
|
3363
|
+
},
|
|
3020
3364
|
{ path: "app/page.tsx", content: sub(APP_PAGE_TEMPLATE, inputs, opts, spec) },
|
|
3021
3365
|
{ path: "lib/analytics/utm.ts", content: sub(ANALYTICS_UTM_TEMPLATE, inputs, opts, spec) },
|
|
3022
3366
|
{
|
|
@@ -3040,7 +3384,7 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
3040
3384
|
{ path: "app/icon.tsx", content: sub(APP_ICON_TEMPLATE, inputs, opts, spec) },
|
|
3041
3385
|
{
|
|
3042
3386
|
path: "SEO-CHECKLIST.md",
|
|
3043
|
-
content: sub(SEO_CHECKLIST_TEMPLATE, inputs, opts, spec),
|
|
3387
|
+
content: sub(pwa ? SEO_CHECKLIST_TEMPLATE + PWA_CHECKLIST_BLOCK : SEO_CHECKLIST_TEMPLATE, inputs, opts, spec),
|
|
3044
3388
|
},
|
|
3045
3389
|
{ path: ".env.example", content: envExample },
|
|
3046
3390
|
];
|
|
@@ -3048,6 +3392,15 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
3048
3392
|
path: ".env.local",
|
|
3049
3393
|
content: localEnvFrom(envExample, ".env.local", inputs.slug),
|
|
3050
3394
|
});
|
|
3395
|
+
if (pwa) {
|
|
3396
|
+
typeSpecific.push({
|
|
3397
|
+
path: "public/manifest.json",
|
|
3398
|
+
content: sub(PWA_MANIFEST_TEMPLATE, inputs, opts, spec),
|
|
3399
|
+
}, { path: "public/icon.svg", content: sub(PWA_ICON_SVG_TEMPLATE, inputs, opts, spec) }, { path: "public/sw.js", content: sub(PWA_SERVICE_WORKER_TEMPLATE, inputs, opts, spec) }, {
|
|
3400
|
+
path: "components/ServiceWorker.tsx",
|
|
3401
|
+
content: sub(PWA_REGISTER_TEMPLATE, inputs, opts, spec),
|
|
3402
|
+
});
|
|
3403
|
+
}
|
|
3051
3404
|
if (hostRouted) {
|
|
3052
3405
|
typeSpecific.push({
|
|
3053
3406
|
path: "middleware.ts",
|