create-user-hub 0.1.2 → 0.1.4

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/index.js CHANGED
@@ -117,13 +117,16 @@ if (hubUrl && !(await hubAnswers(hubUrl))) {
117
117
 
118
118
  console.log(`\nCreating ${name} in ${dest}`);
119
119
  await cp(TEMPLATE, dest, { recursive: true });
120
- // npm drops .gitignore from packages, so the template ships it as gitignore.
120
+ // npm drops .gitignore from packages, so the template ships it as gitignore;
121
+ // .dockerignore travels the same way to be safe.
121
122
  await rename(join(dest, "gitignore"), join(dest, ".gitignore"));
123
+ await rename(join(dest, "dockerignore"), join(dest, ".dockerignore"));
122
124
 
123
125
  for (const file of [
124
126
  "package.json",
125
127
  "README.md",
126
128
  "CLAUDE.md",
129
+ "justfile",
127
130
  "src/routes/__root.tsx",
128
131
  "convex/hub.ts",
129
132
  ]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-user-hub",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Start a TanStack Start + Convex app with User Hub sign-in: bun create user-hub@latest my-app",
5
5
  "type": "module",
6
6
  "bin": {
@@ -4,4 +4,4 @@ HUB_ADMIN_PASSWORD=
4
4
 
5
5
  # Written by bun run setup and the Convex CLI:
6
6
  # CONVEX_DEPLOYMENT, VITE_CONVEX_URL, VITE_HUB_URL, HUB_APP_NAME (this app's
7
- # name in the hub, once registered)
7
+ # name in the hub, once registered), HUB_APP_PROD_URL (once given)
@@ -21,4 +21,4 @@ A TanStack Start + Convex app whose sign-in comes from User Hub: people scan the
21
21
 
22
22
  ## Commands
23
23
 
24
- `bun run setup` (once), `bun run dev`, `bun run check`, `bun run typecheck`, `bun run build`.
24
+ `bun run setup` (once), `bun run setup --prod <url>` (once deployed: registers the production URL so badge scans can reach the app; see the skill's "Production URL"), `bun run dev`, `bun run check`, `bun run typecheck`, `bun run build`, `just build` / `just push` (deploy Convex to production and build the Docker image against it; `IMAGE` sets the registry path; the container needs no env).
@@ -0,0 +1,36 @@
1
+ # syntax=docker/dockerfile:1
2
+
3
+ # TanStack Start built by Vite, served by Bun (server.ts). Build it with
4
+ # `just build` or `just push`, which also deploy Convex to production.
5
+ FROM oven/bun:1.4-slim AS base
6
+ WORKDIR /app
7
+
8
+ # Dependencies, cached while package.json and the lockfile are unchanged.
9
+ FROM base AS deps
10
+ COPY --link bun.lock package.json ./
11
+ RUN bun install --frozen-lockfile
12
+
13
+ # Build: vite build emits dist/client and dist/server/server.js. Both VITE_
14
+ # values are public and inlined into the bundle, so they are build arguments.
15
+ FROM deps AS build
16
+ COPY . .
17
+ ARG VITE_CONVEX_URL
18
+ ARG VITE_HUB_URL
19
+ RUN test -n "$VITE_CONVEX_URL" -a -n "$VITE_HUB_URL" || (echo "Pass --build-arg VITE_CONVEX_URL=… and --build-arg VITE_HUB_URL=…, or run just build" && exit 1)
20
+ ENV NODE_ENV=production CI=1 VITE_CONVEX_URL=${VITE_CONVEX_URL} VITE_HUB_URL=${VITE_HUB_URL}
21
+ RUN rm -rf dist .tanstack node_modules/.vite && bunx --bun vite build && bun run typecheck
22
+
23
+ # Production dependencies only.
24
+ FROM base AS prod-deps
25
+ COPY --link bun.lock package.json ./
26
+ RUN bun install --frozen-lockfile --production
27
+
28
+ # Runtime: no environment needed. Convex holds HUB_ISSUER and HUB_JWKS.
29
+ FROM base AS runner
30
+ ENV NODE_ENV=production PORT=3000
31
+ COPY --from=prod-deps /app/node_modules ./node_modules
32
+ COPY --from=build /app/dist ./dist
33
+ COPY --link server.ts package.json ./
34
+ USER bun
35
+ EXPOSE 3000
36
+ CMD ["bun", "run", "server.ts"]
@@ -13,6 +13,16 @@ A TanStack Start + Convex app with User Hub sign-in: people scan their badge and
13
13
 
14
14
  2. `bun run setup`: creates your Convex project, registers the app with the hub and sets everything up. If another app already has this name in the hub, it asks you for a new one (or run `bun run setup --name <name>`). Safe to run again.
15
15
  3. `bun run dev`, then open http://localhost:3000. You are sent to the hub to pick who to be, then back signed in.
16
+ 4. Once the app is deployed: `bun run setup --prod https://your-app.example.com`, so badge scans can reach it. Setup asks for this the first time; press Enter to skip until you deploy.
17
+
18
+ ## Deploy
19
+
20
+ The app ships as a Docker image served by Bun (`Dockerfile`, `server.ts`); it needs no environment variables at runtime. With [just](https://just.systems) and Docker:
21
+
22
+ - `just build`: deploys the Convex functions to production, then builds the image against that deployment and loads it into Docker. Try it with `docker run -p 3000:3000 __APP_KEY__`.
23
+ - `just push`: the same, built for servers (amd64) and pushed. Set your registry path first: `IMAGE=registry.example.com/team/__APP_KEY__ just push`, or edit `image` at the top of the `justfile`.
24
+
25
+ Then serve the container (port 3000) at your production URL, make sure the hub knows that URL (`bun run setup --prod <url>`), and schedule the app in the hub or force it live.
16
26
 
17
27
  ## What's inside
18
28
 
@@ -23,6 +33,6 @@ A TanStack Start + Convex app with User Hub sign-in: people scan their badge and
23
33
 
24
34
  ## Commands
25
35
 
26
- `bun run dev`, `bun run check` (Biome), `bun run typecheck`, `bun run build`, `bun run start` (production server).
36
+ `bun run dev`, `bun run check` (Biome), `bun run typecheck`, `bun run build`, `bun run start` (production server), `just build`, `just push`.
27
37
 
28
38
  Coding agents: see `CLAUDE.md` and the `user-hub-auth` skill in `.claude/skills`.
@@ -0,0 +1,32 @@
1
+ # Rebuilt inside the image
2
+ node_modules
3
+ dist
4
+ .output
5
+ .tanstack
6
+ .nitro
7
+ .vinxi
8
+
9
+ # Local env and secrets: the public build values come in as build arguments
10
+ .env
11
+ .env.*
12
+ !.env.example
13
+
14
+ # VCS, editors, OS. .gitignore stays: Tailwind v4 reads it to decide what to
15
+ # scan, so without it the image's CSS differs from a local build.
16
+ .git
17
+ .DS_Store
18
+ .idea
19
+ .vscode
20
+
21
+ # Agent files
22
+ .agents
23
+ .claude
24
+
25
+ # Not needed to build or run
26
+ scripts
27
+ justfile
28
+ README.md
29
+ AGENTS.md
30
+ CLAUDE.md
31
+ Dockerfile
32
+ .dockerignore
@@ -0,0 +1,19 @@
1
+ # Production image. Both recipes deploy the Convex functions to production
2
+ # first and build the image against that deployment: `convex deploy --cmd`
3
+ # hands the build the production VITE_CONVEX_URL, and VITE_HUB_URL comes from
4
+ # .env.local (written by bun run setup).
5
+
6
+ set dotenv-load
7
+ set dotenv-filename := ".env.local"
8
+
9
+ # Your registry path, e.g. registry.example.com/team/__APP_KEY__ (or IMAGE=…).
10
+ image := env("IMAGE", "__APP_KEY__")
11
+ tag := env("TAG", "latest")
12
+
13
+ # Deploy Convex, then build the image for this machine and load it into Docker
14
+ build:
15
+ bunx convex deploy --cmd 'docker build --build-arg VITE_CONVEX_URL="$VITE_CONVEX_URL" --build-arg VITE_HUB_URL="$VITE_HUB_URL" -t {{image}}:{{tag}} --load .'
16
+
17
+ # Deploy Convex, then build the image for servers (amd64) and push it
18
+ push:
19
+ bunx convex deploy --cmd 'docker build --platform linux/amd64 --build-arg VITE_CONVEX_URL="$VITE_CONVEX_URL" --build-arg VITE_HUB_URL="$VITE_HUB_URL" -t {{image}}:{{tag}} --push .'
@@ -1,6 +1,7 @@
1
- // One-time setup: creates the Convex project, registers this app with User
2
- // Hub and sets the values that make Convex trust the hub's tokens.
3
- // Run: bun run setup [--name <name>]. Safe to run again.
1
+ // Setup: creates the Convex project, registers this app with User Hub and
2
+ // sets the values that make Convex trust the hub's tokens.
3
+ // Run: bun run setup [--name <name>] [--prod <url>]. Safe to run again; run
4
+ // it with --prod once the app is deployed so badge scans can reach it.
4
5
  // Needs HUB_URL and HUB_ADMIN_PASSWORD in .env.local (Bun loads it).
5
6
 
6
7
  import { existsSync, renameSync } from "node:fs";
@@ -12,6 +13,12 @@ const DEV_URL = "http://localhost:3000";
12
13
  const AUTH_CONFIG = "convex/auth.config.ts";
13
14
  const AUTH_CONFIG_ASIDE = "convex/auth.config.ts.setup";
14
15
 
16
+ // The value after --flag on the command line, if any.
17
+ function flag(name: string) {
18
+ const at = process.argv.indexOf(`--${name}`);
19
+ return at > -1 ? process.argv[at + 1]?.trim() || undefined : undefined;
20
+ }
21
+
15
22
  function step(message: string) {
16
23
  console.log(`\n▸ ${message}`);
17
24
  }
@@ -93,12 +100,18 @@ const packageName = (
93
100
  ).name;
94
101
  // HUB_APP_NAME is written only after a successful registration, so it marks
95
102
  // this app's own entry. `bun run setup --name <name>` picks a new name.
96
- const nameFlag = process.argv.indexOf("--name");
97
103
  const alreadyRegistered = Boolean(process.env.HUB_APP_NAME);
98
- let appName =
99
- process.env.HUB_APP_NAME ??
100
- (nameFlag > -1 ? process.argv[nameFlag + 1] : undefined) ??
101
- packageName;
104
+ let appName = process.env.HUB_APP_NAME ?? flag("name") ?? packageName;
105
+
106
+ // Where badge scans send people. Asked once in a terminal; skipped until the
107
+ // app is deployed, then added with --prod. HUB_APP_PROD_URL remembers it.
108
+ let prodUrl = flag("prod");
109
+ if (!prodUrl && !process.env.HUB_APP_PROD_URL && process.stdin.isTTY) {
110
+ prodUrl =
111
+ prompt(
112
+ " Production URL, where badge scans send people (Enter to skip until you deploy):",
113
+ )?.trim() || undefined;
114
+ }
102
115
  let registered: Awaited<ReturnType<typeof run>>;
103
116
  for (;;) {
104
117
  registered = await run(
@@ -110,6 +123,7 @@ for (;;) {
110
123
  appName,
111
124
  "--dev",
112
125
  DEV_URL,
126
+ ...(prodUrl ? ["--prod", prodUrl] : []),
113
127
  "--json",
114
128
  ...(alreadyRegistered ? [] : ["--new"]),
115
129
  ],
@@ -126,7 +140,9 @@ for (;;) {
126
140
  }
127
141
  if (!registered.ok) {
128
142
  fail(
129
- "The hub refused the registration. Check HUB_URL and HUB_ADMIN_PASSWORD.",
143
+ prodUrl
144
+ ? "The hub refused the registration; see the error above. Check HUB_URL, HUB_ADMIN_PASSWORD and that the production URL is a full https:// address."
145
+ : "The hub refused the registration; see the error above. Check HUB_URL and HUB_ADMIN_PASSWORD.",
130
146
  );
131
147
  }
132
148
  const { key, hubUrl, env } = JSON.parse(registered.output) as {
@@ -135,6 +151,8 @@ const { key, hubUrl, env } = JSON.parse(registered.output) as {
135
151
  env: { HUB_ISSUER: string; HUB_JWKS: string };
136
152
  };
137
153
  await writeEnv("HUB_APP_NAME", appName);
154
+ if (prodUrl) await writeEnv("HUB_APP_PROD_URL", prodUrl);
155
+ const production = prodUrl ?? process.env.HUB_APP_PROD_URL;
138
156
  console.log(` Registered as "${appName}", app key: ${key}`);
139
157
 
140
158
  // The key follows the registered name; keep the code in step with it.
@@ -153,15 +171,46 @@ for (const [variable, value] of Object.entries(env)) {
153
171
  }
154
172
  await writeEnv("VITE_HUB_URL", hubUrl);
155
173
 
174
+ // The production Convex deployment needs the same two values once the app is
175
+ // deployed. It may not exist yet: then say how to set them later.
176
+ let productionEnvSet = false;
177
+ if (production) {
178
+ step("Setting HUB_ISSUER and HUB_JWKS on the production Convex deployment");
179
+ productionEnvSet = true;
180
+ for (const [variable, value] of Object.entries(env)) {
181
+ const result = await run(
182
+ ["bunx", "convex", "env", "set", "--prod", variable, value],
183
+ { capture: true },
184
+ );
185
+ productionEnvSet &&= result.ok;
186
+ }
187
+ }
188
+
156
189
  // 4. Push the functions now that auth is configured.
157
190
  step("Deploying the Convex functions");
158
191
  if (!(await run(["bunx", "convex", "dev", "--once"])).ok) {
159
192
  fail("Convex did not accept the functions; see the error above.");
160
193
  }
161
194
 
195
+ const productionNote = production
196
+ ? productionEnvSet
197
+ ? `Production: ${production}. Badge scans reach it once the app is scheduled
198
+ or forced live in the hub. Deploy Convex with: bunx convex deploy`
199
+ : `Production: ${production} is registered with the hub, but HUB_ISSUER
200
+ and HUB_JWKS could not be set on the production Convex deployment (see the
201
+ error above). Run bun run setup again before \`bunx convex deploy\`.`
202
+ : `No production URL yet, so badge scans cannot reach this app. Once it is
203
+ deployed, run:
204
+
205
+ bun run setup --prod https://your-app.example.com
206
+
207
+ (or ask your coding agent to set up the production URL).`;
208
+
162
209
  console.log(`
163
210
  ✓ Ready. Start the app:
164
211
 
165
212
  bun run dev
166
213
 
167
- Open ${DEV_URL}: you are sent to the hub to pick who to be, then back signed in.`);
214
+ Open ${DEV_URL}: you are sent to the hub to pick who to be, then back signed in.
215
+
216
+ ${productionNote}`);