create-kerf 0.0.0-stage → 0.1.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/LICENSE +16 -0
- package/README.md +401 -2
- package/bin/create-kerf.mjs +121 -0
- package/package.json +37 -3
- package/scripts/tarballs.mjs +77 -0
- package/src/data.mjs +360 -0
- package/src/index.mjs +400 -0
- package/src/stack/pages.mjs +151 -0
- package/src/stack/schema.mjs +195 -0
- package/src/stack.mjs +293 -0
- package/src/templates.mjs +175 -0
- package/src/wizard.mjs +127 -0
- package/templates/admin/files/drizzle/.schema-hash +1 -0
- package/templates/admin/files/drizzle/0000_admin.sql +136 -0
- package/templates/admin/files/drizzle/meta/0000_snapshot.json +771 -0
- package/templates/admin/files/drizzle/meta/_journal.json +13 -0
- package/templates/admin/files/kerf.config.ts +31 -0
- package/templates/admin/files/public/favicon.svg +1 -0
- package/templates/admin/files/src/auth.server.ts +24 -0
- package/templates/admin/files/src/components/AuthPage.tsx +33 -0
- package/templates/admin/files/src/components/Failed.tsx +19 -0
- package/templates/admin/files/src/components/Logo.tsx +16 -0
- package/templates/admin/files/src/components/OrderDetail.tsx +93 -0
- package/templates/admin/files/src/components/OrdersFilters.tsx +44 -0
- package/templates/admin/files/src/components/OrdersTable.tsx +144 -0
- package/templates/admin/files/src/components/Overview.tsx +113 -0
- package/templates/admin/files/src/components/StatusBadge.tsx +12 -0
- package/templates/admin/files/src/db/schema.ts +68 -0
- package/templates/admin/files/src/lib/orders.ts +60 -0
- package/templates/admin/files/src/routes/404.tsx +20 -0
- package/templates/admin/files/src/routes/_error.tsx +20 -0
- package/templates/admin/files/src/routes/_layout.tsx +6 -0
- package/templates/admin/files/src/routes/admin/_layout.tsx +89 -0
- package/templates/admin/files/src/routes/admin/index.tsx +45 -0
- package/templates/admin/files/src/routes/admin/nested/_layout.tsx +35 -0
- package/templates/admin/files/src/routes/admin/nested/index.tsx +77 -0
- package/templates/admin/files/src/routes/admin/orders/[id].tsx +24 -0
- package/templates/admin/files/src/routes/admin/orders/index.tsx +28 -0
- package/templates/admin/files/src/routes/admin/per-row.tsx +81 -0
- package/templates/admin/files/src/routes/admin/slow.tsx +74 -0
- package/templates/admin/files/src/routes/index.tsx +13 -0
- package/templates/admin/files/src/routes/login.tsx +53 -0
- package/templates/admin/files/src/routes/signup.tsx +60 -0
- package/templates/admin/files/src/server/orders.ts +193 -0
- package/templates/admin/files/src/server/reports.ts +92 -0
- package/templates/admin/files/src/server/session.ts +45 -0
- package/templates/admin/files/src/theme.css +43 -0
- package/templates/admin/template.json +22 -0
- package/templates/catalog/files/drizzle/.schema-hash +1 -0
- package/templates/catalog/files/drizzle/0000_catalog.sql +47 -0
- package/templates/catalog/files/drizzle/meta/0000_snapshot.json +263 -0
- package/templates/catalog/files/drizzle/meta/_journal.json +13 -0
- package/templates/catalog/files/kerf.config.ts +30 -0
- package/templates/catalog/files/public/favicon.svg +1 -0
- package/templates/catalog/files/seed.sql +13 -0
- package/templates/catalog/files/src/components/AddToCart.tsx +22 -0
- package/templates/catalog/files/src/components/Aisles.tsx +31 -0
- package/templates/catalog/files/src/components/CartLines.tsx +96 -0
- package/templates/catalog/files/src/components/CartLink.tsx +29 -0
- package/templates/catalog/files/src/components/Failed.tsx +19 -0
- package/templates/catalog/files/src/components/Featured.tsx +19 -0
- package/templates/catalog/files/src/components/Filters.tsx +40 -0
- package/templates/catalog/files/src/components/Logo.tsx +16 -0
- package/templates/catalog/files/src/components/ProductArt.tsx +42 -0
- package/templates/catalog/files/src/components/ProductCard.tsx +42 -0
- package/templates/catalog/files/src/components/ProductList.tsx +65 -0
- package/templates/catalog/files/src/components/Related.tsx +19 -0
- package/templates/catalog/files/src/components/SiteFooter.tsx +9 -0
- package/templates/catalog/files/src/components/SiteHeader.tsx +16 -0
- package/templates/catalog/files/src/db/schema.ts +53 -0
- package/templates/catalog/files/src/lib/catalog.ts +35 -0
- package/templates/catalog/files/src/routes/404.tsx +18 -0
- package/templates/catalog/files/src/routes/_error.tsx +18 -0
- package/templates/catalog/files/src/routes/_layout.tsx +14 -0
- package/templates/catalog/files/src/routes/c/[slug].tsx +53 -0
- package/templates/catalog/files/src/routes/cart.tsx +29 -0
- package/templates/catalog/files/src/routes/index.tsx +84 -0
- package/templates/catalog/files/src/routes/p/[slug].tsx +67 -0
- package/templates/catalog/files/src/server/cart.ts +125 -0
- package/templates/catalog/files/src/server/catalog.ts +107 -0
- package/templates/catalog/files/src/theme.css +159 -0
- package/templates/catalog/template.json +20 -0
- package/templates/landing/files/.kerf/plugins.lock.json +42 -0
- package/templates/landing/files/assets/fonts/LICENSE-figtree.txt +93 -0
- package/templates/landing/files/assets/fonts/figtree.woff2 +0 -0
- package/templates/landing/files/assets/hero.webp +0 -0
- package/templates/landing/files/drizzle/.schema-hash +1 -0
- package/templates/landing/files/drizzle/0000_landing.sql +6 -0
- package/templates/landing/files/drizzle/meta/0000_snapshot.json +60 -0
- package/templates/landing/files/drizzle/meta/_journal.json +13 -0
- package/templates/landing/files/kerf.config.ts +44 -0
- package/templates/landing/files/public/favicon.svg +1 -0
- package/templates/landing/files/src/components/SiteFooter.tsx +24 -0
- package/templates/landing/files/src/components/SiteHeader.tsx +23 -0
- package/templates/landing/files/src/components/WaitlistForm.tsx +36 -0
- package/templates/landing/files/src/db/schema.ts +7 -0
- package/templates/landing/files/src/routes/404.tsx +24 -0
- package/templates/landing/files/src/routes/_error.tsx +24 -0
- package/templates/landing/files/src/routes/_layout.tsx +14 -0
- package/templates/landing/files/src/routes/index.tsx +130 -0
- package/templates/landing/files/src/routes/joined.tsx +30 -0
- package/templates/landing/files/src/routes/pricing.tsx +131 -0
- package/templates/landing/files/src/routes/privacy.tsx +56 -0
- package/templates/landing/files/src/server/waitlist.ts +13 -0
- package/templates/landing/files/src/theme.css +108 -0
- package/templates/landing/template.json +17 -0
- package/templates/todo/files/drizzle/.schema-hash +1 -0
- package/templates/todo/files/drizzle/0000_todo.sql +82 -0
- package/templates/todo/files/drizzle/meta/0000_snapshot.json +462 -0
- package/templates/todo/files/drizzle/meta/_journal.json +13 -0
- package/templates/todo/files/kerf.config.ts +30 -0
- package/templates/todo/files/public/favicon.svg +1 -0
- package/templates/todo/files/src/components/AuthPage.tsx +33 -0
- package/templates/todo/files/src/components/Logo.tsx +14 -0
- package/templates/todo/files/src/components/NewTodo.tsx +27 -0
- package/templates/todo/files/src/components/TodoList.tsx +101 -0
- package/templates/todo/files/src/db/schema.ts +18 -0
- package/templates/todo/files/src/lib/views.ts +13 -0
- package/templates/todo/files/src/routes/404.tsx +20 -0
- package/templates/todo/files/src/routes/_error.tsx +20 -0
- package/templates/todo/files/src/routes/_layout.tsx +6 -0
- package/templates/todo/files/src/routes/index.tsx +13 -0
- package/templates/todo/files/src/routes/login.tsx +53 -0
- package/templates/todo/files/src/routes/signup.tsx +57 -0
- package/templates/todo/files/src/routes/todos.tsx +87 -0
- package/templates/todo/files/src/server/todos.ts +98 -0
- package/templates/todo/files/src/theme.css +71 -0
- package/templates/todo/template.json +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ravonus
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
7
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
11
|
+
Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
14
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
15
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
16
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,402 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/Ravonus/kerf">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/Ravonus/kerf/main/site/public/logo.svg" width="88" height="88" alt="Kerf">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
<h1 align="center">create-kerf</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<strong>Start a Kerf app: pages, a server, a database, sign-in and Veneer's components, wired up.</strong><br>
|
|
11
|
+
The new app passes <code>kerf check</code> as made, and comes with an <code>AGENTS.md</code> for the Kerf it installed.
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://www.npmjs.com/package/create-kerf"><img src="https://img.shields.io/npm/v/create-kerf?color=145c3c&label=npm" alt="npm version"></a>
|
|
16
|
+
<a href="https://github.com/Ravonus/kerf/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-145c3c" alt="MIT license"></a>
|
|
17
|
+
<a href="https://github.com/Ravonus/kerf/actions"><img src="https://img.shields.io/github/actions/workflow/status/Ravonus/kerf/quality.yml?branch=main&label=checks" alt="checks"></a>
|
|
18
|
+
<img src="https://img.shields.io/badge/node-%3E%3D24-145c3c" alt="Node 24 or later">
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#quick-start">Quick start</a> ·
|
|
23
|
+
<a href="https://github.com/Ravonus/kerf/blob/main/site/content/learn/installation.md">Docs</a> ·
|
|
24
|
+
<a href="https://github.com/Ravonus/kerf/tree/main/packages/create-kerf/templates">Templates</a> ·
|
|
25
|
+
<a href="https://github.com/Ravonus/kerf/blob/main/CHANGELOG.md">Changelog</a> ·
|
|
26
|
+
<a href="https://github.com/Ravonus/kerf">GitHub</a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
> [!IMPORTANT]
|
|
30
|
+
> **Early release (0.1.x).** The scaffolds install and check clean, and flags and generated files can still change
|
|
31
|
+
> between minor versions.
|
|
32
|
+
|
|
33
|
+
`create-kerf` is what runs when you type `npm create kerf`. It writes a new
|
|
34
|
+
[Kerf](https://github.com/Ravonus/kerf) app into an empty folder: a home page, an about page, a todo list on server
|
|
35
|
+
functions, sign-in, and the config, types and editor setup around them. Then it installs the dependencies, starts a git
|
|
36
|
+
repository and writes an `AGENTS.md` from the Kerf it just installed.
|
|
37
|
+
|
|
38
|
+
In a terminal it asks what the flags don't answer, with the default already picked. Without one (an agent, CI), it never
|
|
39
|
+
prompts.
|
|
40
|
+
|
|
41
|
+
## Highlights
|
|
42
|
+
|
|
43
|
+
- **One question per choice, or none.** UI kit, database, data layer, sign-in, runtime, config format and package
|
|
44
|
+
manager. A flag answers its question, and `--yes` takes every default.
|
|
45
|
+
- **A full stack by default.** `--yes` gives Veneer, SQLite through Drizzle, and Better Auth, with a guarded todo list
|
|
46
|
+
that works before you write a line.
|
|
47
|
+
- **Four UI choices.** Veneer's components, Veneer's behavior and tokens with your own markup, Tailwind, or plain CSS.
|
|
48
|
+
- **Three databases, three data layers.** SQLite, Postgres or MySQL, through Drizzle, Prisma or plain SQL migrations.
|
|
49
|
+
- **Four starting apps.** `--template todo`, `admin`, `catalog` or `landing`: real apps with their own look and
|
|
50
|
+
their own migrations.
|
|
51
|
+
- **Pinned versions.** Every dependency is pinned to the version the test matrix ran, and Kerf's own packages to the
|
|
52
|
+
version of this scaffold.
|
|
53
|
+
- **Agent-ready.** `AGENTS.md`, `kerf check --json` and `kerf docs` are there from the first run.
|
|
54
|
+
|
|
55
|
+
## Contents
|
|
56
|
+
|
|
57
|
+
- [Quick start](#quick-start)
|
|
58
|
+
- [Flags](#flags)
|
|
59
|
+
- [The questions](#the-questions)
|
|
60
|
+
- [UI](#ui)
|
|
61
|
+
- [Database and data layer](#database-and-data-layer)
|
|
62
|
+
- [Sign-in](#sign-in)
|
|
63
|
+
- [Templates](#templates)
|
|
64
|
+
- [What gets generated](#what-gets-generated)
|
|
65
|
+
- [Package managers and runtimes](#package-managers-and-runtimes)
|
|
66
|
+
- [Recipes](#recipes)
|
|
67
|
+
- [Using it from code](#using-it-from-code)
|
|
68
|
+
- [Troubleshooting](#troubleshooting)
|
|
69
|
+
- [Related packages](#related-packages)
|
|
70
|
+
|
|
71
|
+
## Quick start
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm create kerf my-app
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pnpm create kerf my-app
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
bun create kerf my-app
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
deno run -A npm:create-kerf my-app
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Then:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
cd my-app
|
|
93
|
+
npx kerf db generate # with a database: the first migration
|
|
94
|
+
npx kerf dev
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The last thing it prints is the exact commands for your package manager. Open the URL `kerf dev` prints, sign up, and
|
|
98
|
+
the todo list at `/todos` is yours.
|
|
99
|
+
|
|
100
|
+
You need Node 24 or later, or Bun or Deno in its place.
|
|
101
|
+
|
|
102
|
+
## Flags
|
|
103
|
+
|
|
104
|
+
| Flag | Values | Default | What it does |
|
|
105
|
+
|---|---|---|---|
|
|
106
|
+
| `[dir]` | a folder that's missing or empty | asked; `my-kerf-app` with `--yes` | Where the app goes |
|
|
107
|
+
| `--template` | `todo`, `admin`, `catalog`, `landing` | none | Starts from a fuller app ([below](#templates)) |
|
|
108
|
+
| `--ui` | `veneer`, `headless`, `tailwind`, `none` | `veneer` | The UI kit ([below](#ui)) |
|
|
109
|
+
| `--db` | `sqlite`, `postgres`, `mysql`, `none` | `sqlite` | The database |
|
|
110
|
+
| `--layer` | `drizzle`, `prisma`, `native` | `drizzle` | The data layer. `native` is SQL migrations with no ORM. Asked only with a database |
|
|
111
|
+
| `--auth`, `--no-auth` | | on, with a database | Sign-in |
|
|
112
|
+
| `--auth-provider` | `better-auth`, `custom` | `better-auth` | `custom` writes a stub for your own provider |
|
|
113
|
+
| `--runtime` | `node`, `bun`, `deno` | the one running it | What `kerf build` targets |
|
|
114
|
+
| `--config` | `ts`, `json`, `yaml` | `ts` | The format of the Kerf config |
|
|
115
|
+
| `--pm` | `npm`, `pnpm`, `bun`, `deno`, `yarn` | the one you ran it with | The package manager |
|
|
116
|
+
| `--git`, `--no-git` | | on | Start a git repository |
|
|
117
|
+
| `--install`, `--no-install` | | on; off with no terminal and no `--yes` | Install the dependencies, then write `AGENTS.md` |
|
|
118
|
+
| `--name` | a package name | the folder's name | The `name` in `package.json`, and the app's title |
|
|
119
|
+
| `--tarballs` | a folder with `tarballs.json` | none | Pins Kerf's packages to local tarballs, for testing a checkout |
|
|
120
|
+
| `--yes`, `-y` | | | Take the defaults for anything not given |
|
|
121
|
+
| `--help`, `-h` | | | Print the usage |
|
|
122
|
+
|
|
123
|
+
With npm, flags go after `--`:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm create kerf my-app -- --ui tailwind --db none
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
> [!NOTE]
|
|
130
|
+
> With no terminal and no `[dir]`, it prints the usage and exits 1: it can't ask where to put the app. With no terminal
|
|
131
|
+
> and no `--yes`, it writes the app and runs nothing else, so git and the install stay off unless you ask for them.
|
|
132
|
+
|
|
133
|
+
## The questions
|
|
134
|
+
|
|
135
|
+
In a terminal, each question is a list: the arrow keys move, Enter picks. Enter all the way through is the same app as
|
|
136
|
+
`--yes`.
|
|
137
|
+
|
|
138
|
+
| # | Question | Options | Default | Asked when |
|
|
139
|
+
|---|---|---|---|---|
|
|
140
|
+
| 1 | UI | Veneer, Headless, Tailwind, None | Veneer | always |
|
|
141
|
+
| 2 | Database | SQLite, Postgres, MySQL, none | SQLite | always |
|
|
142
|
+
| 3 | Data layer | Drizzle, Prisma, Native (no ORM) | Drizzle | there's a database |
|
|
143
|
+
| 4 | Sign-in | Better Auth, Bring your own, None | Better Auth | there's a database |
|
|
144
|
+
| 5 | Runtime | Node, Bun, Deno | the one running it | always |
|
|
145
|
+
| 6 | Config file | TypeScript, JSON, YAML | TypeScript | always |
|
|
146
|
+
| 7 | Package manager | npm, pnpm, Bun, Deno, Yarn | the one you ran it with | always |
|
|
147
|
+
| 8 | Start a git repository | Yes, No | Yes | always |
|
|
148
|
+
| 9 | Install dependencies | Yes, No | Yes | always |
|
|
149
|
+
|
|
150
|
+
A flag skips its question, and a template skips the ones it settles.
|
|
151
|
+
|
|
152
|
+
## UI
|
|
153
|
+
|
|
154
|
+
| `--ui` | What you get | Dependencies |
|
|
155
|
+
|---|---|---|
|
|
156
|
+
| `veneer` | Veneer's components (`Card`, `Button`, `Badge`…) and the `veneer()` plugin in the config. The look is `veneer({ seed, dials, radius, fonts, tokens })`, and `kerf check` fails with D010 if a color pair can't pass contrast | `@kerf-js/veneer` |
|
|
157
|
+
| `headless` | Veneer's behavior and tokens, your markup. `src/app.css` styles plain elements over Veneer's `--veneer-*` tokens, and the layout imports `@kerf-js/veneer-core/styles/veneer.css` | [`@kerf-js/veneer-core`](https://www.npmjs.com/package/@kerf-js/veneer-core) |
|
|
158
|
+
| `tailwind` | Tailwind utilities. Writes `vite.config.ts` and `src/app.css`, the same files `kerf add tailwind` writes | Tailwind, as dev dependencies |
|
|
159
|
+
| `none` | A small `src/app.css` on system colors, and nothing else | none |
|
|
160
|
+
|
|
161
|
+
## Database and data layer
|
|
162
|
+
|
|
163
|
+
`--db` picks the engine, and `--layer` how the app talks to it.
|
|
164
|
+
|
|
165
|
+
| `--layer` | Schema | Migrations | `ctx.db` | Packages |
|
|
166
|
+
|---|---|---|---|---|
|
|
167
|
+
| `drizzle` | `src/db/schema.ts` | `drizzle/`, from `kerf db generate` | Drizzle, from `@kerf-js/start/db/<engine>` | `drizzle-orm`, `drizzle-zod`, `drizzle-kit` |
|
|
168
|
+
| `prisma` | `prisma/schema.prisma` | `kerf db generate` | a Prisma client with the engine's adapter | `@prisma/client`, `prisma`, `@kerf-js/db` |
|
|
169
|
+
| `native` | SQL | `migrations/0000_todos.sql`; `kerf db generate <name>` starts a new one | `@kerf-js/db/plugin-native/<engine>` | `@kerf-js/db` |
|
|
170
|
+
|
|
171
|
+
| `--db` | `DATABASE_URL` in `.env` | Driver |
|
|
172
|
+
|---|---|---|
|
|
173
|
+
| `sqlite` | `file:.data/app.db` | none |
|
|
174
|
+
| `postgres` | `postgres://localhost:5432/<name>` | `postgres` |
|
|
175
|
+
| `mysql` | `mysql://root@localhost:3306/<name>` | `mysql2` |
|
|
176
|
+
|
|
177
|
+
`src/env.server.ts` checks the environment with `@t3-oss/env-core` and `zod`. Migrations apply on the next request, so
|
|
178
|
+
after `kerf db generate` there's nothing else to run. With Prisma, `postinstall` runs `prisma generate`, and its
|
|
179
|
+
client goes to `src/generated/`, which `.gitignore` leaves out.
|
|
180
|
+
|
|
181
|
+
## Sign-in
|
|
182
|
+
|
|
183
|
+
Sign-in needs a database: `--auth` with `--db none` is refused.
|
|
184
|
+
|
|
185
|
+
| Choice | What it writes |
|
|
186
|
+
|---|---|
|
|
187
|
+
| Better Auth (`--auth`, the default) | `src/auth.server.ts` on Better Auth, with its tables in your schema; `src/server/session.ts`; a sign-in and sign-up page at `/login`; a guard on `/todos`; and a `BETTER_AUTH_SECRET` that's new for every scaffold |
|
|
188
|
+
| Bring your own (`--auth-provider custom`) | `src/auth.server.ts` with `defineAuth` from `@kerf-js/start/auth`: a `session` and a `handler` to fill in. The app compiles, with no one signed in, and the todo list is public |
|
|
189
|
+
| None (`--no-auth`) | No sign-in. The todo list is public |
|
|
190
|
+
|
|
191
|
+
Login with Better Auth is an opaque session in the database, in an HTTP-only cookie, never a JWT. `ctx.user` is the
|
|
192
|
+
signed-in user in every server function, and `auth: 'user'` on a `query` or `mutation` requires one.
|
|
193
|
+
|
|
194
|
+
## Templates
|
|
195
|
+
|
|
196
|
+
A template is a real app laid over the scaffold, in place of the default todo app. Each runs on Postgres, uses Veneer and
|
|
197
|
+
Drizzle, has a TypeScript config, and ships its own look, migrations and pages.
|
|
198
|
+
|
|
199
|
+
| Template | What it is | Pages | Sign-in | Look |
|
|
200
|
+
|---|---|---|---|---|
|
|
201
|
+
| `todo` | Sign-in and sign-up, and a todo list | `/`, `/login`, `/signup`, `/todos` | on | quiet, cozy, sharp corners, a serif display face |
|
|
202
|
+
| `admin` | An admin area with an orders table, order pages and nested layouts, behind sign-in | `/`, `/login`, `/signup`, `/admin`, `/admin/orders`, `/admin/orders/[id]`, `/admin/nested`, `/admin/per-row`, `/admin/slow` | on | balanced, compact, soft corners, system fonts |
|
|
203
|
+
| `catalog` | A shop: categories, product pages and a cart, with seed data in `seed.sql` | `/`, `/c/[slug]`, `/p/[slug]`, `/cart` | off | balanced, comfortable, round corners |
|
|
204
|
+
| `landing` | A landing page with pricing, a privacy page and a sign-up list | `/`, `/pricing`, `/privacy`, `/joined` | off | vivid, round corners, the Figtree font |
|
|
205
|
+
|
|
206
|
+
A template settles what it needs, and refuses a flag that conflicts rather than ignoring it:
|
|
207
|
+
|
|
208
|
+
| Setting | Every template |
|
|
209
|
+
|---|---|
|
|
210
|
+
| `--db` | `postgres` |
|
|
211
|
+
| `--ui` | `veneer` |
|
|
212
|
+
| `--layer` | `drizzle` |
|
|
213
|
+
| `--config` | `ts` (fonts and media are plugin options in code) |
|
|
214
|
+
| sign-in | as in the table above |
|
|
215
|
+
|
|
216
|
+
`todo` and `admin` also add [`@kerf-js/veneer-icons`](https://www.npmjs.com/package/@kerf-js/veneer-icons). `landing` adds `@kerf-js/veneer-icons`, [`@kerf-js/media`](https://www.npmjs.com/package/@kerf-js/media) and
|
|
217
|
+
[`@kerf-js/text`](https://www.npmjs.com/package/@kerf-js/text), with its hero image and font in `assets/`.
|
|
218
|
+
|
|
219
|
+
A template's `drizzle/` ships with it, written so it runs on a fresh database and on one that already has these tables.
|
|
220
|
+
Set `DATABASE_URL` in `.env` to an empty Postgres database and start the app: `drizzle/` applies on the first request,
|
|
221
|
+
and there's no `kerf db generate` to run. The theme is `src/theme.css` plus `veneer({ seed, dials, radius })` in the config.
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
npm create kerf shop -- --template catalog
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## What gets generated
|
|
228
|
+
|
|
229
|
+
The default app (`--yes`):
|
|
230
|
+
|
|
231
|
+
| File | What it is |
|
|
232
|
+
|---|---|
|
|
233
|
+
| `package.json` | `dev`, `build`, `check`, `typecheck`, `start` and `db:generate` scripts, each a `kerf` command. `@kerf-js/cli` and TypeScript 7 as dev dependencies |
|
|
234
|
+
| `kerf.config.ts` | `site` (name, title, description), `plugins`, and `runtime` when it isn't Node |
|
|
235
|
+
| `tsconfig.json` | Strict, `jsxImportSource: '@kerf-js/core'`, the `#/*` alias for `src/*`, and the `@kerf-js/cli/ts-plugin` editor plugin |
|
|
236
|
+
| `.vscode/settings.json` | Points VS Code's TypeScript at that plugin |
|
|
237
|
+
| `.gitignore` | `node_modules/`, `.kerf/` (except the plugin lock), `.output/`, `dist/`, and with a database `.env` and `.data/` |
|
|
238
|
+
| `.kerf/plugins.lock.json` | The plugins you chose, with the permissions they declare |
|
|
239
|
+
| `AGENTS.md` | A short guide; after the install, `kerf agents-md` writes the full one over it |
|
|
240
|
+
| `.env`, `.env.example` | `DATABASE_URL`, and with Better Auth `BETTER_AUTH_SECRET` and `BETTER_AUTH_URL` |
|
|
241
|
+
| `src/env.server.ts` | The environment, checked |
|
|
242
|
+
| `src/context.server.ts` | What `ctx` holds in server functions |
|
|
243
|
+
| `src/routes/_layout.tsx` | The shell: links, and sign in or sign out |
|
|
244
|
+
| `src/routes/index.tsx` | The home page: a counter in a card |
|
|
245
|
+
| `src/routes/about.tsx` | The about page |
|
|
246
|
+
| `src/routes/todos/index.tsx`, `_layout.tsx` | The todo list, and the guard that sends a signed-out visitor to sign in |
|
|
247
|
+
| `src/routes/login.tsx` | Sign in and sign up |
|
|
248
|
+
| `src/server/todos.ts` | The todo list's `query` and `mutation` functions |
|
|
249
|
+
| `src/server/session.ts` | `me`, `signUp`, `signIn` and `signOut` |
|
|
250
|
+
| `src/auth.server.ts` | Better Auth |
|
|
251
|
+
| `drizzle.config.ts`, `src/db/schema.ts`, `src/db/index.server.ts` | The database |
|
|
252
|
+
|
|
253
|
+
Other choices change that list:
|
|
254
|
+
|
|
255
|
+
| Choice | Adds | Drops |
|
|
256
|
+
|---|---|---|
|
|
257
|
+
| `--ui headless`, `none` | `src/app.css` | |
|
|
258
|
+
| `--ui tailwind` | `src/app.css`, `vite.config.ts` | |
|
|
259
|
+
| `--db none` | | the database, server and sign-in files, and the layout's Todos link |
|
|
260
|
+
| `--layer prisma` | `prisma/schema.prisma`, `prisma.config.ts`, a `postinstall` script | `drizzle.config.ts`, `src/db/schema.ts` |
|
|
261
|
+
| `--layer native` | `migrations/0000_todos.sql` | `drizzle.config.ts`, `src/db/schema.ts` |
|
|
262
|
+
| `--no-auth` | | the sign-in files, the guard and the auth secret |
|
|
263
|
+
| `--config json`, `yaml` | `kerf.config.json` or `.yaml`, with a `$schema` for editor completion | `kerf.config.ts` |
|
|
264
|
+
| `--pm pnpm` | `pnpm-workspace.yaml`, which settles the build scripts pnpm would stop at | |
|
|
265
|
+
| `--template <t>` | the template's files, and `src/db/auth.ts` when it has sign-in | the about page and the default todo app |
|
|
266
|
+
|
|
267
|
+
Everything else in `.kerf/` is generated by `kerf` itself on the first `kerf dev` or `kerf check`, so a scaffold never
|
|
268
|
+
goes stale against the CLI.
|
|
269
|
+
|
|
270
|
+
`kerf check` passes on the new app as made. Its one finding is the warning H001, which asks for `site.url` in the
|
|
271
|
+
config before you deploy.
|
|
272
|
+
|
|
273
|
+
### Pinned versions
|
|
274
|
+
|
|
275
|
+
| Package | Version |
|
|
276
|
+
|---|---|
|
|
277
|
+
| `@kerf-js/*` | the version of this package |
|
|
278
|
+
| `typescript` | 7.0.2 |
|
|
279
|
+
| `drizzle-orm`, `drizzle-kit`, `drizzle-zod` | 0.45.4, 0.31.11, 0.8.3 |
|
|
280
|
+
| `prisma`, `@prisma/client`, `@prisma/adapter-*` | 7.10.1 |
|
|
281
|
+
| `better-auth` | 1.7.14 |
|
|
282
|
+
| `postgres`, `mysql2` | 4.0.0, 3.24.6 |
|
|
283
|
+
| `kysely` (native layer with sign-in) | 0.29.7 |
|
|
284
|
+
| `@t3-oss/env-core`, `zod` | 0.13.11, 4.6.7 |
|
|
285
|
+
| `@types/node` | 26.6.5 |
|
|
286
|
+
|
|
287
|
+
## Package managers and runtimes
|
|
288
|
+
|
|
289
|
+
`--pm` picks the package manager for the install and for the commands it prints at the end. Without it, a run under Node
|
|
290
|
+
uses the one that started it (from `npm_config_user_agent`), and a run under Bun or Deno uses that one.
|
|
291
|
+
|
|
292
|
+
| `--pm` | How to start it | The `kerf` command it prints |
|
|
293
|
+
|---|---|---|
|
|
294
|
+
| `npm` | `npm create kerf my-app` | `npx kerf` |
|
|
295
|
+
| `pnpm` | `pnpm create kerf my-app` | `pnpm exec kerf` |
|
|
296
|
+
| `bun` | `bun create kerf my-app` | `bunx --bun kerf` |
|
|
297
|
+
| `deno` | `deno run -A npm:create-kerf my-app` | `deno run -A npm:@kerf-js/cli` |
|
|
298
|
+
| `yarn` | `yarn create kerf my-app` | `yarn kerf` |
|
|
299
|
+
|
|
300
|
+
`--runtime` is separate: it's what `kerf build` targets and `kerf start` runs. Without it, the scaffold picks the one
|
|
301
|
+
running it, since a machine may have only that one. Anything but Node is written into the config as `runtime`.
|
|
302
|
+
|
|
303
|
+
## Recipes
|
|
304
|
+
|
|
305
|
+
A front end with no server code:
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
npm create kerf site -- --db none --yes
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Postgres with Prisma and your own auth:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
pnpm create kerf app --db postgres --layer prisma \
|
|
315
|
+
--auth-provider custom --yes
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Tailwind on MySQL with plain SQL, a YAML config, and no install:
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
bun create kerf app --ui tailwind --db mysql \
|
|
322
|
+
--layer native --config yaml --no-install --yes
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
For an agent or CI: no prompts, and everything run.
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
npm create kerf my-app -- --yes
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## Using it from code
|
|
332
|
+
|
|
333
|
+
The package exports what the command is built from. `kerf add db` and `kerf add auth` use `./stack`.
|
|
334
|
+
|
|
335
|
+
| Import | Exports |
|
|
336
|
+
|---|---|
|
|
337
|
+
| `create-kerf` | `scaffold(dir, options)`, `template(options)`, `withTemplate(options)`, and the choice lists `UI`, `DB`, `LAYERS`, `RUNTIMES`, `CONFIGS`, `TEMPLATES` |
|
|
338
|
+
| `create-kerf/stack` | `stackDeps`, `stackFiles`, `authFiles`, `VERSIONS`, `VERSION` and the page builders: the database and auth part of a scaffold |
|
|
339
|
+
|
|
340
|
+
```js
|
|
341
|
+
import { scaffold, template } from 'create-kerf'
|
|
342
|
+
|
|
343
|
+
// Every file as { path: text }, written nowhere
|
|
344
|
+
const files = template({
|
|
345
|
+
name: 'shop',
|
|
346
|
+
ui: 'veneer',
|
|
347
|
+
db: 'sqlite',
|
|
348
|
+
auth: true,
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
// The same, written into an empty folder
|
|
352
|
+
const { files: written } = scaffold('./shop', {
|
|
353
|
+
ui: 'veneer',
|
|
354
|
+
db: 'sqlite',
|
|
355
|
+
auth: true,
|
|
356
|
+
})
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
> [!NOTE]
|
|
360
|
+
> `template()` and `scaffold()` don't apply the wizard's defaults: without `db` there's no database, and without
|
|
361
|
+
> `auth` no sign-in. They don't install or start git either.
|
|
362
|
+
|
|
363
|
+
## Troubleshooting
|
|
364
|
+
|
|
365
|
+
| Message | Why | Fix |
|
|
366
|
+
|---|---|---|
|
|
367
|
+
| `<dir> is not empty` | It only writes into a missing or empty folder | Pick another name, or empty it |
|
|
368
|
+
| `--auth keeps users in a database` | Sign-in with `--db none` | Add `--db sqlite`, `postgres` or `mysql`, or `--no-auth` |
|
|
369
|
+
| `the <name> template needs --db postgres` (or `--ui veneer`, `--layer drizzle`, `--config ts`, sign-in on or off) | A flag conflicts with the template | Drop the flag, or use the value it names |
|
|
370
|
+
| `--ui must be one of …` and the like | An unknown value | Use one from [Flags](#flags) |
|
|
371
|
+
| `The install didn't finish; run … yourself.` | The package manager failed. The app is already written | Run the command it prints. The run exits 1 |
|
|
372
|
+
| `git init didn't finish` | git isn't installed, or failed | The app is fine; run `git init` when you want it |
|
|
373
|
+
|
|
374
|
+
## Related packages
|
|
375
|
+
|
|
376
|
+
| Package | What it is |
|
|
377
|
+
|---|---|
|
|
378
|
+
| [`@kerf-js/cli`](https://www.npmjs.com/package/@kerf-js/cli) <sup>[source](https://github.com/Ravonus/kerf/tree/main/packages/cli)</sup> | The `kerf` command every new app uses |
|
|
379
|
+
| [`@kerf-js/core`](https://www.npmjs.com/package/@kerf-js/core) <sup>[source](https://github.com/Ravonus/kerf/tree/main/packages/core)</sup> | The runtime, the compiler binding, the Vite plugin, SSR and test utilities |
|
|
380
|
+
| [`@kerf-js/start`](https://www.npmjs.com/package/@kerf-js/start) <sup>[source](https://github.com/Ravonus/kerf/tree/main/packages/start)</sup> | File routes, server functions, SSR, the database, auth and live data |
|
|
381
|
+
| [`@kerf-js/db`](https://www.npmjs.com/package/@kerf-js/db) <sup>[source](https://github.com/Ravonus/kerf/tree/main/packages/db)</sup> | The Prisma and native SQL data layers |
|
|
382
|
+
| [`@kerf-js/veneer`](https://www.npmjs.com/package/@kerf-js/veneer) <sup>[source](https://github.com/Ravonus/kerf/tree/main/packages/veneer)</sup> | Veneer's components, and the `veneer()` theming plugin |
|
|
383
|
+
|
|
384
|
+
[Installation](https://github.com/Ravonus/kerf/blob/main/site/content/learn/installation.md) walks through every file in
|
|
385
|
+
a new app, and how to run, check, build and deploy it.
|
|
386
|
+
|
|
387
|
+
## Contributing
|
|
388
|
+
|
|
389
|
+
[CONTRIBUTING.md](https://github.com/Ravonus/kerf/blob/main/CONTRIBUTING.md) has the setup. To work on this package:
|
|
390
|
+
|
|
391
|
+
```bash
|
|
392
|
+
pnpm --filter create-kerf test
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
A template is a folder in
|
|
396
|
+
[`packages/create-kerf/templates`](https://github.com/Ravonus/kerf/tree/main/packages/create-kerf/templates) with a
|
|
397
|
+
`template.json` (what it `requires`, its `pages`, its `veneer()` options and `dependencies`) and a `files/` folder that's
|
|
398
|
+
copied as it is.
|
|
399
|
+
|
|
400
|
+
## License
|
|
401
|
+
|
|
402
|
+
[MIT](https://github.com/Ravonus/kerf/blob/main/LICENSE).
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// create-kerf [dir] [--template landing|todo|admin|catalog] [--ui veneer|headless|tailwind|none] [--db sqlite|postgres|mysql|none] [--layer drizzle|prisma|native] [--[no-]auth] [--auth-provider better-auth|custom] [--runtime node|bun|deno]
|
|
3
|
+
// [--config ts|json|yaml] [--pm npm|pnpm|bun|deno|yarn] [--[no-]git] [--[no-]install] [--name <name>] [--tarballs <dir>] [--yes]
|
|
4
|
+
// In a terminal it asks what the flags don't answer; --yes, or no terminal, takes the defaults.
|
|
5
|
+
import { execFileSync } from 'node:child_process'
|
|
6
|
+
import { readFileSync, writeFileSync } from 'node:fs'
|
|
7
|
+
import { join, resolve } from 'node:path'
|
|
8
|
+
import { createInterface } from 'node:readline/promises'
|
|
9
|
+
import { parseArgs } from 'node:util'
|
|
10
|
+
import {
|
|
11
|
+
CONFIGS,
|
|
12
|
+
DB,
|
|
13
|
+
LAYERS,
|
|
14
|
+
RUNTIMES,
|
|
15
|
+
scaffold,
|
|
16
|
+
TEMPLATES,
|
|
17
|
+
UI,
|
|
18
|
+
withTemplate,
|
|
19
|
+
} from '../src/index.mjs'
|
|
20
|
+
import { resolveChoices } from '../src/wizard.mjs'
|
|
21
|
+
import { pin, pinWorkspace } from '../scripts/tarballs.mjs'
|
|
22
|
+
|
|
23
|
+
const usage = `Usage: npm create kerf -- [dir] [--template ${TEMPLATES.join('|')}] [--ui ${UI.join('|')}] [--db ${DB.join('|')}] [--layer ${LAYERS.join('|')}] [--[no-]auth] [--auth-provider better-auth|custom] [--runtime ${RUNTIMES.join('|')}] [--config ${CONFIGS.join('|')}] [--pm <manager>] [--[no-]git] [--[no-]install] [--name <name>] [--tarballs <dir>] [--yes]`
|
|
24
|
+
const string = { type: 'string' },
|
|
25
|
+
boolean = { type: 'boolean' }
|
|
26
|
+
const { values, positionals } = parseArgs({
|
|
27
|
+
allowPositionals: true,
|
|
28
|
+
allowNegative: true,
|
|
29
|
+
options: {
|
|
30
|
+
template: string,
|
|
31
|
+
ui: string,
|
|
32
|
+
db: string,
|
|
33
|
+
layer: string,
|
|
34
|
+
auth: boolean,
|
|
35
|
+
'auth-provider': string,
|
|
36
|
+
runtime: string,
|
|
37
|
+
config: string,
|
|
38
|
+
pm: string,
|
|
39
|
+
git: boolean,
|
|
40
|
+
install: boolean,
|
|
41
|
+
name: string,
|
|
42
|
+
tarballs: string,
|
|
43
|
+
yes: { ...boolean, short: 'y' },
|
|
44
|
+
help: { ...boolean, short: 'h' },
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
const interactive = process.stdin.isTTY && process.stdout.isTTY
|
|
48
|
+
if (values.help || positionals.length > 1 || (!positionals.length && !interactive)) {
|
|
49
|
+
console.log(usage)
|
|
50
|
+
process.exit(values.help ? 0 : 1)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function directory() {
|
|
54
|
+
if (positionals.length) return positionals[0]
|
|
55
|
+
if (values.yes) return 'my-kerf-app'
|
|
56
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout })
|
|
57
|
+
const answer = await rl.question('App directory (my-kerf-app) ')
|
|
58
|
+
rl.close()
|
|
59
|
+
return answer.trim() || 'my-kerf-app'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The app is already written, so a failure here leaves a step for later; a failed install still fails the command. */
|
|
63
|
+
function step(what, command, args, cwd) {
|
|
64
|
+
try {
|
|
65
|
+
execFileSync(command, args, {
|
|
66
|
+
cwd,
|
|
67
|
+
stdio: ['ignore', 'ignore', 'inherit'],
|
|
68
|
+
shell: process.platform === 'win32',
|
|
69
|
+
}) // npm is npm.cmd there
|
|
70
|
+
return true
|
|
71
|
+
} catch {
|
|
72
|
+
console.error(
|
|
73
|
+
`create-kerf: ${what} didn't finish; run \`${[command, ...args].join(' ')}\` yourself.`,
|
|
74
|
+
)
|
|
75
|
+
return false
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const { yes, help: _help, name, tarballs, 'auth-provider': authProvider, ...flags } = values
|
|
81
|
+
if (authProvider && !['better-auth', 'custom'].includes(authProvider))
|
|
82
|
+
throw new Error('--auth-provider must be better-auth or custom')
|
|
83
|
+
if (authProvider) flags.auth = authProvider === 'custom' ? 'custom' : true
|
|
84
|
+
const where = await directory()
|
|
85
|
+
const dir = resolve(where)
|
|
86
|
+
const choices = await resolveChoices(withTemplate(flags), {
|
|
87
|
+
interactive,
|
|
88
|
+
yes,
|
|
89
|
+
io: { input: process.stdin, output: process.stdout },
|
|
90
|
+
})
|
|
91
|
+
const { files } = scaffold(dir, { ...choices, ...(name && { name }) })
|
|
92
|
+
// Before the install: a checkout's packages aren't on npm, so `local.mjs new` needs them wired in from the start.
|
|
93
|
+
if (tarballs) {
|
|
94
|
+
const file = join(dir, 'package.json')
|
|
95
|
+
const map = JSON.parse(readFileSync(join(tarballs, 'tarballs.json'), 'utf8'))
|
|
96
|
+
writeFileSync(file, JSON.stringify(pin(JSON.parse(readFileSync(file, 'utf8')), map), null, 2))
|
|
97
|
+
pinWorkspace(dir, map)
|
|
98
|
+
}
|
|
99
|
+
console.log(`\nCreated ${files.length} files in ${dir}`)
|
|
100
|
+
if (choices.git) step('git init', 'git', ['init', '--quiet'], dir)
|
|
101
|
+
const installed = choices.install && step('The install', choices.pm, ['install'], dir)
|
|
102
|
+
const kerf = {
|
|
103
|
+
npm: 'npx kerf',
|
|
104
|
+
pnpm: 'pnpm exec kerf',
|
|
105
|
+
bun: 'bunx --bun kerf',
|
|
106
|
+
deno: 'deno run -A npm:@kerf-js/cli',
|
|
107
|
+
yarn: 'yarn kerf',
|
|
108
|
+
}[choices.pm]
|
|
109
|
+
// AGENTS.md comes from the kerf just installed, so it always matches the compiler the app runs.
|
|
110
|
+
if (installed) {
|
|
111
|
+
const [command, ...args] = kerf.split(' ')
|
|
112
|
+
step('AGENTS.md', command, [...args, 'agents-md'], dir)
|
|
113
|
+
}
|
|
114
|
+
console.log(
|
|
115
|
+
`\n cd ${where}${installed ? '' : `\n ${choices.pm} install\n ${kerf} agents-md`}${choices.db === 'none' || choices.template ? '' : `\n ${kerf} db generate`}\n ${kerf} dev\n`,
|
|
116
|
+
)
|
|
117
|
+
if (choices.install && !installed) process.exitCode = 1
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.error(`create-kerf: ${e.message}`)
|
|
120
|
+
process.exit(1)
|
|
121
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-kerf",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scaffold a kerf app: npm create kerf",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"kerf"
|
|
7
|
+
],
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Ravonus/kerf.git",
|
|
12
|
+
"directory": "packages/create-kerf"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/Ravonus/kerf/tree/main/packages/create-kerf#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/Ravonus/kerf/issues"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"create-kerf": "./bin/create-kerf.mjs"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"bin",
|
|
23
|
+
"src",
|
|
24
|
+
"templates",
|
|
25
|
+
"scripts/tarballs.mjs",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./src/index.mjs",
|
|
32
|
+
"./stack": "./src/stack.mjs"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=24"
|
|
39
|
+
}
|
|
6
40
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Every package as a tarball, and an app's package.json pointed at them: what the packed gates and `local.mjs` share.
|
|
2
|
+
import { execFileSync } from 'node:child_process'
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { join, resolve } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
export const pkgs = fileURLToPath(new URL('../../', import.meta.url))
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Write the install policy and tarball overrides for a fresh pnpm workspace. kerf's own dependency patches stay
|
|
11
|
+
* behind: their files live in this repo, not in the app.
|
|
12
|
+
*/
|
|
13
|
+
export function writePackedPolicy(dir, tarballs = {}, packages = []) {
|
|
14
|
+
const policy = readFileSync(new URL('../../../pnpm-workspace.yaml', import.meta.url), 'utf8')
|
|
15
|
+
.replace(/^packages:\n(?:[ \t].*\n)*/m, '')
|
|
16
|
+
.replace(/^(?:#.*\n)*patchedDependencies:\n(?:[ \t].*\n)*/m, '')
|
|
17
|
+
const overrides = Object.entries(tarballs)
|
|
18
|
+
.map(([name, spec]) => ` ${JSON.stringify(name)}: ${JSON.stringify(spec)}\n`)
|
|
19
|
+
.join('')
|
|
20
|
+
const merged = /^overrides:\n/m.test(policy)
|
|
21
|
+
? policy.replace(/^overrides:\n/m, `overrides:\n${overrides}`)
|
|
22
|
+
: `${policy}${overrides ? `\noverrides:\n${overrides}` : ''}`
|
|
23
|
+
writeFileSync(
|
|
24
|
+
join(dir, 'pnpm-workspace.yaml'),
|
|
25
|
+
`${packages.length ? `packages:\n${packages.map((name) => ` - ${JSON.stringify(name)}\n`).join('')}` : ''}${merged}\n`,
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Pack one package to a known path, independent of lifecycle output. */
|
|
30
|
+
export function pack(dir, dest) {
|
|
31
|
+
const { name, version } = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
|
|
32
|
+
const file = join(resolve(dest), `${name.replace(/^@/, '').replaceAll('/', '-')}-${version}.tgz`)
|
|
33
|
+
execFileSync('pnpm', ['pack', '--out', file], {
|
|
34
|
+
cwd: dir,
|
|
35
|
+
stdio: ['ignore', 'pipe', 'inherit'],
|
|
36
|
+
shell: process.platform === 'win32',
|
|
37
|
+
})
|
|
38
|
+
if (!existsSync(file)) throw new Error(`pnpm pack did not create ${file}`)
|
|
39
|
+
return `file:${file}`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Pack each package into `dest`. Returns `{ name: 'file:…tgz' }`. */
|
|
43
|
+
export function packAll(dest) {
|
|
44
|
+
mkdirSync(dest, { recursive: true })
|
|
45
|
+
const tarballs = {}
|
|
46
|
+
for (const dir of readdirSync(pkgs)) {
|
|
47
|
+
const file = join(pkgs, dir, 'package.json')
|
|
48
|
+
if (!existsSync(file)) continue
|
|
49
|
+
const { name } = JSON.parse(readFileSync(file, 'utf8'))
|
|
50
|
+
tarballs[name] = pack(join(pkgs, dir), dest)
|
|
51
|
+
}
|
|
52
|
+
return tarballs
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** `pkg` with its kerf dependencies on the tarballs. The overrides reach the ones packages declare for each other. */
|
|
56
|
+
/**
|
|
57
|
+
* The same overrides in the app's own pnpm-workspace.yaml, when create wrote one: that file makes the app its own
|
|
58
|
+
* workspace root, and pnpm reads overrides only from there (not from package.json, nor from a workspace above it).
|
|
59
|
+
*/
|
|
60
|
+
export function pinWorkspace(dir, tarballs) {
|
|
61
|
+
const file = join(dir, 'pnpm-workspace.yaml')
|
|
62
|
+
if (!existsSync(file) || !Object.keys(tarballs).length) return
|
|
63
|
+
const lines = Object.entries(tarballs)
|
|
64
|
+
.map(([name, spec]) => ` ${JSON.stringify(name)}: ${JSON.stringify(spec)}\n`)
|
|
65
|
+
.join('')
|
|
66
|
+
writeFileSync(file, `${readFileSync(file, 'utf8')}overrides:\n${lines}`)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function pin(pkg, tarballs) {
|
|
70
|
+
for (const deps of [pkg.dependencies, pkg.devDependencies])
|
|
71
|
+
for (const name in deps) if (tarballs[name]) deps[name] = tarballs[name]
|
|
72
|
+
return {
|
|
73
|
+
...pkg,
|
|
74
|
+
overrides: { ...pkg.overrides, ...tarballs },
|
|
75
|
+
pnpm: { ...pkg.pnpm, overrides: { ...pkg.pnpm?.overrides, ...tarballs } },
|
|
76
|
+
}
|
|
77
|
+
}
|