@zero2webmaster/starter-kit 0.18.3 → 0.19.0
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 +295 -3
- package/dist/writer.js +19 -0
- 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.0 | **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.0 (current)** 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.
|
|
87
|
+
- **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.
|
|
88
|
+
- **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.
|
|
87
89
|
- **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.
|
|
88
90
|
- **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.
|
|
89
91
|
- **v0.18.0** implements **Kerry's 2026-08-14 ruling — Option A: "ship the artifact, not the doctrine."** A new `audience` input (`internal` | `external`, defaulting to `internal`) gates what an outside customer's scaffold contains. The emitted **code is untouched** — that is the value a customer is buying — but the ~40 KB prose corpus explaining which internal rulings produced it is not emitted: `Standards block`, `Z2W Portfolio Standards`, `Capture Learnings`, `Keeping This Framework Current`, `Common Name & Terminology Glossary` and `Agent Coordination` are dropped as **whole `##` sections**, and surviving `[[skill]]` Vault pointers are unwrapped to plain text. Measured on a real customer scaffold: **CLAUDE.md 85,702 → 44,848 B, a 47.7% reduction, 0 Vault pointers, 0 bulletin-repo mentions**; the internal control is byte-for-byte unchanged. **Whole sections, never edited sentences** — omitting a fingerprinted block makes no identity claim, whereas editing one ships a modified body under an unmodified fingerprint and an emitter mints that lie forever. The gate **refuses to emit** when a section it must drop cannot be found (a renamed heading would otherwise re-leak it silently), and **reports** surviving back-references to dropped sections rather than editing the canonical body to fix them.
|
|
@@ -124,4 +126,4 @@ Inquiries: kerry@zero2webmaster.com.
|
|
|
124
126
|
---
|
|
125
127
|
|
|
126
128
|
*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.*
|
|
127
|
-
*Version: 0.
|
|
129
|
+
*Version: 0.19.0 | Last Updated: 2026-08-16*
|
|
@@ -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
|
|
@@ -2116,7 +2116,7 @@ describe("form standards", () => {
|
|
|
2116
2116
|
* is a deliberate act with a comment saying why.
|
|
2117
2117
|
*/
|
|
2118
2118
|
const SENTRY_SHARED_TEMPLATE = `/**
|
|
2119
|
-
* Sentry data-collection policy for {{
|
|
2119
|
+
* Sentry data-collection policy for {{slug}} — the single source of truth.
|
|
2120
2120
|
*
|
|
2121
2121
|
* Every Sentry runtime config (\`sentry.client.config.ts\`,
|
|
2122
2122
|
* \`sentry.server.config.ts\`, \`sentry.edge.config.ts\`) MUST spread
|
|
@@ -2448,6 +2448,275 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
2448
2448
|
);
|
|
2449
2449
|
}
|
|
2450
2450
|
`;
|
|
2451
|
+
// --- PWA baseline: manifest + maskable icon + service worker ---------------
|
|
2452
|
+
//
|
|
2453
|
+
// Emitted for `nextjs` when `hasWebUi` is true. Kerry runs several of these
|
|
2454
|
+
// apps (org-hq, the command center) from his phone, and phone-installability
|
|
2455
|
+
// is otherwise a thing nobody retrofits.
|
|
2456
|
+
//
|
|
2457
|
+
// 🔴 THREE DEVIATIONS FROM THE ROADMAP CANDIDATE NOTE, each with a reason —
|
|
2458
|
+
// read them before "restoring" the note's version:
|
|
2459
|
+
//
|
|
2460
|
+
// 1. The note says emit `app/icon.svg` "so Next.js auto-serves the favicon".
|
|
2461
|
+
// We do NOT. This scaffold already ships `app/icon.tsx`, whose own comment
|
|
2462
|
+
// records that a STATIC icon file in the same segment TAKES PRECEDENCE over
|
|
2463
|
+
// the route. Emitting `app/icon.svg` would therefore silently retire the
|
|
2464
|
+
// generated favicon — a regression dressed as an addition. The manifest
|
|
2465
|
+
// reads `public/icon.svg`; the tab keeps reading `app/icon.tsx`.
|
|
2466
|
+
//
|
|
2467
|
+
// 2. The note says `theme_color` comes from the brand ACCENT. It comes from
|
|
2468
|
+
// the brand PRIMARY here, because `app/layout.tsx` already exports
|
|
2469
|
+
// `viewport.themeColor = "{{primary_color}}"`. Two different theme colours
|
|
2470
|
+
// for one app is a defect, not a palette.
|
|
2471
|
+
//
|
|
2472
|
+
// 3. The glyph is a geometric path, not the brand initial as `<text>`. A
|
|
2473
|
+
// manifest icon is rasterised by the OS/browser installer, where no
|
|
2474
|
+
// particular font is guaranteed; a `<text>` glyph can land as a fallback
|
|
2475
|
+
// face or as nothing. Paths render identically everywhere.
|
|
2476
|
+
const PWA_MANIFEST_TEMPLATE = `{
|
|
2477
|
+
"name": "{{brand_name}} — {{slug}}",
|
|
2478
|
+
"short_name": "{{slug}}",
|
|
2479
|
+
"description": "{{description}}",
|
|
2480
|
+
"id": "/",
|
|
2481
|
+
"start_url": "/",
|
|
2482
|
+
"scope": "/",
|
|
2483
|
+
"display": "standalone",
|
|
2484
|
+
"orientation": "any",
|
|
2485
|
+
"background_color": "#ffffff",
|
|
2486
|
+
"theme_color": "{{primary_color}}",
|
|
2487
|
+
"icons": [
|
|
2488
|
+
{
|
|
2489
|
+
"src": "/icon.svg",
|
|
2490
|
+
"sizes": "any",
|
|
2491
|
+
"type": "image/svg+xml",
|
|
2492
|
+
"purpose": "any"
|
|
2493
|
+
},
|
|
2494
|
+
{
|
|
2495
|
+
"src": "/icon.svg",
|
|
2496
|
+
"sizes": "any",
|
|
2497
|
+
"type": "image/svg+xml",
|
|
2498
|
+
"purpose": "maskable"
|
|
2499
|
+
}
|
|
2500
|
+
]
|
|
2501
|
+
}
|
|
2502
|
+
`;
|
|
2503
|
+
// One SVG listed twice in the manifest — once `purpose: "any"`, once
|
|
2504
|
+
// `purpose: "maskable"`. They are different jobs, not a duplicate: an icon with
|
|
2505
|
+
// no `maskable` entry gets a white plate drawn behind it on Android, and an
|
|
2506
|
+
// icon with ONLY a `maskable` entry is padded again everywhere else.
|
|
2507
|
+
//
|
|
2508
|
+
// The sizing transform is the load-bearing line and it is not arbitrary.
|
|
2509
|
+
// Lucide's 24×24 glyphs draw inside x/y 3→21, so
|
|
2510
|
+
// `translate(256 256) scale(15) translate(-12 -12)` centres 18 units × 15 =
|
|
2511
|
+
// 270px of artwork in a 512px frame — 53%. Android's adaptive-icon mask crops
|
|
2512
|
+
// roughly the outer 16.7%, leaving a safe circle of ~410px, so the glyph
|
|
2513
|
+
// survives the crop with room to spare. Scale it up and the mask starts eating
|
|
2514
|
+
// corners on exactly the devices you cannot test on.
|
|
2515
|
+
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}}">
|
|
2516
|
+
<!-- Generated placeholder, not a design. Replace with real artwork before
|
|
2517
|
+
launch; keep the 512×512 frame and the rounded-rect field, and keep the
|
|
2518
|
+
artwork inside the central ~80% so the Android maskable crop is safe. -->
|
|
2519
|
+
<rect width="512" height="512" rx="96" fill="{{primary_color}}" />
|
|
2520
|
+
<g transform="translate(256 256) scale(15) translate(-12 -12)" fill="#ffffff">
|
|
2521
|
+
<rect x="3" y="3" width="7" height="7" rx="1" />
|
|
2522
|
+
<rect x="14" y="3" width="7" height="7" rx="1" />
|
|
2523
|
+
<rect x="14" y="14" width="7" height="7" rx="1" />
|
|
2524
|
+
<rect x="3" y="14" width="7" height="7" rx="1" />
|
|
2525
|
+
</g>
|
|
2526
|
+
</svg>
|
|
2527
|
+
`;
|
|
2528
|
+
const PWA_SERVICE_WORKER_TEMPLATE = `// Service worker for {{brand_name}} — {{slug}}.
|
|
2529
|
+
//
|
|
2530
|
+
// NETWORK-FIRST with a cache fallback, deliberately. Cache-first is faster and
|
|
2531
|
+
// is the wrong default for an app whose content changes: it serves yesterday's
|
|
2532
|
+
// HTML to a user who is online and has no way to ask for today's. Here the
|
|
2533
|
+
// cache only answers when the network has already failed, so the worst case is
|
|
2534
|
+
// "you saw the last version you loaded" rather than "the app is stuck".
|
|
2535
|
+
//
|
|
2536
|
+
// The cache name is namespaced per app because two Z2W apps can share an
|
|
2537
|
+
// origin (rootdomain.com/app-a, rootdomain.com/app-b — see
|
|
2538
|
+
// [[subdomain-vs-subdirectory]]) and a shared cache name would have them
|
|
2539
|
+
// evicting each other's entries on every activate.
|
|
2540
|
+
//
|
|
2541
|
+
// To ship a breaking change to the caching rules, bump the version suffix. The
|
|
2542
|
+
// activate handler deletes this app's OTHER versions and nothing else.
|
|
2543
|
+
const CACHE_PREFIX = "{{slug}}-";
|
|
2544
|
+
const CACHE = CACHE_PREFIX + "v1";
|
|
2545
|
+
|
|
2546
|
+
self.addEventListener("install", () => {
|
|
2547
|
+
// Take over immediately rather than waiting for every tab to close. Paired
|
|
2548
|
+
// with clients.claim() below, this means a fix to this file reaches users on
|
|
2549
|
+
// their next load instead of on their next browser restart.
|
|
2550
|
+
self.skipWaiting();
|
|
2551
|
+
});
|
|
2552
|
+
|
|
2553
|
+
self.addEventListener("activate", (event) => {
|
|
2554
|
+
event.waitUntil(
|
|
2555
|
+
caches
|
|
2556
|
+
.keys()
|
|
2557
|
+
// 🔴 Scoped to OUR prefix, not "everything that is not the current
|
|
2558
|
+
// cache". caches.keys() returns every cache on the ORIGIN, and two Z2W
|
|
2559
|
+
// apps routinely share one — the standing guidance is to put
|
|
2560
|
+
// SEO-important apps at rootdomain.com/path behind a Cloudflare front
|
|
2561
|
+
// door rather than on a subdomain ([[subdomain-vs-subdirectory]]). An
|
|
2562
|
+
// unscoped sweep means deploying app B silently wipes app A's offline
|
|
2563
|
+
// cache, which nothing reports and nobody would think to look for.
|
|
2564
|
+
.then((keys) =>
|
|
2565
|
+
Promise.all(
|
|
2566
|
+
keys
|
|
2567
|
+
.filter((key) => key.startsWith(CACHE_PREFIX) && key !== CACHE)
|
|
2568
|
+
.map((key) => caches.delete(key)),
|
|
2569
|
+
),
|
|
2570
|
+
)
|
|
2571
|
+
.then(() => self.clients.claim()),
|
|
2572
|
+
);
|
|
2573
|
+
});
|
|
2574
|
+
|
|
2575
|
+
self.addEventListener("fetch", (event) => {
|
|
2576
|
+
const request = event.request;
|
|
2577
|
+
|
|
2578
|
+
// Non-GET is never cacheable, and intercepting it buys nothing. Returning
|
|
2579
|
+
// without calling respondWith() hands the request straight back to the
|
|
2580
|
+
// browser, which is what we want — it is not a silent drop.
|
|
2581
|
+
if (request.method !== "GET") return;
|
|
2582
|
+
|
|
2583
|
+
const url = new URL(request.url);
|
|
2584
|
+
|
|
2585
|
+
// Cross-origin (fonts, Fathom, Sentry) belongs to whoever serves it. We have
|
|
2586
|
+
// no way to know their freshness rules, so we do not hold their bytes.
|
|
2587
|
+
if (url.origin !== self.location.origin) return;
|
|
2588
|
+
|
|
2589
|
+
// 🔴 NEVER the API. An API response is per-user and often per-second; a stale
|
|
2590
|
+
// one replayed from cache is not a degraded experience, it is wrong data
|
|
2591
|
+
// presented as current. Offline support for API reads, if this app ever
|
|
2592
|
+
// wants it, belongs in the app's own data layer where it can be reasoned
|
|
2593
|
+
// about per endpoint.
|
|
2594
|
+
if (url.pathname === "/api" || url.pathname.startsWith("/api/")) return;
|
|
2595
|
+
|
|
2596
|
+
event.respondWith(networkFirst(request));
|
|
2597
|
+
});
|
|
2598
|
+
|
|
2599
|
+
async function networkFirst(request) {
|
|
2600
|
+
const cache = await caches.open(CACHE);
|
|
2601
|
+
try {
|
|
2602
|
+
const response = await fetch(request);
|
|
2603
|
+
// Only same-origin, genuinely-successful responses are stored. Caching a
|
|
2604
|
+
// 404 or a redirect would make the failure sticky, which is worse than the
|
|
2605
|
+
// failure.
|
|
2606
|
+
if (response && response.ok && response.type === "basic") {
|
|
2607
|
+
cache.put(request, response.clone());
|
|
2608
|
+
}
|
|
2609
|
+
return response;
|
|
2610
|
+
} catch (networkError) {
|
|
2611
|
+
const cached = await cache.match(request);
|
|
2612
|
+
if (cached) return cached;
|
|
2613
|
+
// Nothing cached and no network: let the browser show its own offline
|
|
2614
|
+
// error rather than inventing one. Swallowing this would present an empty
|
|
2615
|
+
// page as a successful load.
|
|
2616
|
+
throw networkError;
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
`;
|
|
2620
|
+
const PWA_REGISTER_TEMPLATE = `"use client";
|
|
2621
|
+
|
|
2622
|
+
// Registers public/sw.js. Mounted once from app/layout.tsx; renders nothing.
|
|
2623
|
+
//
|
|
2624
|
+
// Client component on purpose — the root layout is a Server Component and
|
|
2625
|
+
// navigator.serviceWorker only exists in the browser.
|
|
2626
|
+
|
|
2627
|
+
import { useEffect } from "react";
|
|
2628
|
+
|
|
2629
|
+
export function ServiceWorker() {
|
|
2630
|
+
useEffect(() => {
|
|
2631
|
+
// 🔴 Production only. \`next dev\` serves uncompiled, uncached assets and a
|
|
2632
|
+
// service worker sitting in front of them produces the single most
|
|
2633
|
+
// confusing class of local bug there is: an edit that does not appear, on
|
|
2634
|
+
// a dev server that reports a successful rebuild.
|
|
2635
|
+
if (process.env.NODE_ENV !== "production") return;
|
|
2636
|
+
if (typeof navigator === "undefined" || !("serviceWorker" in navigator)) return;
|
|
2637
|
+
|
|
2638
|
+
const register = () => {
|
|
2639
|
+
void navigator.serviceWorker.register("/sw.js", { scope: "/" }).catch(() => {
|
|
2640
|
+
// Installability is a progressive enhancement. A registration failure
|
|
2641
|
+
// (private mode, an unsupported browser, a blocked scope) must never
|
|
2642
|
+
// surface to the user or break the page they came for.
|
|
2643
|
+
});
|
|
2644
|
+
};
|
|
2645
|
+
|
|
2646
|
+
// Register after load so the worker install never competes with the first
|
|
2647
|
+
// paint for bandwidth.
|
|
2648
|
+
if (document.readyState === "complete") {
|
|
2649
|
+
register();
|
|
2650
|
+
return;
|
|
2651
|
+
}
|
|
2652
|
+
window.addEventListener("load", register);
|
|
2653
|
+
return () => window.removeEventListener("load", register);
|
|
2654
|
+
}, []);
|
|
2655
|
+
|
|
2656
|
+
return null;
|
|
2657
|
+
}
|
|
2658
|
+
`;
|
|
2659
|
+
const PWA_CHECKLIST_BLOCK = `
|
|
2660
|
+
## PWA / installability (wired at instantiation)
|
|
2661
|
+
|
|
2662
|
+
Not SEO, but it is a pre-launch check and this is the pre-launch file.
|
|
2663
|
+
|
|
2664
|
+
- ✅ \`public/manifest.json\` — \`display: "standalone"\`, \`start_url: "/"\`, \`theme_color\` matching \`viewport.themeColor\` in \`app/layout.tsx\`
|
|
2665
|
+
- ✅ \`public/icon.svg\` — 512×512, listed twice in the manifest (\`purpose: "any"\` **and** \`purpose: "maskable"\`)
|
|
2666
|
+
- ✅ \`public/sw.js\` — network-first with cache fallback; never caches \`/api/\`; skips non-GET and cross-origin
|
|
2667
|
+
- ✅ \`components/ServiceWorker.tsx\` — registers the worker in **production only**, mounted from \`app/layout.tsx\`
|
|
2668
|
+
- [ ] **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
|
|
2669
|
+
- [ ] **Confirm \`/api/\` is not being cached** — DevTools → Application → Cache Storage → \`{{slug}}-v1\`, and check no API path appears
|
|
2670
|
+
- [ ] Replace \`public/icon.svg\` with real artwork; keep the 512×512 frame and keep the mark inside the central ~80% (Android crops the rest)
|
|
2671
|
+
- [ ] Shorten \`short_name\` if \`{{slug}}\` is over ~12 characters — longer names are truncated under the home-screen icon
|
|
2672
|
+
`;
|
|
2673
|
+
/**
|
|
2674
|
+
* Replace exactly one occurrence of `needle`, and throw if that is not what
|
|
2675
|
+
* happened.
|
|
2676
|
+
*
|
|
2677
|
+
* 🔴 This exists because `String.prototype.replace` is a SILENT NO-OP on a
|
|
2678
|
+
* miss: it returns the input unchanged and raises nothing. This project lost
|
|
2679
|
+
* time to that twice in one session (2026-08-15) editing markdown, and the
|
|
2680
|
+
* failure is worse here — a missed anchor would emit a layout with no manifest
|
|
2681
|
+
* link or no service-worker mount, which builds clean, typechecks clean, and
|
|
2682
|
+
* is only visible to someone who opens DevTools on a phone.
|
|
2683
|
+
*
|
|
2684
|
+
* Ambiguity is an error too. Two matches means the anchor stopped identifying
|
|
2685
|
+
* one place, and picking the first is a coin flip nobody documented.
|
|
2686
|
+
*/
|
|
2687
|
+
function replaceOnce(source, needle, replacement) {
|
|
2688
|
+
const first = source.indexOf(needle);
|
|
2689
|
+
if (first === -1) {
|
|
2690
|
+
throw new Error(`replaceOnce: anchor not found, so the emitted file would be silently wrong. Anchor: ${JSON.stringify(needle)}`);
|
|
2691
|
+
}
|
|
2692
|
+
if (source.indexOf(needle, first + needle.length) !== -1) {
|
|
2693
|
+
throw new Error(`replaceOnce: anchor matched more than once and is no longer unique. Anchor: ${JSON.stringify(needle)}`);
|
|
2694
|
+
}
|
|
2695
|
+
return source.slice(0, first) + replacement + source.slice(first + needle.length);
|
|
2696
|
+
}
|
|
2697
|
+
/**
|
|
2698
|
+
* The root layout with the PWA wiring spliced in.
|
|
2699
|
+
*
|
|
2700
|
+
* Splicing rather than a second full copy of the template: two layout
|
|
2701
|
+
* templates would drift the moment somebody edits the SEO half, and the SEO
|
|
2702
|
+
* half is the one with the expensive, hard-won comments in it.
|
|
2703
|
+
*/
|
|
2704
|
+
export function withPwaWiring(layout) {
|
|
2705
|
+
let out = replaceOnce(layout, `import { Analytics } from "@/lib/analytics/Analytics";`, `import { Analytics } from "@/lib/analytics/Analytics";\nimport { ServiceWorker } from "@/components/ServiceWorker";`);
|
|
2706
|
+
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: {`);
|
|
2707
|
+
out = replaceOnce(out, ` <Analytics />\n`, ` <Analytics />\n {/* Registers public/sw.js in production. Renders nothing. */}\n <ServiceWorker />\n`);
|
|
2708
|
+
return out;
|
|
2709
|
+
}
|
|
2710
|
+
/**
|
|
2711
|
+
* Exported so tests can assert the PWA file set from one place rather than
|
|
2712
|
+
* restating four paths per assertion — same job as NEXTJS_SEO_BASELINE_PATHS.
|
|
2713
|
+
*/
|
|
2714
|
+
export const NEXTJS_PWA_PATHS = [
|
|
2715
|
+
"public/manifest.json",
|
|
2716
|
+
"public/icon.svg",
|
|
2717
|
+
"public/sw.js",
|
|
2718
|
+
"components/ServiceWorker.tsx",
|
|
2719
|
+
];
|
|
2451
2720
|
// --- Fathom analytics: the three-file canonical pattern ---------------------
|
|
2452
2721
|
// Per [[fathom-analytics]] §2 (single-tenant). data-auto="false" alone records
|
|
2453
2722
|
// ZERO pageviews — it MUST be paired with the RouteTracker that calls
|
|
@@ -2958,6 +3227,17 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
2958
3227
|
// the emitted comments say so plainly rather than implying a guarantee that
|
|
2959
3228
|
// isn't there — an in-memory limiter's real ceiling is `limit × instances`.
|
|
2960
3229
|
const durableLimit = acceptsCards && inputs.dbStrategy === "neon-postgres";
|
|
3230
|
+
// The PWA baseline. Gated on `hasWebUi` — the existing input that already
|
|
3231
|
+
// records "this project has pages a person looks at" — and NOT on a new
|
|
3232
|
+
// ScaffoldInputs field, following the v0.9.0 FormBits precedent. A new
|
|
3233
|
+
// optional input needs FOUR touch points (the interface, the scaffolder,
|
|
3234
|
+
// `parseScaffoldInputs` in src/writer.ts, and confirm/wizard/parse-brief),
|
|
3235
|
+
// and `hostRoutedTenancy` shipped with two of them, so the real CLI silently
|
|
3236
|
+
// dropped it while 783 tests passed.
|
|
3237
|
+
//
|
|
3238
|
+
// There is nothing to install on an API-only Next.js app, so an unconditional
|
|
3239
|
+
// manifest there would be an install prompt for a blank page.
|
|
3240
|
+
const pwa = inputs.hasWebUi === true;
|
|
2961
3241
|
let packageJson = sub(PACKAGE_JSON_TEMPLATE, inputs, opts, spec);
|
|
2962
3242
|
if (sendsEmail)
|
|
2963
3243
|
packageJson = withEmailDeps(packageJson);
|
|
@@ -3016,7 +3296,10 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
3016
3296
|
},
|
|
3017
3297
|
]
|
|
3018
3298
|
: []),
|
|
3019
|
-
{
|
|
3299
|
+
{
|
|
3300
|
+
path: "app/layout.tsx",
|
|
3301
|
+
content: sub(pwa ? withPwaWiring(APP_LAYOUT_TEMPLATE) : APP_LAYOUT_TEMPLATE, inputs, opts, spec),
|
|
3302
|
+
},
|
|
3020
3303
|
{ path: "app/page.tsx", content: sub(APP_PAGE_TEMPLATE, inputs, opts, spec) },
|
|
3021
3304
|
{ path: "lib/analytics/utm.ts", content: sub(ANALYTICS_UTM_TEMPLATE, inputs, opts, spec) },
|
|
3022
3305
|
{
|
|
@@ -3040,7 +3323,7 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
3040
3323
|
{ path: "app/icon.tsx", content: sub(APP_ICON_TEMPLATE, inputs, opts, spec) },
|
|
3041
3324
|
{
|
|
3042
3325
|
path: "SEO-CHECKLIST.md",
|
|
3043
|
-
content: sub(SEO_CHECKLIST_TEMPLATE, inputs, opts, spec),
|
|
3326
|
+
content: sub(pwa ? SEO_CHECKLIST_TEMPLATE + PWA_CHECKLIST_BLOCK : SEO_CHECKLIST_TEMPLATE, inputs, opts, spec),
|
|
3044
3327
|
},
|
|
3045
3328
|
{ path: ".env.example", content: envExample },
|
|
3046
3329
|
];
|
|
@@ -3048,6 +3331,15 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
3048
3331
|
path: ".env.local",
|
|
3049
3332
|
content: localEnvFrom(envExample, ".env.local", inputs.slug),
|
|
3050
3333
|
});
|
|
3334
|
+
if (pwa) {
|
|
3335
|
+
typeSpecific.push({
|
|
3336
|
+
path: "public/manifest.json",
|
|
3337
|
+
content: sub(PWA_MANIFEST_TEMPLATE, inputs, opts, spec),
|
|
3338
|
+
}, { 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) }, {
|
|
3339
|
+
path: "components/ServiceWorker.tsx",
|
|
3340
|
+
content: sub(PWA_REGISTER_TEMPLATE, inputs, opts, spec),
|
|
3341
|
+
});
|
|
3342
|
+
}
|
|
3051
3343
|
if (hostRouted) {
|
|
3052
3344
|
typeSpecific.push({
|
|
3053
3345
|
path: "middleware.ts",
|
package/dist/writer.js
CHANGED
|
@@ -286,6 +286,25 @@ export async function writeScaffold(inputs, targetPath, opts = {}) {
|
|
|
286
286
|
claudeContent = stripVaultPointers(gate.content, audience);
|
|
287
287
|
checkNoUnfilledMarkers(claudeContent, "CLAUDE.md");
|
|
288
288
|
files[claudeIdx] = { path: claudeFile.path, content: claudeContent };
|
|
289
|
+
// 🔴 Run the SAME check over EVERY emitted file, not just CLAUDE.md.
|
|
290
|
+
//
|
|
291
|
+
// The header of this module has advertised a "cross-cutting correctness
|
|
292
|
+
// check" since Step 6, and for that entire time it ran against exactly one
|
|
293
|
+
// of the ~42 files a Next.js scaffold emits. That is the [[zero-is-not-a-pass]]
|
|
294
|
+
// shape in this repo's own writer: a check that examines one specimen and
|
|
295
|
+
// reports like it examined the set.
|
|
296
|
+
//
|
|
297
|
+
// Found 2026-08-15 by dogfooding a real `volunteer-engine` scaffold, which
|
|
298
|
+
// shipped `sentry.shared.ts` carrying a literal `{{project_name}}` — a key
|
|
299
|
+
// that has never existed in `buildSubstitutionMap` (the map says `slug`).
|
|
300
|
+
// `applySubstitutions` leaves an unknown placeholder untouched by design, so
|
|
301
|
+
// nothing upstream objected, and the one guard that would have caught it was
|
|
302
|
+
// pointed at a different file. Consistent with this project's standing note
|
|
303
|
+
// that every scaffold defect to date was found by someone dogfooding the
|
|
304
|
+
// artifact rather than by the suite.
|
|
305
|
+
for (const file of files) {
|
|
306
|
+
checkNoUnfilledMarkers(file.content, file.path);
|
|
307
|
+
}
|
|
289
308
|
// Append promotions follow-up file if any standard was promoted.
|
|
290
309
|
if (promotions.some((p) => p.choice === "promote")) {
|
|
291
310
|
const dateForFile = opts.date ?? new Date().toISOString().slice(0, 10);
|