create-authhero 0.19.0 → 0.20.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.
@@ -59,6 +59,25 @@ try {
59
59
 
60
60
  copyDirectory(sourceDir, targetDir);
61
61
 
62
+ // Also copy widget files from @authhero/widget package
63
+ const widgetSourceDir = path.join(
64
+ __dirname,
65
+ "node_modules",
66
+ "@authhero",
67
+ "widget",
68
+ "dist",
69
+ "authhero-widget",
70
+ );
71
+ const widgetTargetDir = path.join(targetDir, "u", "widget");
72
+
73
+ if (fs.existsSync(widgetSourceDir)) {
74
+ console.log("📦 Copying widget assets...");
75
+ copyDirectory(widgetSourceDir, widgetTargetDir);
76
+ } else {
77
+ console.warn(`⚠️ Widget directory not found: ${widgetSourceDir}`);
78
+ console.warn("Widget features may not work. Install @authhero/widget to enable.");
79
+ }
80
+
62
81
  console.log(`✅ Assets copied to ${targetDir}`);
63
82
  } catch (error) {
64
83
  console.error("❌ Error copying assets:", error.message);
@@ -59,6 +59,25 @@ try {
59
59
 
60
60
  copyDirectory(sourceDir, targetDir);
61
61
 
62
+ // Also copy widget files from @authhero/widget package
63
+ const widgetSourceDir = path.join(
64
+ __dirname,
65
+ "node_modules",
66
+ "@authhero",
67
+ "widget",
68
+ "dist",
69
+ "authhero-widget",
70
+ );
71
+ const widgetTargetDir = path.join(targetDir, "u", "widget");
72
+
73
+ if (fs.existsSync(widgetSourceDir)) {
74
+ console.log("📦 Copying widget assets...");
75
+ copyDirectory(widgetSourceDir, widgetTargetDir);
76
+ } else {
77
+ console.warn(`⚠️ Widget directory not found: ${widgetSourceDir}`);
78
+ console.warn("Widget features may not work. Install @authhero/widget to enable.");
79
+ }
80
+
62
81
  console.log(`✅ Assets copied to ${targetDir}`);
63
82
  } catch (error) {
64
83
  console.error("❌ Error copying assets:", error.message);
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command as A } from "commander";
3
3
  import m from "inquirer";
4
- import n from "fs";
4
+ import o from "fs";
5
5
  import i from "path";
6
6
  import { spawn as b } from "child_process";
7
7
  const D = new A(), c = {
@@ -9,8 +9,8 @@ const D = new A(), c = {
9
9
  name: "Local (SQLite)",
10
10
  description: "Local development setup with SQLite database - great for getting started",
11
11
  templateDir: "local",
12
- packageJson: (o) => ({
13
- name: o,
12
+ packageJson: (n) => ({
13
+ name: n,
14
14
  version: "1.0.0",
15
15
  type: "module",
16
16
  scripts: {
@@ -42,15 +42,16 @@ const D = new A(), c = {
42
42
  name: "Cloudflare Simple (Single Tenant)",
43
43
  description: "Single-tenant Cloudflare Workers setup with D1 database",
44
44
  templateDir: "cloudflare-simple",
45
- packageJson: (o) => ({
46
- name: o,
45
+ packageJson: (n) => ({
46
+ name: n,
47
47
  version: "1.0.0",
48
48
  type: "module",
49
49
  scripts: {
50
+ postinstall: "node copy-assets.js",
50
51
  "copy-assets": "node copy-assets.js",
51
- dev: "npm run copy-assets && wrangler dev --port 3000 --local-protocol https",
52
- "dev:remote": "npm run copy-assets && wrangler dev --port 3000 --local-protocol https --remote --config wrangler.local.toml",
53
- deploy: "npm run copy-assets && wrangler deploy --config wrangler.local.toml",
52
+ dev: "wrangler dev --port 3000 --local-protocol https",
53
+ "dev:remote": "wrangler dev --port 3000 --local-protocol https --remote --config wrangler.local.toml",
54
+ deploy: "wrangler deploy --config wrangler.local.toml",
54
55
  "db:migrate:local": "wrangler d1 migrations apply AUTH_DB --local",
55
56
  "db:migrate:remote": "wrangler d1 migrations apply AUTH_DB --remote --config wrangler.local.toml",
56
57
  migrate: "wrangler d1 migrations apply AUTH_DB --local",
@@ -62,6 +63,7 @@ const D = new A(), c = {
62
63
  dependencies: {
63
64
  "@authhero/drizzle": "latest",
64
65
  "@authhero/kysely-adapter": "latest",
66
+ "@authhero/widget": "latest",
65
67
  "@hono/swagger-ui": "^0.5.0",
66
68
  "@hono/zod-openapi": "^0.19.0",
67
69
  authhero: "latest",
@@ -83,15 +85,16 @@ const D = new A(), c = {
83
85
  name: "Cloudflare Multi-Tenant (Production)",
84
86
  description: "Production-grade multi-tenant setup with D1 database and tenant management",
85
87
  templateDir: "cloudflare-multitenant",
86
- packageJson: (o) => ({
87
- name: o,
88
+ packageJson: (n) => ({
89
+ name: n,
88
90
  version: "1.0.0",
89
91
  type: "module",
90
92
  scripts: {
93
+ postinstall: "node copy-assets.js",
91
94
  "copy-assets": "node copy-assets.js",
92
- dev: "npm run copy-assets && wrangler dev --port 3000 --local-protocol https",
93
- "dev:remote": "npm run copy-assets && wrangler dev --port 3000 --local-protocol https --remote --config wrangler.local.toml",
94
- deploy: "npm run copy-assets && wrangler deploy --config wrangler.local.toml",
95
+ dev: "wrangler dev --port 3000 --local-protocol https",
96
+ "dev:remote": "wrangler dev --port 3000 --local-protocol https --remote --config wrangler.local.toml",
97
+ deploy: "wrangler deploy --config wrangler.local.toml",
95
98
  "db:migrate:local": "wrangler d1 migrations apply AUTH_DB --local",
96
99
  "db:migrate:remote": "wrangler d1 migrations apply AUTH_DB --remote --config wrangler.local.toml",
97
100
  migrate: "wrangler d1 migrations apply AUTH_DB --local",
@@ -104,6 +107,7 @@ const D = new A(), c = {
104
107
  "@authhero/drizzle": "latest",
105
108
  "@authhero/kysely-adapter": "latest",
106
109
  "@authhero/multi-tenancy": "latest",
110
+ "@authhero/widget": "latest",
107
111
  "@hono/swagger-ui": "^0.5.0",
108
112
  "@hono/zod-openapi": "^0.19.0",
109
113
  authhero: "latest",
@@ -122,10 +126,10 @@ const D = new A(), c = {
122
126
  seedFile: "seed.ts"
123
127
  }
124
128
  };
125
- function j(o, e) {
126
- n.readdirSync(o).forEach((s) => {
127
- const a = i.join(o, s), t = i.join(e, s);
128
- n.lstatSync(a).isDirectory() ? (n.mkdirSync(t, { recursive: !0 }), j(a, t)) : n.copyFileSync(a, t);
129
+ function j(n, e) {
130
+ o.readdirSync(n).forEach((s) => {
131
+ const a = i.join(n, s), t = i.join(e, s);
132
+ o.lstatSync(a).isDirectory() ? (o.mkdirSync(t, { recursive: !0 }), j(a, t)) : o.copyFileSync(a, t);
129
133
  });
130
134
  }
131
135
  function I() {
@@ -162,9 +166,9 @@ async function main() {
162
166
  main().catch(console.error);
163
167
  `;
164
168
  }
165
- function x(o) {
166
- const e = i.join(o, ".github", "workflows");
167
- n.mkdirSync(e, { recursive: !0 });
169
+ function x(n) {
170
+ const e = i.join(n, ".github", "workflows");
171
+ o.mkdirSync(e, { recursive: !0 });
168
172
  const r = `name: Unit tests
169
173
 
170
174
  on: push
@@ -251,9 +255,9 @@ jobs:
251
255
  apiToken: \${{ secrets.PROD_CLOUDFLARE_API_TOKEN }}
252
256
  command: deploy --env production
253
257
  `;
254
- n.writeFileSync(i.join(e, "unit-tests.yml"), r), n.writeFileSync(i.join(e, "deploy-dev.yml"), s), n.writeFileSync(i.join(e, "release.yml"), a), console.log("\\n📦 GitHub CI workflows created!");
258
+ o.writeFileSync(i.join(e, "unit-tests.yml"), r), o.writeFileSync(i.join(e, "deploy-dev.yml"), s), o.writeFileSync(i.join(e, "release.yml"), a), console.log("\\n📦 GitHub CI workflows created!");
255
259
  }
256
- function C(o) {
260
+ function C(n) {
257
261
  const e = {
258
262
  branches: ["main"],
259
263
  plugins: [
@@ -262,11 +266,11 @@ function C(o) {
262
266
  "@semantic-release/github"
263
267
  ]
264
268
  };
265
- n.writeFileSync(
266
- i.join(o, ".releaserc.json"),
269
+ o.writeFileSync(
270
+ i.join(n, ".releaserc.json"),
267
271
  JSON.stringify(e, null, 2)
268
272
  );
269
- const r = i.join(o, "package.json"), s = JSON.parse(n.readFileSync(r, "utf-8"));
273
+ const r = i.join(n, "package.json"), s = JSON.parse(o.readFileSync(r, "utf-8"));
270
274
  s.devDependencies = {
271
275
  ...s.devDependencies,
272
276
  "semantic-release": "^24.0.0"
@@ -274,11 +278,11 @@ function C(o) {
274
278
  ...s.scripts,
275
279
  test: 'echo "No tests yet"',
276
280
  "type-check": "tsc --noEmit"
277
- }, n.writeFileSync(r, JSON.stringify(s, null, 2));
281
+ }, o.writeFileSync(r, JSON.stringify(s, null, 2));
278
282
  }
279
- function v(o, e) {
283
+ function v(n, e) {
280
284
  return new Promise((r, s) => {
281
- const a = b(o, [], {
285
+ const a = b(n, [], {
282
286
  cwd: e,
283
287
  shell: !0,
284
288
  stdio: "inherit"
@@ -288,9 +292,9 @@ function v(o, e) {
288
292
  }), a.on("error", s);
289
293
  });
290
294
  }
291
- function S(o, e, r) {
295
+ function S(n, e, r) {
292
296
  return new Promise((s, a) => {
293
- const t = b(o, [], {
297
+ const t = b(n, [], {
294
298
  cwd: e,
295
299
  shell: !0,
296
300
  stdio: "inherit",
@@ -307,23 +311,23 @@ D.version("1.0.0").description("Create a new AuthHero project").argument("[proje
307
311
  ).option("-e, --email <email>", "admin email address").option("-p, --password <password>", "admin password (min 8 characters)").option(
308
312
  "--package-manager <pm>",
309
313
  "package manager to use: npm, yarn, pnpm, or bun"
310
- ).option("--skip-install", "skip installing dependencies").option("--skip-migrate", "skip running database migrations").option("--skip-seed", "skip seeding the database").option("--skip-start", "skip starting the development server").option("--github-ci", "include GitHub CI workflows with semantic versioning").option("-y, --yes", "skip all prompts and use defaults/provided options").action(async (o, e) => {
314
+ ).option("--skip-install", "skip installing dependencies").option("--skip-migrate", "skip running database migrations").option("--skip-seed", "skip seeding the database").option("--skip-start", "skip starting the development server").option("--github-ci", "include GitHub CI workflows with semantic versioning").option("-y, --yes", "skip all prompts and use defaults/provided options").action(async (n, e) => {
311
315
  const r = e.yes === !0;
312
316
  console.log(`
313
317
  🔐 Welcome to AuthHero!
314
318
  `);
315
- let s = o;
319
+ let s = n;
316
320
  s || (r ? (s = "auth-server", console.log(`Using default project name: ${s}`)) : s = (await m.prompt([
317
321
  {
318
322
  type: "input",
319
323
  name: "projectName",
320
324
  message: "Project name:",
321
325
  default: "auth-server",
322
- validate: (p) => p !== "" || "Project name cannot be empty"
326
+ validate: (d) => d !== "" || "Project name cannot be empty"
323
327
  }
324
328
  ])).projectName);
325
329
  const a = i.join(process.cwd(), s);
326
- n.existsSync(a) && (console.error(`❌ Project "${s}" already exists.`), process.exit(1));
330
+ o.existsSync(a) && (console.error(`❌ Project "${s}" already exists.`), process.exit(1));
327
331
  let t;
328
332
  e.template ? (["local", "cloudflare-simple", "cloudflare-multitenant"].includes(
329
333
  e.template
@@ -357,7 +361,7 @@ D.version("1.0.0").description("Create a new AuthHero project").argument("[proje
357
361
  }
358
362
  ])).setupType;
359
363
  const f = c[t];
360
- n.mkdirSync(a, { recursive: !0 }), n.writeFileSync(
364
+ o.mkdirSync(a, { recursive: !0 }), o.writeFileSync(
361
365
  i.join(a, "package.json"),
362
366
  JSON.stringify(f.packageJson(s), null, 2)
363
367
  );
@@ -365,25 +369,25 @@ D.version("1.0.0").description("Create a new AuthHero project").argument("[proje
365
369
  import.meta.url.replace("file://", "").replace("/create-authhero.js", ""),
366
370
  f.templateDir
367
371
  );
368
- if (n.existsSync(k) ? j(k, a) : (console.error(`❌ Template directory not found: ${k}`), process.exit(1)), t === "cloudflare-simple" || t === "cloudflare-multitenant") {
369
- const l = i.join(a, "wrangler.toml"), p = i.join(a, "wrangler.local.toml");
370
- n.existsSync(l) && n.copyFileSync(l, p);
371
- const d = i.join(a, ".dev.vars.example"), u = i.join(a, ".dev.vars");
372
- n.existsSync(d) && n.copyFileSync(d, u), console.log(
372
+ if (o.existsSync(k) ? j(k, a) : (console.error(`❌ Template directory not found: ${k}`), process.exit(1)), t === "cloudflare-simple" || t === "cloudflare-multitenant") {
373
+ const l = i.join(a, "wrangler.toml"), d = i.join(a, "wrangler.local.toml");
374
+ o.existsSync(l) && o.copyFileSync(l, d);
375
+ const p = i.join(a, ".dev.vars.example"), u = i.join(a, ".dev.vars");
376
+ o.existsSync(p) && o.copyFileSync(p, u), console.log(
373
377
  "📁 Created wrangler.local.toml and .dev.vars for local development"
374
378
  );
375
379
  }
376
- let y = !1;
377
- if ((t === "cloudflare-simple" || t === "cloudflare-multitenant") && (e.githubCi !== void 0 ? (y = e.githubCi, y && console.log("Including GitHub CI workflows with semantic versioning")) : r || (y = (await m.prompt([
380
+ let w = !1;
381
+ if ((t === "cloudflare-simple" || t === "cloudflare-multitenant") && (e.githubCi !== void 0 ? (w = e.githubCi, w && console.log("Including GitHub CI workflows with semantic versioning")) : r || (w = (await m.prompt([
378
382
  {
379
383
  type: "confirm",
380
384
  name: "includeGithubCi",
381
385
  message: "Would you like to include GitHub CI with semantic versioning?",
382
386
  default: !1
383
387
  }
384
- ])).includeGithubCi), y && (x(a), C(a))), t === "local") {
388
+ ])).includeGithubCi), w && (x(a), C(a))), t === "local") {
385
389
  const l = I();
386
- n.writeFileSync(i.join(a, "src/seed.ts"), l);
390
+ o.writeFileSync(i.join(a, "src/seed.ts"), l);
387
391
  }
388
392
  console.log(
389
393
  `
@@ -419,8 +423,8 @@ D.version("1.0.0").description("Create a new AuthHero project").argument("[proje
419
423
  📦 Installing dependencies with ${l}...
420
424
  `);
421
425
  try {
422
- const p = l === "pnpm" ? "pnpm install --ignore-workspace" : `${l} install`;
423
- if (await v(p, a), t === "local" && (console.log(`
426
+ const d = l === "pnpm" ? "pnpm install --ignore-workspace" : `${l} install`;
427
+ if (await v(d, a), t === "local" && (console.log(`
424
428
  🔧 Building native modules...
425
429
  `), await v("npm rebuild better-sqlite3", a)), console.log(`
426
430
  ✅ Dependencies installed successfully!
@@ -444,14 +448,14 @@ D.version("1.0.0").description("Create a new AuthHero project").argument("[proje
444
448
  name: "username",
445
449
  message: "Admin email:",
446
450
  default: "admin@example.com",
447
- validate: (w) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(w) || "Please enter a valid email address"
451
+ validate: (y) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(y) || "Please enter a valid email address"
448
452
  },
449
453
  {
450
454
  type: "password",
451
455
  name: "password",
452
456
  message: "Admin password:",
453
457
  mask: "*",
454
- validate: (w) => w.length < 8 ? "Password must be at least 8 characters" : !0
458
+ validate: (y) => y.length < 8 ? "Password must be at least 8 characters" : !0
455
459
  }
456
460
  ]), e.skipMigrate || (console.log(`
457
461
  🔄 Running migrations...
@@ -474,27 +478,27 @@ D.version("1.0.0").description("Create a new AuthHero project").argument("[proje
474
478
  ));
475
479
  }
476
480
  }
477
- let d;
478
- e.skipStart || r ? d = !1 : d = (await m.prompt([
481
+ let p;
482
+ e.skipStart || r ? p = !1 : p = (await m.prompt([
479
483
  {
480
484
  type: "confirm",
481
485
  name: "shouldStart",
482
486
  message: "Would you like to start the development server?",
483
487
  default: !0
484
488
  }
485
- ])).shouldStart, d && (console.log(
489
+ ])).shouldStart, p && (console.log(
486
490
  `
487
491
  🚀 Starting development server on https://localhost:3000 ...
488
492
  `
489
- ), await v(`${l} run dev`, a)), r && !d && (console.log(`
493
+ ), await v(`${l} run dev`, a)), r && !p && (console.log(`
490
494
  ✅ Setup complete!`), console.log(`
491
495
  To start the development server:`), console.log(` cd ${s}`), console.log(" npm run dev"), (t === "cloudflare-simple" || t === "cloudflare-multitenant") && console.log(
492
496
  `
493
497
  Server will be available at: https://localhost:3000`
494
498
  ));
495
- } catch (p) {
499
+ } catch (d) {
496
500
  console.error(`
497
- ❌ An error occurred:`, p), process.exit(1);
501
+ ❌ An error occurred:`, d), process.exit(1);
498
502
  }
499
503
  }
500
504
  h || (console.log("Next steps:"), console.log(` cd ${s}`), t === "local" ? (console.log(" npm install"), console.log(" npm run migrate"), console.log(
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "https://github.com/markusahlstrand/authhero"
7
7
  },
8
- "version": "0.19.0",
8
+ "version": "0.20.0",
9
9
  "type": "module",
10
10
  "main": "dist/create-authhero.js",
11
11
  "bin": {