@marktiderman/genesis-cli 1.0.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/dist/index.js ADDED
@@ -0,0 +1,344 @@
1
+ // src/scaffolder.ts
2
+ var VALID_NAME_PATTERN = /^[a-z][a-z0-9-]{1,30}$/;
3
+ var NOOP_LOGGER = {
4
+ info() {
5
+ },
6
+ warn() {
7
+ },
8
+ error() {
9
+ }
10
+ };
11
+ function validateConsumerName(name) {
12
+ if (!VALID_NAME_PATTERN.test(name)) {
13
+ throw new Error(
14
+ `Invalid consumer name "${name}". Must be lowercase letters/digits/hyphens, 2-31 chars, starting with a letter (e.g., "sanctiv", "gamify-mobile").`
15
+ );
16
+ }
17
+ }
18
+ function planScaffold(opts) {
19
+ const consumer = opts.consumerName;
20
+ const genesisVersion = opts.genesisVersion ?? "workspace:^";
21
+ return [
22
+ {
23
+ path: `packages/${consumer}-brand/package.json`,
24
+ content: brandPackageJson(consumer, genesisVersion)
25
+ },
26
+ {
27
+ path: `packages/${consumer}-brand/src/brand.ts`,
28
+ content: brandSchema(consumer)
29
+ },
30
+ {
31
+ path: `packages/${consumer}-brand/src/index.ts`,
32
+ content: `export { brand } from "./brand";
33
+ export type { Brand } from "./brand";
34
+ `
35
+ },
36
+ {
37
+ path: `packages/${consumer}-brand/tsconfig.json`,
38
+ content: brandTsconfig()
39
+ },
40
+ {
41
+ path: `tailwind.config.ts`,
42
+ content: tailwindConfig(consumer)
43
+ },
44
+ {
45
+ path: `app/global.css`,
46
+ content: globalCss()
47
+ },
48
+ {
49
+ path: `.genesis/config.yml`,
50
+ content: genesisConfig(consumer)
51
+ },
52
+ {
53
+ path: `CLAUDE.md`,
54
+ content: claudeMd(consumer)
55
+ }
56
+ ];
57
+ }
58
+ async function runScaffold(opts, fs) {
59
+ validateConsumerName(opts.consumerName);
60
+ const log = opts.logger ?? NOOP_LOGGER;
61
+ const plan = planScaffold(opts);
62
+ const written = [];
63
+ const skipped = [];
64
+ const conflicts = [];
65
+ for (const file of plan) {
66
+ const fullPath = joinPath(opts.targetDir, file.path);
67
+ const dir = dirname(fullPath);
68
+ await fs.mkdirp(dir);
69
+ const exists = await fs.exists(fullPath);
70
+ if (!exists) {
71
+ await fs.writeFile(fullPath, file.content);
72
+ written.push(file.path);
73
+ log.info(`\u2714 wrote ${file.path}`);
74
+ continue;
75
+ }
76
+ const existing = await fs.readFile(fullPath);
77
+ if (existing === file.content) {
78
+ skipped.push(file.path);
79
+ log.info(`= skipped ${file.path} (identical)`);
80
+ continue;
81
+ }
82
+ if (opts.emitConflicts) {
83
+ const nextPath = `${fullPath}.genesis-next`;
84
+ await fs.writeFile(nextPath, file.content);
85
+ conflicts.push(`${file.path}.genesis-next`);
86
+ log.warn(
87
+ `! diff ${file.path} \u2014 wrote .genesis-next sibling for review`
88
+ );
89
+ } else {
90
+ skipped.push(file.path);
91
+ log.warn(
92
+ `! skipped ${file.path} (exists; pass --emit-conflicts to diff)`
93
+ );
94
+ }
95
+ }
96
+ return { written, skipped, conflicts };
97
+ }
98
+ function joinPath(...parts) {
99
+ return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
100
+ }
101
+ function dirname(path) {
102
+ const idx = path.lastIndexOf("/");
103
+ return idx === -1 ? "." : path.slice(0, idx);
104
+ }
105
+ function brandPackageJson(consumer, genesisVersion) {
106
+ return JSON.stringify(
107
+ {
108
+ name: `@${consumer}/brand`,
109
+ version: "0.1.0",
110
+ private: true,
111
+ type: "module",
112
+ main: "./src/index.ts",
113
+ types: "./src/index.ts",
114
+ description: `Brand tokens + extensions for the ${consumer} app. Consumed by Genesis primitives via canonical schema.`,
115
+ peerDependencies: {
116
+ "@marktiderman/genesis-design-system": genesisVersion
117
+ }
118
+ },
119
+ null,
120
+ 2
121
+ ) + "\n";
122
+ }
123
+ function brandTsconfig() {
124
+ return JSON.stringify(
125
+ {
126
+ extends: "../../tsconfig.base.json",
127
+ compilerOptions: {
128
+ outDir: "dist",
129
+ rootDir: "src"
130
+ },
131
+ include: ["src"]
132
+ },
133
+ null,
134
+ 2
135
+ ) + "\n";
136
+ }
137
+ function brandSchema(consumer) {
138
+ return `/**
139
+ * @${consumer}/brand \u2014 canonical brand tokens + extensions.
140
+ *
141
+ * Genesis primitives consume tokens from this file via the design-system
142
+ * provider. Edit colors/spacing/typography here to retheme every screen
143
+ * at once. Domain-specific tokens (e.g., "mood" for Sanctiv, "rarity" for
144
+ * Gamify) go under \`extensions\` \u2014 Genesis primitives don't read these,
145
+ * but consumer composites do via \`useGenesisExtension(key)\`.
146
+ *
147
+ * Schema is intentionally narrow at the top level. Add categories under
148
+ * \`extensions\` rather than inventing new top-level slots.
149
+ */
150
+
151
+ export interface BrandColorScale {
152
+ 50: string;
153
+ 100: string;
154
+ 200: string;
155
+ 300: string;
156
+ 400: string;
157
+ 500: string;
158
+ 600: string;
159
+ 700: string;
160
+ 800: string;
161
+ 900: string;
162
+ }
163
+
164
+ export interface BrandColors {
165
+ primary: BrandColorScale;
166
+ destructive: BrandColorScale;
167
+ /** Neutral / gray scale used for surfaces, text, borders. */
168
+ neutral: BrandColorScale;
169
+ }
170
+
171
+ export interface Brand {
172
+ /** Slug used for namespacing (e.g., extensions key prefix). */
173
+ name: string;
174
+ colors: BrandColors;
175
+ /**
176
+ * Domain-specific token categories. Consumer composites read these
177
+ * via \`useGenesisExtension("<key>")\`. Genesis primitives do NOT read
178
+ * extensions \u2014 only canonical \`colors\`.
179
+ */
180
+ extensions?: Record<string, Record<string | number, unknown>>;
181
+ }
182
+
183
+ // ---------------------------------------------------------------------------
184
+ // Default brand \u2014 replace these placeholder values with your design's
185
+ // actual hex values. The canonical schema is the only contract; how you
186
+ // reach it is up to you (Figma export, hand-pick, generated from a base).
187
+ // ---------------------------------------------------------------------------
188
+
189
+ export const brand: Brand = {
190
+ name: "${consumer}",
191
+ colors: {
192
+ primary: {
193
+ 50: "#eff6ff",
194
+ 100: "#dbeafe",
195
+ 200: "#bfdbfe",
196
+ 300: "#93c5fd",
197
+ 400: "#60a5fa",
198
+ 500: "#3b82f6",
199
+ 600: "#2563eb",
200
+ 700: "#1d4ed8",
201
+ 800: "#1e40af",
202
+ 900: "#1e3a8a",
203
+ },
204
+ destructive: {
205
+ 50: "#fef2f2",
206
+ 100: "#fee2e2",
207
+ 200: "#fecaca",
208
+ 300: "#fca5a5",
209
+ 400: "#f87171",
210
+ 500: "#ef4444",
211
+ 600: "#dc2626",
212
+ 700: "#b91c1c",
213
+ 800: "#991b1b",
214
+ 900: "#7f1d1d",
215
+ },
216
+ neutral: {
217
+ 50: "#f9fafb",
218
+ 100: "#f3f4f6",
219
+ 200: "#e5e7eb",
220
+ 300: "#d1d5db",
221
+ 400: "#9ca3af",
222
+ 500: "#6b7280",
223
+ 600: "#4b5563",
224
+ 700: "#374151",
225
+ 800: "#1f2937",
226
+ 900: "#111827",
227
+ },
228
+ },
229
+ // extensions: { mood: { ... }, rarity: { ... } },
230
+ };
231
+ `;
232
+ }
233
+ function tailwindConfig(consumer) {
234
+ return `import type { Config } from "tailwindcss";
235
+ import { brand } from "@${consumer}/brand";
236
+
237
+ /**
238
+ * Tailwind config \u2014 wires Genesis canonical tokens to your brand values.
239
+ *
240
+ * Genesis ships a tailwind preset that maps semantic class names
241
+ * (\`bg-primary\`, \`text-foreground\`, etc.) to CSS variables. This config
242
+ * extends that preset with your consumer's hex values, so Genesis
243
+ * primitives automatically pick up your brand once the global.css import
244
+ * fires.
245
+ */
246
+ const config: Config = {
247
+ content: [
248
+ "./app/**/*.{ts,tsx}",
249
+ "./components/**/*.{ts,tsx}",
250
+ "./node_modules/@marktiderman/genesis-ui-native/**/*.{js,ts,tsx}",
251
+ ],
252
+ presets: [require("@marktiderman/genesis-design-system/tailwind-preset")],
253
+ theme: {
254
+ extend: {
255
+ colors: {
256
+ primary: {
257
+ DEFAULT: brand.colors.primary[600],
258
+ ...brand.colors.primary,
259
+ },
260
+ destructive: {
261
+ DEFAULT: brand.colors.destructive[600],
262
+ ...brand.colors.destructive,
263
+ },
264
+ },
265
+ },
266
+ },
267
+ };
268
+
269
+ export default config;
270
+ `;
271
+ }
272
+ function globalCss() {
273
+ return `/**
274
+ * Genesis global stylesheet entry. Imports the canonical token sheet
275
+ * + the consumer's tailwind layers. The token sheet wires CSS variables
276
+ * (--color-primary, --color-foreground, etc.) used by every Genesis
277
+ * primitive's tailwind classes.
278
+ */
279
+ @import "@marktiderman/genesis-design-system/tokens.css";
280
+ @tailwind base;
281
+ @tailwind components;
282
+ @tailwind utilities;
283
+ `;
284
+ }
285
+ function genesisConfig(consumer) {
286
+ return `# Genesis consumer config \u2014 read by genesis CLI + .claude/hooks/*
287
+ #
288
+ # version pin: which @marktiderman/genesis-* major are we on. The genesis CLI
289
+ # uses this to validate that an upgrade hasn't drifted past breaking-change
290
+ # boundaries.
291
+ version: "1"
292
+ consumer: "${consumer}"
293
+
294
+ rules:
295
+ # Block raw hex in consumer code \u2014 must use brand tokens.
296
+ no-raw-hex: error
297
+ # Block StyleSheet.create() in NativeWind-first projects.
298
+ no-stylesheet-create: error
299
+ # Block fork-and-modify of Genesis primitives.
300
+ no-genesis-fork: error
301
+ # Layouts must compose Genesis primitives, not rebuild them.
302
+ prefer-genesis-layout: warn
303
+
304
+ # Path map \u2014 where consumer composites + brand live. Default values match
305
+ # the scaffolder's output; adjust if your layout differs.
306
+ paths:
307
+ brand: "packages/${consumer}-brand"
308
+ composites: "components"
309
+ app: "app"
310
+ `;
311
+ }
312
+ function claudeMd(consumer) {
313
+ return `# CLAUDE.md \u2014 ${consumer}
314
+
315
+ This consumer was bootstrapped with \`@marktiderman/genesis-cli init ${consumer}\`.
316
+
317
+ ## Workflow
318
+
319
+ - **Reuse before extend, extend before create.** See the Genesis usage
320
+ doctrine: \`docs/prds/PRD-07-genesis-consumption-architecture/standards/usage-doctrine.md\`
321
+ - **Brand changes live in \`packages/${consumer}-brand\`.** Don't fork Genesis
322
+ primitives \u2014 edit your brand schema instead (Layer 1).
323
+ - **Layout customization has 4 layers.** Default \u2192 named props \u2192
324
+ ScreenContainer \u2192 brand schema. Reach for the lowest layer first.
325
+
326
+ ## Critical rules
327
+
328
+ - \`.genesis/config.yml\` rules are enforced via Claude Code hooks. Don't
329
+ bypass with \`StyleSheet.create()\` or raw hex; use brand tokens.
330
+ - Run \`pnpm test\` before every commit.
331
+ - Open RFCs in the genesis repo for missing primitives \u2014 don't fork
332
+ locally and forget.
333
+
334
+ ## Quick reference
335
+
336
+ - \`packages/${consumer}-brand/src/brand.ts\` \u2014 your brand tokens + extensions
337
+ - \`tailwind.config.ts\` \u2014 Genesis preset + brand color overrides
338
+ - \`app/global.css\` \u2014 Genesis token sheet + tailwind layers
339
+ `;
340
+ }
341
+
342
+ export { planScaffold, runScaffold, validateConsumerName };
343
+ //# sourceMappingURL=index.js.map
344
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/scaffolder.ts"],"names":[],"mappings":";AAgEA,IAAM,kBAAA,GAAqB,wBAAA;AAE3B,IAAM,WAAA,GAA8B;AAAA,EAClC,IAAA,GAAO;AAAA,EAAC,CAAA;AAAA,EACR,IAAA,GAAO;AAAA,EAAC,CAAA;AAAA,EACR,KAAA,GAAQ;AAAA,EAAC;AACX,CAAA;AAQO,SAAS,qBAAqB,IAAA,EAAoB;AACvD,EAAA,IAAI,CAAC,kBAAA,CAAmB,IAAA,CAAK,IAAI,CAAA,EAAG;AAClC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,0BAA0B,IAAI,CAAA,mHAAA;AAAA,KAEhC;AAAA,EACF;AACF;AAMO,SAAS,aACd,IAAA,EACqC;AACrC,EAAA,MAAM,WAAW,IAAA,CAAK,YAAA;AACtB,EAAA,MAAM,cAAA,GAAiB,KAAK,cAAA,IAAkB,aAAA;AAC9C,EAAA,OAAO;AAAA,IACL;AAAA,MACE,IAAA,EAAM,YAAY,QAAQ,CAAA,mBAAA,CAAA;AAAA,MAC1B,OAAA,EAAS,gBAAA,CAAiB,QA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A;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA,mBAAA,EAeA,QAAQ,CAAA;AAAA;AAAA;AAAA,CAAA;AAI7B;AAEA,SAAS,SAAS,QAAA,EAA0B;AAC1C,EAAA,OAAO,sBAAiB,QAAQ;;AAAA,qEAAA,EAEqC,QAAQ,CAAA;;AAAA;;AAAA;AAAA;AAAA,qCAAA,EAMxC,QAAQ,CAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA,aAAA,EAehC,QAAQ,CAAA;AAAA;AAAA;AAAA,CAAA;AAIvB","file":"index.js","sourcesContent":["/**\n * Genesis init scaffolder — pure-function core.\n *\n * `runScaffolder()` takes a plan (consumer name, target dir, options) +\n * a filesystem implementation, and writes the files needed to bootstrap\n * a new Genesis-based app:\n *\n * - `packages/<consumer>-brand/src/brand.ts` (canonical schema seed)\n * - `packages/<consumer>-brand/package.json`\n * - `tailwind.config.ts` (genesis preset import)\n * - `app/global.css` (genesis tokens import)\n * - `.genesis/config.yml` (rules + version pin)\n * - `CLAUDE.md` (cross-link + workflow)\n *\n * Idempotent: existing files are NOT overwritten. The scaffolder reads\n * each target path first; if present, it appends a `.genesis-next` sibling\n * with the would-be content + emits a warning so the caller can diff. This\n * keeps the operation safe to re-run after upstream Genesis updates.\n *\n * The CLI wraps this with a real `node:fs` impl + commander argument\n * parsing; the test harness wraps it with an in-memory map for fast,\n * deterministic tests.\n *\n * @stability Beta\n */\n\nexport interface FileSystem {\n exists(path: string): Promise<boolean>;\n readFile(path: string): Promise<string>;\n writeFile(path: string, content: string): Promise<void>;\n mkdirp(dir: string): Promise<void>;\n}\n\nexport interface ScaffoldOptions {\n /** Slug used for `<consumer>-brand` package + tokens namespace. */\n consumerName: string;\n /** Target directory the scaffold writes into. Default `process.cwd()`. */\n targetDir: string;\n /** Pin Genesis package version. Default `\"workspace:^\"` if monorepo, else `\"^1.0.0\"`. */\n genesisVersion?: string;\n /** When true, even idempotent skips emit a write at `.genesis-next` for diffing. */\n emitConflicts?: boolean;\n /**\n * Logger. Defaults to a no-op when running in tests; CLI passes\n * `console.log` etc.\n */\n logger?: ScaffoldLogger;\n}\n\nexport interface ScaffoldLogger {\n info(msg: string): void;\n warn(msg: string): void;\n error(msg: string): void;\n}\n\nexport interface ScaffoldResult {\n /** Paths the scaffolder wrote. */\n written: string[];\n /** Paths that already existed and were left alone (idempotent skip). */\n skipped: string[];\n /** Paths emitted as `.genesis-next` for consumer to diff. */\n conflicts: string[];\n}\n\nconst VALID_NAME_PATTERN = /^[a-z][a-z0-9-]{1,30}$/;\n\nconst NOOP_LOGGER: ScaffoldLogger = {\n info() {},\n warn() {},\n error() {},\n};\n\n/**\n * Validate a consumer slug. Throws if invalid.\n *\n * Rules: lowercase alphanumeric + hyphens, 2-31 chars, must start with letter.\n * Matches the npm package-name subset that's also a safe directory name.\n */\nexport function validateConsumerName(name: string): void {\n if (!VALID_NAME_PATTERN.test(name)) {\n throw new Error(\n `Invalid consumer name \"${name}\". Must be lowercase letters/digits/hyphens, ` +\n `2-31 chars, starting with a letter (e.g., \"sanctiv\", \"gamify-mobile\").`,\n );\n }\n}\n\n/**\n * Compute which files the scaffolder would write for a given plan.\n * Pure function — no I/O. Tests use this directly.\n */\nexport function planScaffold(\n opts: Pick<ScaffoldOptions, \"consumerName\" | \"genesisVersion\">,\n): { path: string; content: string }[] {\n const consumer = opts.consumerName;\n const genesisVersion = opts.genesisVersion ?? \"workspace:^\";\n return [\n {\n path: `packages/${consumer}-brand/package.json`,\n content: brandPackageJson(consumer, genesisVersion),\n },\n {\n path: `packages/${consumer}-brand/src/brand.ts`,\n content: brandSchema(consumer),\n },\n {\n path: `packages/${consumer}-brand/src/index.ts`,\n content: `export { brand } from \"./brand\";\\nexport type { Brand } from \"./brand\";\\n`,\n },\n {\n path: `packages/${consumer}-brand/tsconfig.json`,\n content: brandTsconfig(),\n },\n {\n path: `tailwind.config.ts`,\n content: tailwindConfig(consumer),\n },\n {\n path: `app/global.css`,\n content: globalCss(),\n },\n {\n path: `.genesis/config.yml`,\n content: genesisConfig(consumer),\n },\n {\n path: `CLAUDE.md`,\n content: claudeMd(consumer),\n },\n ];\n}\n\n/**\n * Run the scaffolder against a FileSystem implementation. Returns a\n * record of what it did so the CLI / test harness can summarize.\n */\nexport async function runScaffold(\n opts: ScaffoldOptions,\n fs: FileSystem,\n): Promise<ScaffoldResult> {\n validateConsumerName(opts.consumerName);\n const log = opts.logger ?? NOOP_LOGGER;\n\n const plan = planScaffold(opts);\n\n const written: string[] = [];\n const skipped: string[] = [];\n const conflicts: string[] = [];\n\n for (const file of plan) {\n const fullPath = joinPath(opts.targetDir, file.path);\n const dir = dirname(fullPath);\n await fs.mkdirp(dir);\n\n const exists = await fs.exists(fullPath);\n if (!exists) {\n await fs.writeFile(fullPath, file.content);\n written.push(file.path);\n log.info(`✔ wrote ${file.path}`);\n continue;\n }\n\n // Idempotent skip — file exists. Optionally drop a `.genesis-next`\n // sibling so consumers can diff.\n const existing = await fs.readFile(fullPath);\n if (existing === file.content) {\n skipped.push(file.path);\n log.info(`= skipped ${file.path} (identical)`);\n continue;\n }\n\n if (opts.emitConflicts) {\n const nextPath = `${fullPath}.genesis-next`;\n await fs.writeFile(nextPath, file.content);\n conflicts.push(`${file.path}.genesis-next`);\n log.warn(\n `! diff ${file.path} — wrote .genesis-next sibling for review`,\n );\n } else {\n skipped.push(file.path);\n log.warn(\n `! skipped ${file.path} (exists; pass --emit-conflicts to diff)`,\n );\n }\n }\n\n return { written, skipped, conflicts };\n}\n\n// ---------------------------------------------------------------------------\n// Path helpers — kept inline so the scaffolder has zero non-commander deps\n// ---------------------------------------------------------------------------\n\nfunction joinPath(...parts: string[]): string {\n return parts\n .filter(Boolean)\n .join(\"/\")\n .replace(/\\/+/g, \"/\");\n}\n\nfunction dirname(path: string): string {\n const idx = path.lastIndexOf(\"/\");\n return idx === -1 ? \".\" : path.slice(0, idx);\n}\n\n// ---------------------------------------------------------------------------\n// Templates — readable string builders, NOT freeze-dried .tpl files. This\n// keeps the scaffolder a single .ts file and avoids __dirname juggling\n// when we publish to npm.\n// ---------------------------------------------------------------------------\n\nfunction brandPackageJson(consumer: string, genesisVersion: string): string {\n return JSON.stringify(\n {\n name: `@${consumer}/brand`,\n version: \"0.1.0\",\n private: true,\n type: \"module\",\n main: \"./src/index.ts\",\n types: \"./src/index.ts\",\n description: `Brand tokens + extensions for the ${consumer} app. Consumed by Genesis primitives via canonical schema.`,\n peerDependencies: {\n \"@marktiderman/genesis-design-system\": genesisVersion,\n },\n },\n null,\n 2,\n ) + \"\\n\";\n}\n\nfunction brandTsconfig(): string {\n return JSON.stringify(\n {\n extends: \"../../tsconfig.base.json\",\n compilerOptions: {\n outDir: \"dist\",\n rootDir: \"src\",\n },\n include: [\"src\"],\n },\n null,\n 2,\n ) + \"\\n\";\n}\n\nfunction brandSchema(consumer: string): string {\n return `/**\n * @${consumer}/brand — canonical brand tokens + extensions.\n *\n * Genesis primitives consume tokens from this file via the design-system\n * provider. Edit colors/spacing/typography here to retheme every screen\n * at once. Domain-specific tokens (e.g., \"mood\" for Sanctiv, \"rarity\" for\n * Gamify) go under \\`extensions\\` — Genesis primitives don't read these,\n * but consumer composites do via \\`useGenesisExtension(key)\\`.\n *\n * Schema is intentionally narrow at the top level. Add categories under\n * \\`extensions\\` rather than inventing new top-level slots.\n */\n\nexport interface BrandColorScale {\n 50: string;\n 100: string;\n 200: string;\n 300: string;\n 400: string;\n 500: string;\n 600: string;\n 700: string;\n 800: string;\n 900: string;\n}\n\nexport interface BrandColors {\n primary: BrandColorScale;\n destructive: BrandColorScale;\n /** Neutral / gray scale used for surfaces, text, borders. */\n neutral: BrandColorScale;\n}\n\nexport interface Brand {\n /** Slug used for namespacing (e.g., extensions key prefix). */\n name: string;\n colors: BrandColors;\n /**\n * Domain-specific token categories. Consumer composites read these\n * via \\`useGenesisExtension(\"<key>\")\\`. Genesis primitives do NOT read\n * extensions — only canonical \\`colors\\`.\n */\n extensions?: Record<string, Record<string | number, unknown>>;\n}\n\n// ---------------------------------------------------------------------------\n// Default brand — replace these placeholder values with your design's\n// actual hex values. The canonical schema is the only contract; how you\n// reach it is up to you (Figma export, hand-pick, generated from a base).\n// ---------------------------------------------------------------------------\n\nexport const brand: Brand = {\n name: \"${consumer}\",\n colors: {\n primary: {\n 50: \"#eff6ff\",\n 100: \"#dbeafe\",\n 200: \"#bfdbfe\",\n 300: \"#93c5fd\",\n 400: \"#60a5fa\",\n 500: \"#3b82f6\",\n 600: \"#2563eb\",\n 700: \"#1d4ed8\",\n 800: \"#1e40af\",\n 900: \"#1e3a8a\",\n },\n destructive: {\n 50: \"#fef2f2\",\n 100: \"#fee2e2\",\n 200: \"#fecaca\",\n 300: \"#fca5a5\",\n 400: \"#f87171\",\n 500: \"#ef4444\",\n 600: \"#dc2626\",\n 700: \"#b91c1c\",\n 800: \"#991b1b\",\n 900: \"#7f1d1d\",\n },\n neutral: {\n 50: \"#f9fafb\",\n 100: \"#f3f4f6\",\n 200: \"#e5e7eb\",\n 300: \"#d1d5db\",\n 400: \"#9ca3af\",\n 500: \"#6b7280\",\n 600: \"#4b5563\",\n 700: \"#374151\",\n 800: \"#1f2937\",\n 900: \"#111827\",\n },\n },\n // extensions: { mood: { ... }, rarity: { ... } },\n};\n`;\n}\n\nfunction tailwindConfig(consumer: string): string {\n return `import type { Config } from \"tailwindcss\";\nimport { brand } from \"@${consumer}/brand\";\n\n/**\n * Tailwind config — wires Genesis canonical tokens to your brand values.\n *\n * Genesis ships a tailwind preset that maps semantic class names\n * (\\`bg-primary\\`, \\`text-foreground\\`, etc.) to CSS variables. This config\n * extends that preset with your consumer's hex values, so Genesis\n * primitives automatically pick up your brand once the global.css import\n * fires.\n */\nconst config: Config = {\n content: [\n \"./app/**/*.{ts,tsx}\",\n \"./components/**/*.{ts,tsx}\",\n \"./node_modules/@marktiderman/genesis-ui-native/**/*.{js,ts,tsx}\",\n ],\n presets: [require(\"@marktiderman/genesis-design-system/tailwind-preset\")],\n theme: {\n extend: {\n colors: {\n primary: {\n DEFAULT: brand.colors.primary[600],\n ...brand.colors.primary,\n },\n destructive: {\n DEFAULT: brand.colors.destructive[600],\n ...brand.colors.destructive,\n },\n },\n },\n },\n};\n\nexport default config;\n`;\n}\n\nfunction globalCss(): string {\n return `/**\n * Genesis global stylesheet entry. Imports the canonical token sheet\n * + the consumer's tailwind layers. The token sheet wires CSS variables\n * (--color-primary, --color-foreground, etc.) used by every Genesis\n * primitive's tailwind classes.\n */\n@import \"@marktiderman/genesis-design-system/tokens.css\";\n@tailwind base;\n@tailwind components;\n@tailwind utilities;\n`;\n}\n\nfunction genesisConfig(consumer: string): string {\n return `# Genesis consumer config — read by genesis CLI + .claude/hooks/*\n#\n# version pin: which @marktiderman/genesis-* major are we on. The genesis CLI\n# uses this to validate that an upgrade hasn't drifted past breaking-change\n# boundaries.\nversion: \"1\"\nconsumer: \"${consumer}\"\n\nrules:\n # Block raw hex in consumer code — must use brand tokens.\n no-raw-hex: error\n # Block StyleSheet.create() in NativeWind-first projects.\n no-stylesheet-create: error\n # Block fork-and-modify of Genesis primitives.\n no-genesis-fork: error\n # Layouts must compose Genesis primitives, not rebuild them.\n prefer-genesis-layout: warn\n\n# Path map — where consumer composites + brand live. Default values match\n# the scaffolder's output; adjust if your layout differs.\npaths:\n brand: \"packages/${consumer}-brand\"\n composites: \"components\"\n app: \"app\"\n`;\n}\n\nfunction claudeMd(consumer: string): string {\n return `# CLAUDE.md — ${consumer}\n\nThis consumer was bootstrapped with \\`@marktiderman/genesis-cli init ${consumer}\\`.\n\n## Workflow\n\n- **Reuse before extend, extend before create.** See the Genesis usage\n doctrine: \\`docs/prds/PRD-07-genesis-consumption-architecture/standards/usage-doctrine.md\\`\n- **Brand changes live in \\`packages/${consumer}-brand\\`.** Don't fork Genesis\n primitives — edit your brand schema instead (Layer 1).\n- **Layout customization has 4 layers.** Default → named props →\n ScreenContainer → brand schema. Reach for the lowest layer first.\n\n## Critical rules\n\n- \\`.genesis/config.yml\\` rules are enforced via Claude Code hooks. Don't\n bypass with \\`StyleSheet.create()\\` or raw hex; use brand tokens.\n- Run \\`pnpm test\\` before every commit.\n- Open RFCs in the genesis repo for missing primitives — don't fork\n locally and forget.\n\n## Quick reference\n\n- \\`packages/${consumer}-brand/src/brand.ts\\` — your brand tokens + extensions\n- \\`tailwind.config.ts\\` — Genesis preset + brand color overrides\n- \\`app/global.css\\` — Genesis token sheet + tailwind layers\n`;\n}\n"]}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Genesis init scaffolder — pure-function core.
3
+ *
4
+ * `runScaffolder()` takes a plan (consumer name, target dir, options) +
5
+ * a filesystem implementation, and writes the files needed to bootstrap
6
+ * a new Genesis-based app:
7
+ *
8
+ * - `packages/<consumer>-brand/src/brand.ts` (canonical schema seed)
9
+ * - `packages/<consumer>-brand/package.json`
10
+ * - `tailwind.config.ts` (genesis preset import)
11
+ * - `app/global.css` (genesis tokens import)
12
+ * - `.genesis/config.yml` (rules + version pin)
13
+ * - `CLAUDE.md` (cross-link + workflow)
14
+ *
15
+ * Idempotent: existing files are NOT overwritten. The scaffolder reads
16
+ * each target path first; if present, it appends a `.genesis-next` sibling
17
+ * with the would-be content + emits a warning so the caller can diff. This
18
+ * keeps the operation safe to re-run after upstream Genesis updates.
19
+ *
20
+ * The CLI wraps this with a real `node:fs` impl + commander argument
21
+ * parsing; the test harness wraps it with an in-memory map for fast,
22
+ * deterministic tests.
23
+ *
24
+ * @stability Beta
25
+ */
26
+ interface FileSystem {
27
+ exists(path: string): Promise<boolean>;
28
+ readFile(path: string): Promise<string>;
29
+ writeFile(path: string, content: string): Promise<void>;
30
+ mkdirp(dir: string): Promise<void>;
31
+ }
32
+ interface ScaffoldOptions {
33
+ /** Slug used for `<consumer>-brand` package + tokens namespace. */
34
+ consumerName: string;
35
+ /** Target directory the scaffold writes into. Default `process.cwd()`. */
36
+ targetDir: string;
37
+ /** Pin Genesis package version. Default `"workspace:^"` if monorepo, else `"^1.0.0"`. */
38
+ genesisVersion?: string;
39
+ /** When true, even idempotent skips emit a write at `.genesis-next` for diffing. */
40
+ emitConflicts?: boolean;
41
+ /**
42
+ * Logger. Defaults to a no-op when running in tests; CLI passes
43
+ * `console.log` etc.
44
+ */
45
+ logger?: ScaffoldLogger;
46
+ }
47
+ interface ScaffoldLogger {
48
+ info(msg: string): void;
49
+ warn(msg: string): void;
50
+ error(msg: string): void;
51
+ }
52
+ interface ScaffoldResult {
53
+ /** Paths the scaffolder wrote. */
54
+ written: string[];
55
+ /** Paths that already existed and were left alone (idempotent skip). */
56
+ skipped: string[];
57
+ /** Paths emitted as `.genesis-next` for consumer to diff. */
58
+ conflicts: string[];
59
+ }
60
+ /**
61
+ * Validate a consumer slug. Throws if invalid.
62
+ *
63
+ * Rules: lowercase alphanumeric + hyphens, 2-31 chars, must start with letter.
64
+ * Matches the npm package-name subset that's also a safe directory name.
65
+ */
66
+ declare function validateConsumerName(name: string): void;
67
+ /**
68
+ * Compute which files the scaffolder would write for a given plan.
69
+ * Pure function — no I/O. Tests use this directly.
70
+ */
71
+ declare function planScaffold(opts: Pick<ScaffoldOptions, "consumerName" | "genesisVersion">): {
72
+ path: string;
73
+ content: string;
74
+ }[];
75
+ /**
76
+ * Run the scaffolder against a FileSystem implementation. Returns a
77
+ * record of what it did so the CLI / test harness can summarize.
78
+ */
79
+ declare function runScaffold(opts: ScaffoldOptions, fs: FileSystem): Promise<ScaffoldResult>;
80
+
81
+ export { type FileSystem, type ScaffoldLogger, type ScaffoldOptions, type ScaffoldResult, planScaffold, runScaffold, validateConsumerName };