@zero2webmaster/starter-kit 0.2.0 → 0.3.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 +14 -15
- package/dist/airtable.d.ts +119 -0
- package/dist/airtable.js +273 -0
- package/dist/brief.d.ts +2 -2
- package/dist/brief.js +11 -4
- package/dist/cli.js +290 -17
- package/dist/confirm.d.ts +16 -4
- package/dist/confirm.js +66 -32
- package/dist/index.d.ts +195 -3
- package/dist/index.js +155 -6
- package/dist/inventory.d.ts +137 -0
- package/dist/inventory.js +258 -0
- package/dist/license.d.ts +97 -0
- package/dist/license.js +474 -0
- package/dist/parse-brief.d.ts +45 -1
- package/dist/parse-brief.js +349 -21
- package/dist/scaffolders/common.d.ts +42 -1
- package/dist/scaffolders/common.js +753 -30
- package/dist/scaffolders/index.d.ts +1 -0
- package/dist/scaffolders/index.js +3 -0
- package/dist/scaffolders/library.js +26 -2
- package/dist/scaffolders/nextjs.d.ts +1 -1
- package/dist/scaffolders/nextjs.js +254 -24
- package/dist/scaffolders/node-service.d.ts +3 -0
- package/dist/scaffolders/node-service.js +320 -0
- package/dist/scaffolders/pro-seo-extension.d.ts +11 -0
- package/dist/scaffolders/pro-seo-extension.js +782 -0
- package/dist/scaffolders/python-service.js +10 -2
- package/dist/scaffolders/wp-plugin.js +8 -8
- package/dist/standards.d.ts +1 -1
- package/dist/standards.js +164 -5
- package/dist/substitute.d.ts +22 -3
- package/dist/substitute.js +19 -5
- package/dist/summary.d.ts +9 -0
- package/dist/summary.js +31 -13
- package/dist/templates.d.ts +43 -57
- package/dist/templates.js +108 -175
- package/dist/with-init.d.ts +32 -0
- package/dist/with-init.js +171 -0
- package/dist/wizard.js +21 -0
- package/dist/writer.d.ts +13 -6
- package/dist/writer.js +119 -21
- package/package.json +2 -1
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// Scaffolder: `node-service` — Node + Hono API service for Cloud Run.
|
|
2
|
+
//
|
|
3
|
+
// A portable, runtime-agnostic HTTP API: Hono on @hono/node-server, listening
|
|
4
|
+
// on `process.env.PORT` (Cloud Run injects this; 8080 is the default), with a
|
|
5
|
+
// DB-free `/health` route and a vitest smoke test that passes on first
|
|
6
|
+
// `npm test`. Containerized via the included Dockerfile.
|
|
7
|
+
//
|
|
8
|
+
// When `dbStrategy === "neon-postgres"` the scaffolder also lays down a
|
|
9
|
+
// lazy/import-safe Drizzle + Neon data layer (`src/db/`) plus a `drizzle.config.ts`
|
|
10
|
+
// — the DB handle reads `DATABASE_URL` on first use, never at import time, so
|
|
11
|
+
// the DB-free `/health` path and the tests never require the secret (per
|
|
12
|
+
// [[portable-stack]] §15 + [[neon-postgres]]).
|
|
13
|
+
//
|
|
14
|
+
// NOT subject to the SEO baseline (API-only service, no public HTML surface)
|
|
15
|
+
// and NOT to Fathom (no web UI). IS a deploy target, so the standards resolver
|
|
16
|
+
// inserts the Uptime Kuma + (when applicable) Neon-careful disciplines.
|
|
17
|
+
import { commonBaseFiles, EMAIL_DEPS, EMAIL_ENV_BLOCK, emailFiles, localEnvFrom, resolveBrandSpec, sub, } from "./common.js";
|
|
18
|
+
function buildNarrative(usesNeon) {
|
|
19
|
+
const dbParagraph = usesNeon
|
|
20
|
+
? `
|
|
21
|
+
|
|
22
|
+
**Database:** Neon Postgres via Drizzle (\`src/db/\`). The handle is lazy and import-safe — \`db()\` in \`src/db/index.ts\` reads \`DATABASE_URL\` on first use, never at module load, so the DB-free \`/health\` path and the tests never require the secret (per [[portable-stack]] §15). Migrations: \`npm run db:generate\` then \`npm run db:push\` (drizzle-kit). Keep to standard Postgres types so the schema ports to any Postgres host.`
|
|
23
|
+
: "";
|
|
24
|
+
return `## What this is
|
|
25
|
+
|
|
26
|
+
\`{{slug}}\` is a Node + Hono API service scaffolded under the {{brand_name}} brand, built to deploy on **Cloud Run** (or any Node host — Fly, Render, Railway). API-only — no public HTML surface, no SEO baseline.
|
|
27
|
+
|
|
28
|
+
**Quick start for contributors:**
|
|
29
|
+
|
|
30
|
+
\`\`\`bash
|
|
31
|
+
npm install
|
|
32
|
+
# .env was scaffolded for you — fill in the values it lists
|
|
33
|
+
npm run dev # local server (tsx watch) on http://localhost:8080
|
|
34
|
+
npm test # vitest
|
|
35
|
+
npm run build # compile to dist/
|
|
36
|
+
npm start # node dist/index.js (what the container runs)
|
|
37
|
+
\`\`\`
|
|
38
|
+
|
|
39
|
+
**Health endpoint:** \`GET /health\` returns \`{ "status": "ok" }\`. **Do NOT** make this endpoint touch the database — per [[neon-postgres]], routine uptime probes (per [[uptime-kuma-monitor]]) would burn Neon Free's CU-hour quota and break scale-to-zero. Add a separate \`/health/deep\` with an explicit budget if a real readiness check is ever needed.
|
|
40
|
+
|
|
41
|
+
**Runtime:** Node 20+, listening on \`process.env.PORT\` (Cloud Run injects this; 8080 is the local default). The app is built in \`src/app.ts\` (importable by tests without starting a server) and served by \`src/index.ts\`.
|
|
42
|
+
|
|
43
|
+
**Deployment:** containerized via the included \`Dockerfile\` (multi-stage, \`node:20-slim\`). Per [[portable-stack]], the service avoids host-branded SDKs so it moves between Node hosts with no rewrite.${dbParagraph}
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
function buildPackageJson(usesNeon, sendsEmail) {
|
|
47
|
+
const pkg = {
|
|
48
|
+
name: "{{slug}}",
|
|
49
|
+
version: "{{version}}",
|
|
50
|
+
description: "{{description}}",
|
|
51
|
+
private: true,
|
|
52
|
+
type: "module",
|
|
53
|
+
engines: { node: ">=20" },
|
|
54
|
+
main: "dist/index.js",
|
|
55
|
+
scripts: {
|
|
56
|
+
dev: "tsx watch src/index.ts",
|
|
57
|
+
build: "tsc -p tsconfig.json",
|
|
58
|
+
start: "node dist/index.js",
|
|
59
|
+
typecheck: "tsc --noEmit",
|
|
60
|
+
test: "vitest run",
|
|
61
|
+
...(usesNeon
|
|
62
|
+
? {
|
|
63
|
+
"db:generate": "drizzle-kit generate",
|
|
64
|
+
"db:push": "drizzle-kit push",
|
|
65
|
+
}
|
|
66
|
+
: {}),
|
|
67
|
+
},
|
|
68
|
+
dependencies: {
|
|
69
|
+
"@hono/node-server": "^1.13.0",
|
|
70
|
+
hono: "^4.6.0",
|
|
71
|
+
...(usesNeon
|
|
72
|
+
? {
|
|
73
|
+
"@neondatabase/serverless": "^0.10.0",
|
|
74
|
+
// >=0.45.2 — clears GHSA-gpj5-g38j-94v9 (SQL injection via
|
|
75
|
+
// improperly-escaped identifiers in drizzle-orm <0.45.2).
|
|
76
|
+
"drizzle-orm": "^0.45.2",
|
|
77
|
+
}
|
|
78
|
+
: {}),
|
|
79
|
+
...(sendsEmail ? EMAIL_DEPS : {}),
|
|
80
|
+
},
|
|
81
|
+
devDependencies: {
|
|
82
|
+
"@types/node": "^22.0.0",
|
|
83
|
+
tsx: "^4.20.0",
|
|
84
|
+
typescript: "^5.6.0",
|
|
85
|
+
// vitest 4 (vite 6.x) — vitest <=3.2.5 pulls a vulnerable vite/esbuild
|
|
86
|
+
// (GHSA-67mh-4wv8-2f99). 4.x ships a clean tree (matches the starter-kit's
|
|
87
|
+
// own vitest-2→4 audit fix, its ROADMAP Step 11).
|
|
88
|
+
vitest: "^4.1.0",
|
|
89
|
+
...(usesNeon ? { "drizzle-kit": "^0.31.0" } : {}),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
return JSON.stringify(pkg, null, 2) + "\n";
|
|
93
|
+
}
|
|
94
|
+
const TSCONFIG_TEMPLATE = `{
|
|
95
|
+
"compilerOptions": {
|
|
96
|
+
"target": "ES2022",
|
|
97
|
+
"module": "NodeNext",
|
|
98
|
+
"moduleResolution": "NodeNext",
|
|
99
|
+
"lib": ["ES2022"],
|
|
100
|
+
"types": ["node"],
|
|
101
|
+
"outDir": "dist",
|
|
102
|
+
"rootDir": "src",
|
|
103
|
+
"strict": true,
|
|
104
|
+
"esModuleInterop": true,
|
|
105
|
+
"skipLibCheck": true,
|
|
106
|
+
"forceConsistentCasingInFileNames": true,
|
|
107
|
+
"resolveJsonModule": true,
|
|
108
|
+
"declaration": false,
|
|
109
|
+
"sourceMap": false
|
|
110
|
+
},
|
|
111
|
+
"include": ["src/**/*"],
|
|
112
|
+
"exclude": ["node_modules", "dist"]
|
|
113
|
+
}
|
|
114
|
+
`;
|
|
115
|
+
const VITEST_CONFIG_TEMPLATE = `import { defineConfig } from "vitest/config";
|
|
116
|
+
|
|
117
|
+
export default defineConfig({
|
|
118
|
+
test: {
|
|
119
|
+
include: ["src/**/*.test.ts"],
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
`;
|
|
123
|
+
const SRC_INDEX_TEMPLATE = `// {{slug}} — server entry point.
|
|
124
|
+
//
|
|
125
|
+
// {{description}}
|
|
126
|
+
//
|
|
127
|
+
// Listens on process.env.PORT (Cloud Run injects this at runtime; 8080 is the
|
|
128
|
+
// local default). The Hono app itself lives in ./app.ts so tests can import it
|
|
129
|
+
// without binding a port.
|
|
130
|
+
|
|
131
|
+
import { serve } from "@hono/node-server";
|
|
132
|
+
|
|
133
|
+
import { app } from "./app.js";
|
|
134
|
+
|
|
135
|
+
// \`||\` not \`??\` — the scaffolded .env seeds PORT="" until filled in, and
|
|
136
|
+
// \`Number("" ?? 8080)\` is \`Number("")\` = 0 (binds a random port). \`||\` falls back.
|
|
137
|
+
const port = Number(process.env.PORT || 8080);
|
|
138
|
+
|
|
139
|
+
serve({ fetch: app.fetch, port }, (info) => {
|
|
140
|
+
// eslint-disable-next-line no-console
|
|
141
|
+
console.log(\`{{slug}} listening on http://localhost:\${info.port}\`);
|
|
142
|
+
});
|
|
143
|
+
`;
|
|
144
|
+
const SRC_APP_TEMPLATE = `// {{slug}} — Hono application.
|
|
145
|
+
//
|
|
146
|
+
// Exported separately from the server entry (index.ts) so tests and other
|
|
147
|
+
// callers can exercise routes via \`app.request(...)\` without starting a server.
|
|
148
|
+
|
|
149
|
+
import { Hono } from "hono";
|
|
150
|
+
|
|
151
|
+
import { health } from "./routes/health.js";
|
|
152
|
+
|
|
153
|
+
export const app = new Hono();
|
|
154
|
+
|
|
155
|
+
app.route("/health", health);
|
|
156
|
+
|
|
157
|
+
app.get("/", (c) => c.json({ service: "{{slug}}", status: "ok" }));
|
|
158
|
+
`;
|
|
159
|
+
const SRC_ROUTES_HEALTH_TEMPLATE = `// DB-free health endpoint for {{slug}}.
|
|
160
|
+
//
|
|
161
|
+
// Per [[neon-postgres]], do NOT add a database roundtrip here. Routine probes
|
|
162
|
+
// from uptime monitors (per [[uptime-kuma-monitor]]) would burn through Neon
|
|
163
|
+
// Free's 100 CU-hour monthly quota and defeat scale-to-zero. If a deeper
|
|
164
|
+
// readiness check is needed, add a separate /health/deep with explicit budget.
|
|
165
|
+
|
|
166
|
+
import { Hono } from "hono";
|
|
167
|
+
|
|
168
|
+
export const health = new Hono();
|
|
169
|
+
|
|
170
|
+
health.get("/", (c) => c.json({ status: "ok" }));
|
|
171
|
+
`;
|
|
172
|
+
const SRC_ROUTES_HEALTH_TEST_TEMPLATE = `import { describe, expect, it } from "vitest";
|
|
173
|
+
|
|
174
|
+
import { app } from "../app.js";
|
|
175
|
+
|
|
176
|
+
describe("GET /health", () => {
|
|
177
|
+
it("returns 200 {status: ok} without touching the database", async () => {
|
|
178
|
+
const res = await app.request("/health");
|
|
179
|
+
expect(res.status).toBe(200);
|
|
180
|
+
expect(await res.json()).toEqual({ status: "ok" });
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
`;
|
|
184
|
+
const DOCKERFILE_TEMPLATE = `# {{slug}} — Cloud Run container.
|
|
185
|
+
#
|
|
186
|
+
# Cloud Run injects the PORT environment variable at runtime (default 8080);
|
|
187
|
+
# src/index.ts listens on it. Multi-stage build keeps the runtime image small
|
|
188
|
+
# (no dev dependencies, no TypeScript sources).
|
|
189
|
+
|
|
190
|
+
FROM node:20-slim AS build
|
|
191
|
+
WORKDIR /app
|
|
192
|
+
COPY package*.json ./
|
|
193
|
+
RUN npm ci
|
|
194
|
+
COPY tsconfig.json ./
|
|
195
|
+
COPY src ./src
|
|
196
|
+
RUN npm run build
|
|
197
|
+
|
|
198
|
+
FROM node:20-slim AS runtime
|
|
199
|
+
WORKDIR /app
|
|
200
|
+
ENV NODE_ENV=production
|
|
201
|
+
COPY package*.json ./
|
|
202
|
+
RUN npm ci --omit=dev
|
|
203
|
+
COPY --from=build /app/dist ./dist
|
|
204
|
+
EXPOSE 8080
|
|
205
|
+
CMD ["node", "dist/index.js"]
|
|
206
|
+
`;
|
|
207
|
+
const DOCKERIGNORE_TEMPLATE = `node_modules
|
|
208
|
+
dist
|
|
209
|
+
.env
|
|
210
|
+
.env.local
|
|
211
|
+
.git
|
|
212
|
+
*.log
|
|
213
|
+
.tmp
|
|
214
|
+
.specstory
|
|
215
|
+
`;
|
|
216
|
+
function buildEnvExample(usesNeon, sendsEmail) {
|
|
217
|
+
const dbLine = usesNeon
|
|
218
|
+
? `# Neon Postgres pooled connection string (required). Per [[neon-postgres]],
|
|
219
|
+
# use the POOLED URL and keep /health DB-free so the compute scales to zero.
|
|
220
|
+
DATABASE_URL=postgresql://user:pass@host/db?sslmode=require
|
|
221
|
+
`
|
|
222
|
+
: `# Database URL (only if this service uses a database). For Neon Postgres, use
|
|
223
|
+
# the pooled connection string per [[neon-postgres]].
|
|
224
|
+
# DATABASE_URL=postgresql://user:pass@host/db?sslmode=require
|
|
225
|
+
`;
|
|
226
|
+
return `# {{slug}} — example environment variables.
|
|
227
|
+
# Copy to \`.env\` (gitignored) and fill in real values. Do NOT commit \`.env\`.
|
|
228
|
+
|
|
229
|
+
# Port the service listens on. Cloud Run overrides this at runtime; 8080 is the
|
|
230
|
+
# Cloud Run default and a sensible local default.
|
|
231
|
+
PORT=8080
|
|
232
|
+
|
|
233
|
+
${dbLine}${sendsEmail ? EMAIL_ENV_BLOCK : ""}`;
|
|
234
|
+
}
|
|
235
|
+
const DRIZZLE_CONFIG_TEMPLATE = `import { defineConfig } from "drizzle-kit";
|
|
236
|
+
|
|
237
|
+
export default defineConfig({
|
|
238
|
+
schema: "./src/db/schema.ts",
|
|
239
|
+
out: "./drizzle",
|
|
240
|
+
dialect: "postgresql",
|
|
241
|
+
dbCredentials: {
|
|
242
|
+
url: process.env.DATABASE_URL!,
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
`;
|
|
246
|
+
const DB_INDEX_TEMPLATE = `// {{slug}} — Drizzle + Neon data layer.
|
|
247
|
+
//
|
|
248
|
+
// Lazy, import-safe DB handle. Per [[portable-stack]] §15, NEVER read
|
|
249
|
+
// DATABASE_URL at module-evaluation time — doing so crashes any import of this
|
|
250
|
+
// module (including the tests and the DB-free /health path) whenever the secret
|
|
251
|
+
// is absent. The client is built on first use and memoized.
|
|
252
|
+
|
|
253
|
+
import { neon } from "@neondatabase/serverless";
|
|
254
|
+
import { drizzle } from "drizzle-orm/neon-http";
|
|
255
|
+
|
|
256
|
+
import * as schema from "./schema.js";
|
|
257
|
+
|
|
258
|
+
let cached: ReturnType<typeof drizzle<typeof schema>> | undefined;
|
|
259
|
+
|
|
260
|
+
export function db(): ReturnType<typeof drizzle<typeof schema>> {
|
|
261
|
+
if (cached) return cached;
|
|
262
|
+
const url = process.env.DATABASE_URL;
|
|
263
|
+
if (!url) {
|
|
264
|
+
throw new Error(
|
|
265
|
+
"DATABASE_URL is not set. Set it in .env (local) or the Cloud Run service environment.",
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
cached = drizzle(neon(url), { schema });
|
|
269
|
+
return cached;
|
|
270
|
+
}
|
|
271
|
+
`;
|
|
272
|
+
const DB_SCHEMA_TEMPLATE = `// Drizzle schema for {{slug}}.
|
|
273
|
+
//
|
|
274
|
+
// Replace this placeholder table with the real schema as the service takes
|
|
275
|
+
// shape. Per [[portable-stack]], keep to standard Postgres types so the schema
|
|
276
|
+
// ports to any Postgres host (no Neon-/host-specific column types).
|
|
277
|
+
|
|
278
|
+
import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
|
|
279
|
+
|
|
280
|
+
export const example = pgTable("example", {
|
|
281
|
+
id: serial("id").primaryKey(),
|
|
282
|
+
name: text("name").notNull(),
|
|
283
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
284
|
+
.defaultNow()
|
|
285
|
+
.notNull(),
|
|
286
|
+
});
|
|
287
|
+
`;
|
|
288
|
+
export function scaffoldNodeService(inputs, opts) {
|
|
289
|
+
const spec = resolveBrandSpec(inputs);
|
|
290
|
+
const usesNeon = inputs.dbStrategy === "neon-postgres";
|
|
291
|
+
const sendsEmail = inputs.sendsEmail === true;
|
|
292
|
+
const base = commonBaseFiles(inputs, opts, buildNarrative(usesNeon));
|
|
293
|
+
const envExample = sub(buildEnvExample(usesNeon, sendsEmail), inputs, opts, spec);
|
|
294
|
+
const typeSpecific = [
|
|
295
|
+
{ path: "package.json", content: sub(buildPackageJson(usesNeon, sendsEmail), inputs, opts, spec) },
|
|
296
|
+
{ path: "tsconfig.json", content: sub(TSCONFIG_TEMPLATE, inputs, opts, spec) },
|
|
297
|
+
{ path: "vitest.config.ts", content: sub(VITEST_CONFIG_TEMPLATE, inputs, opts, spec) },
|
|
298
|
+
{ path: "src/index.ts", content: sub(SRC_INDEX_TEMPLATE, inputs, opts, spec) },
|
|
299
|
+
{ path: "src/app.ts", content: sub(SRC_APP_TEMPLATE, inputs, opts, spec) },
|
|
300
|
+
{
|
|
301
|
+
path: "src/routes/health.ts",
|
|
302
|
+
content: sub(SRC_ROUTES_HEALTH_TEMPLATE, inputs, opts, spec),
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
path: "src/routes/health.test.ts",
|
|
306
|
+
content: sub(SRC_ROUTES_HEALTH_TEST_TEMPLATE, inputs, opts, spec),
|
|
307
|
+
},
|
|
308
|
+
{ path: "Dockerfile", content: sub(DOCKERFILE_TEMPLATE, inputs, opts, spec) },
|
|
309
|
+
{ path: ".dockerignore", content: DOCKERIGNORE_TEMPLATE },
|
|
310
|
+
{ path: ".env.example", content: envExample },
|
|
311
|
+
{ path: ".env", content: localEnvFrom(envExample, ".env", inputs.slug) },
|
|
312
|
+
];
|
|
313
|
+
if (usesNeon) {
|
|
314
|
+
typeSpecific.push({ path: "drizzle.config.ts", content: sub(DRIZZLE_CONFIG_TEMPLATE, inputs, opts, spec) }, { path: "src/db/index.ts", content: sub(DB_INDEX_TEMPLATE, inputs, opts, spec) }, { path: "src/db/schema.ts", content: sub(DB_SCHEMA_TEMPLATE, inputs, opts, spec) });
|
|
315
|
+
}
|
|
316
|
+
if (sendsEmail) {
|
|
317
|
+
typeSpecific.push(...emailFiles(inputs, opts, spec, "node-service"));
|
|
318
|
+
}
|
|
319
|
+
return [...base, ...typeSpecific];
|
|
320
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ScaffoldInputs } from "../index.js";
|
|
2
|
+
import type { ScaffoldFile } from "./common.js";
|
|
3
|
+
export declare const PRO_SEO_BASELINE_PATHS: readonly ["src/seo/json-ld.ts", "scripts/seo-audit.mjs", "scripts/og-image-gen.mjs", "scripts/link-rot.mjs", ".github/workflows/perf-budgets.yml", "PRO_SEO_README.md"];
|
|
4
|
+
/**
|
|
5
|
+
* Returns whether the Pro SEO extension applies to a given project type.
|
|
6
|
+
* Only nextjs + cf-pages have a free SEO baseline to extend; other types
|
|
7
|
+
* either have no public web surface (library, protocol-repo, cf-worker,
|
|
8
|
+
* python-service) or use a non-Next.js SEO stack (wp-plugin → RankMath).
|
|
9
|
+
*/
|
|
10
|
+
export declare function proSeoApplies(inputs: ScaffoldInputs): boolean;
|
|
11
|
+
export declare function buildProSeoExtension(inputs: ScaffoldInputs): ScaffoldFile[];
|