create-authhero 0.21.0 → 0.22.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/create-authhero.js +103 -193
- package/package.json +1 -1
package/dist/create-authhero.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Command as
|
|
2
|
+
import { Command as T } from "commander";
|
|
3
3
|
import d from "inquirer";
|
|
4
4
|
import s from "fs";
|
|
5
|
-
import
|
|
6
|
-
import { spawn as
|
|
7
|
-
const
|
|
5
|
+
import i from "path";
|
|
6
|
+
import { spawn as D } from "child_process";
|
|
7
|
+
const I = new T(), m = {
|
|
8
8
|
local: {
|
|
9
9
|
name: "Local (SQLite)",
|
|
10
10
|
description: "Local development setup with SQLite database - great for getting started",
|
|
@@ -85,10 +85,10 @@ const P = new b(), m = {
|
|
|
85
85
|
seedFile: "seed.ts"
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
|
-
function
|
|
88
|
+
function x(t, e) {
|
|
89
89
|
s.readdirSync(t).forEach((o) => {
|
|
90
|
-
const n =
|
|
91
|
-
s.lstatSync(n).isDirectory() ? (s.mkdirSync(
|
|
90
|
+
const n = i.join(t, o), r = i.join(e, o);
|
|
91
|
+
s.lstatSync(n).isDirectory() ? (s.mkdirSync(r, { recursive: !0 }), x(n, r)) : s.copyFileSync(n, r);
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
function E(t) {
|
|
@@ -128,77 +128,32 @@ async function main() {
|
|
|
128
128
|
main().catch(console.error);
|
|
129
129
|
`;
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function j(t) {
|
|
132
132
|
return t ? `import { Context } from "hono";
|
|
133
|
-
import { HTTPException } from "hono/http-exception";
|
|
134
133
|
import { swaggerUI } from "@hono/swagger-ui";
|
|
135
|
-
import {
|
|
134
|
+
import { AuthHeroConfig } from "authhero";
|
|
136
135
|
import { serveStatic } from "@hono/node-server/serve-static";
|
|
137
|
-
import {
|
|
138
|
-
createSyncHooks,
|
|
139
|
-
createTenantsOpenAPIRouter,
|
|
140
|
-
createProtectSyncedMiddleware,
|
|
141
|
-
} from "@authhero/multi-tenancy";
|
|
136
|
+
import { initMultiTenant } from "@authhero/multi-tenancy";
|
|
142
137
|
import { DataAdapters } from "@authhero/adapter-interfaces";
|
|
143
138
|
|
|
144
139
|
// Control plane tenant ID - the tenant that manages all other tenants
|
|
145
140
|
const CONTROL_PLANE_TENANT_ID = "control_plane";
|
|
146
141
|
|
|
147
142
|
export default function createApp(config: AuthHeroConfig & { dataAdapter: DataAdapters }) {
|
|
148
|
-
//
|
|
149
|
-
const {
|
|
150
|
-
controlPlaneTenantId: CONTROL_PLANE_TENANT_ID,
|
|
151
|
-
getChildTenantIds: async () => {
|
|
152
|
-
const allTenants = await fetchAll<{ id: string }>(
|
|
153
|
-
(params) => config.dataAdapter.tenants.list(params),
|
|
154
|
-
"tenants",
|
|
155
|
-
{ cursorField: "id", pageSize: 100 },
|
|
156
|
-
);
|
|
157
|
-
return allTenants
|
|
158
|
-
.filter((t) => t.id !== CONTROL_PLANE_TENANT_ID)
|
|
159
|
-
.map((t) => t.id);
|
|
160
|
-
},
|
|
161
|
-
getAdapters: async () => config.dataAdapter,
|
|
162
|
-
getControlPlaneAdapters: async () => config.dataAdapter,
|
|
163
|
-
sync: {
|
|
164
|
-
resourceServers: true,
|
|
165
|
-
roles: true,
|
|
166
|
-
connections: true,
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// Create tenants router
|
|
171
|
-
const tenantsRouter = createTenantsOpenAPIRouter(
|
|
172
|
-
{
|
|
173
|
-
accessControl: {
|
|
174
|
-
controlPlaneTenantId: CONTROL_PLANE_TENANT_ID,
|
|
175
|
-
requireOrganizationMatch: false,
|
|
176
|
-
defaultPermissions: ["tenant:admin"],
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
{ tenants: tenantHooks },
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
// Initialize AuthHero with sync hooks and tenant routes
|
|
183
|
-
const { app } = init({
|
|
143
|
+
// Initialize multi-tenant AuthHero - syncs resource servers, roles, and connections by default
|
|
144
|
+
const { app } = initMultiTenant({
|
|
184
145
|
...config,
|
|
185
|
-
|
|
186
|
-
managementApiExtensions: [
|
|
187
|
-
...(config.managementApiExtensions || []),
|
|
188
|
-
{ path: "/tenants", router: tenantsRouter },
|
|
189
|
-
],
|
|
146
|
+
controlPlaneTenantId: CONTROL_PLANE_TENANT_ID,
|
|
190
147
|
});
|
|
191
148
|
|
|
192
|
-
// Add middleware to protect synced entities from modification on child tenants
|
|
193
|
-
app.use("/api/v2/*", createProtectSyncedMiddleware());
|
|
194
|
-
|
|
195
149
|
app
|
|
196
150
|
.onError((err, ctx) => {
|
|
197
|
-
|
|
198
|
-
|
|
151
|
+
// Use duck-typing to avoid instanceof issues with bundled dependencies
|
|
152
|
+
if (err && typeof err === "object" && "getResponse" in err) {
|
|
153
|
+
return (err as { getResponse: () => Response }).getResponse();
|
|
199
154
|
}
|
|
200
155
|
console.error(err);
|
|
201
|
-
return ctx.text(err.message, 500);
|
|
156
|
+
return ctx.text(err instanceof Error ? err.message : "Internal Server Error", 500);
|
|
202
157
|
})
|
|
203
158
|
.get("/", async (ctx: Context) => {
|
|
204
159
|
return ctx.json({
|
|
@@ -230,7 +185,6 @@ export default function createApp(config: AuthHeroConfig & { dataAdapter: DataAd
|
|
|
230
185
|
return app;
|
|
231
186
|
}
|
|
232
187
|
` : `import { Context } from "hono";
|
|
233
|
-
import { HTTPException } from "hono/http-exception";
|
|
234
188
|
import { AuthHeroConfig, init } from "authhero";
|
|
235
189
|
import { swaggerUI } from "@hono/swagger-ui";
|
|
236
190
|
import { serveStatic } from "@hono/node-server/serve-static";
|
|
@@ -240,11 +194,12 @@ export default function createApp(config: AuthHeroConfig) {
|
|
|
240
194
|
|
|
241
195
|
app
|
|
242
196
|
.onError((err, ctx) => {
|
|
243
|
-
|
|
244
|
-
|
|
197
|
+
// Use duck-typing to avoid instanceof issues with bundled dependencies
|
|
198
|
+
if (err && typeof err === "object" && "getResponse" in err) {
|
|
199
|
+
return (err as { getResponse: () => Response }).getResponse();
|
|
245
200
|
}
|
|
246
201
|
console.error(err);
|
|
247
|
-
return ctx.text(err.message, 500);
|
|
202
|
+
return ctx.text(err instanceof Error ? err.message : "Internal Server Error", 500);
|
|
248
203
|
})
|
|
249
204
|
.get("/", async (ctx: Context) => {
|
|
250
205
|
return ctx.json({
|
|
@@ -274,7 +229,7 @@ export default function createApp(config: AuthHeroConfig) {
|
|
|
274
229
|
}
|
|
275
230
|
`;
|
|
276
231
|
}
|
|
277
|
-
function
|
|
232
|
+
function _(t) {
|
|
278
233
|
return `import { D1Dialect } from "kysely-d1";
|
|
279
234
|
import { Kysely } from "kysely";
|
|
280
235
|
import createAdapters from "@authhero/kysely-adapter";
|
|
@@ -347,76 +302,31 @@ export default {
|
|
|
347
302
|
};
|
|
348
303
|
`;
|
|
349
304
|
}
|
|
350
|
-
function
|
|
305
|
+
function R(t) {
|
|
351
306
|
return t ? `import { Context } from "hono";
|
|
352
|
-
import { HTTPException } from "hono/http-exception";
|
|
353
307
|
import { swaggerUI } from "@hono/swagger-ui";
|
|
354
|
-
import {
|
|
355
|
-
import {
|
|
356
|
-
createSyncHooks,
|
|
357
|
-
createTenantsOpenAPIRouter,
|
|
358
|
-
createProtectSyncedMiddleware,
|
|
359
|
-
} from "@authhero/multi-tenancy";
|
|
308
|
+
import { AuthHeroConfig } from "authhero";
|
|
309
|
+
import { initMultiTenant } from "@authhero/multi-tenancy";
|
|
360
310
|
import { DataAdapters } from "@authhero/adapter-interfaces";
|
|
361
311
|
|
|
362
312
|
// Control plane tenant ID - the tenant that manages all other tenants
|
|
363
313
|
const CONTROL_PLANE_TENANT_ID = "control_plane";
|
|
364
314
|
|
|
365
315
|
export default function createApp(config: AuthHeroConfig & { dataAdapter: DataAdapters }) {
|
|
366
|
-
//
|
|
367
|
-
const {
|
|
368
|
-
controlPlaneTenantId: CONTROL_PLANE_TENANT_ID,
|
|
369
|
-
getChildTenantIds: async () => {
|
|
370
|
-
const allTenants = await fetchAll<{ id: string }>(
|
|
371
|
-
(params) => config.dataAdapter.tenants.list(params),
|
|
372
|
-
"tenants",
|
|
373
|
-
{ cursorField: "id", pageSize: 100 },
|
|
374
|
-
);
|
|
375
|
-
return allTenants
|
|
376
|
-
.filter((t) => t.id !== CONTROL_PLANE_TENANT_ID)
|
|
377
|
-
.map((t) => t.id);
|
|
378
|
-
},
|
|
379
|
-
getAdapters: async () => config.dataAdapter,
|
|
380
|
-
getControlPlaneAdapters: async () => config.dataAdapter,
|
|
381
|
-
sync: {
|
|
382
|
-
resourceServers: true,
|
|
383
|
-
roles: true,
|
|
384
|
-
connections: true,
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
// Create tenants router
|
|
389
|
-
const tenantsRouter = createTenantsOpenAPIRouter(
|
|
390
|
-
{
|
|
391
|
-
accessControl: {
|
|
392
|
-
controlPlaneTenantId: CONTROL_PLANE_TENANT_ID,
|
|
393
|
-
requireOrganizationMatch: false,
|
|
394
|
-
defaultPermissions: ["tenant:admin"],
|
|
395
|
-
},
|
|
396
|
-
},
|
|
397
|
-
{ tenants: tenantHooks },
|
|
398
|
-
);
|
|
399
|
-
|
|
400
|
-
// Initialize AuthHero with sync hooks and tenant routes
|
|
401
|
-
const { app } = init({
|
|
316
|
+
// Initialize multi-tenant AuthHero - syncs resource servers, roles, and connections by default
|
|
317
|
+
const { app } = initMultiTenant({
|
|
402
318
|
...config,
|
|
403
|
-
|
|
404
|
-
managementApiExtensions: [
|
|
405
|
-
...(config.managementApiExtensions || []),
|
|
406
|
-
{ path: "/tenants", router: tenantsRouter },
|
|
407
|
-
],
|
|
319
|
+
controlPlaneTenantId: CONTROL_PLANE_TENANT_ID,
|
|
408
320
|
});
|
|
409
321
|
|
|
410
|
-
// Add middleware to protect synced entities from modification on child tenants
|
|
411
|
-
app.use("/api/v2/*", createProtectSyncedMiddleware());
|
|
412
|
-
|
|
413
322
|
app
|
|
414
323
|
.onError((err, ctx) => {
|
|
415
|
-
|
|
416
|
-
|
|
324
|
+
// Use duck-typing to avoid instanceof issues with bundled dependencies
|
|
325
|
+
if (err && typeof err === "object" && "getResponse" in err) {
|
|
326
|
+
return (err as { getResponse: () => Response }).getResponse();
|
|
417
327
|
}
|
|
418
328
|
console.error(err);
|
|
419
|
-
return ctx.text(err.message, 500);
|
|
329
|
+
return ctx.text(err instanceof Error ? err.message : "Internal Server Error", 500);
|
|
420
330
|
})
|
|
421
331
|
.get("/", async (ctx: Context) => {
|
|
422
332
|
return ctx.json({
|
|
@@ -432,7 +342,6 @@ export default function createApp(config: AuthHeroConfig & { dataAdapter: DataAd
|
|
|
432
342
|
return app;
|
|
433
343
|
}
|
|
434
344
|
` : `import { Context } from "hono";
|
|
435
|
-
import { HTTPException } from "hono/http-exception";
|
|
436
345
|
import { cors } from "hono/cors";
|
|
437
346
|
import { AuthHeroConfig, init } from "authhero";
|
|
438
347
|
import { swaggerUI } from "@hono/swagger-ui";
|
|
@@ -451,11 +360,12 @@ export default function createApp(config: AuthHeroConfig) {
|
|
|
451
360
|
|
|
452
361
|
app
|
|
453
362
|
.onError((err, ctx) => {
|
|
454
|
-
|
|
455
|
-
|
|
363
|
+
// Use duck-typing to avoid instanceof issues with bundled dependencies
|
|
364
|
+
if (err && typeof err === "object" && "getResponse" in err) {
|
|
365
|
+
return (err as { getResponse: () => Response }).getResponse();
|
|
456
366
|
}
|
|
457
367
|
console.error(err);
|
|
458
|
-
return ctx.text(err.message, 500);
|
|
368
|
+
return ctx.text(err instanceof Error ? err.message : "Internal Server Error", 500);
|
|
459
369
|
})
|
|
460
370
|
.get("/", async (ctx: Context) => {
|
|
461
371
|
return ctx.json({
|
|
@@ -469,10 +379,10 @@ export default function createApp(config: AuthHeroConfig) {
|
|
|
469
379
|
}
|
|
470
380
|
`;
|
|
471
381
|
}
|
|
472
|
-
function
|
|
473
|
-
const e =
|
|
382
|
+
function M(t) {
|
|
383
|
+
const e = i.join(t, ".github", "workflows");
|
|
474
384
|
s.mkdirSync(e, { recursive: !0 });
|
|
475
|
-
const
|
|
385
|
+
const a = `name: Unit tests
|
|
476
386
|
|
|
477
387
|
on: push
|
|
478
388
|
|
|
@@ -558,9 +468,9 @@ jobs:
|
|
|
558
468
|
apiToken: \${{ secrets.PROD_CLOUDFLARE_API_TOKEN }}
|
|
559
469
|
command: deploy --env production
|
|
560
470
|
`;
|
|
561
|
-
s.writeFileSync(
|
|
471
|
+
s.writeFileSync(i.join(e, "unit-tests.yml"), a), s.writeFileSync(i.join(e, "deploy-dev.yml"), o), s.writeFileSync(i.join(e, "release.yml"), n), console.log("\\n📦 GitHub CI workflows created!");
|
|
562
472
|
}
|
|
563
|
-
function
|
|
473
|
+
function $(t) {
|
|
564
474
|
const e = {
|
|
565
475
|
branches: ["main"],
|
|
566
476
|
plugins: [
|
|
@@ -570,10 +480,10 @@ function O(t) {
|
|
|
570
480
|
]
|
|
571
481
|
};
|
|
572
482
|
s.writeFileSync(
|
|
573
|
-
|
|
483
|
+
i.join(t, ".releaserc.json"),
|
|
574
484
|
JSON.stringify(e, null, 2)
|
|
575
485
|
);
|
|
576
|
-
const
|
|
486
|
+
const a = i.join(t, "package.json"), o = JSON.parse(s.readFileSync(a, "utf-8"));
|
|
577
487
|
o.devDependencies = {
|
|
578
488
|
...o.devDependencies,
|
|
579
489
|
"semantic-release": "^24.0.0"
|
|
@@ -581,41 +491,41 @@ function O(t) {
|
|
|
581
491
|
...o.scripts,
|
|
582
492
|
test: 'echo "No tests yet"',
|
|
583
493
|
"type-check": "tsc --noEmit"
|
|
584
|
-
}, s.writeFileSync(
|
|
494
|
+
}, s.writeFileSync(a, JSON.stringify(o, null, 2));
|
|
585
495
|
}
|
|
586
496
|
function v(t, e) {
|
|
587
|
-
return new Promise((
|
|
588
|
-
const n =
|
|
497
|
+
return new Promise((a, o) => {
|
|
498
|
+
const n = D(t, [], {
|
|
589
499
|
cwd: e,
|
|
590
500
|
shell: !0,
|
|
591
501
|
stdio: "inherit"
|
|
592
502
|
});
|
|
593
|
-
n.on("close", (
|
|
594
|
-
|
|
503
|
+
n.on("close", (r) => {
|
|
504
|
+
r === 0 ? a() : o(new Error(`Command failed with exit code ${r}`));
|
|
595
505
|
}), n.on("error", o);
|
|
596
506
|
});
|
|
597
507
|
}
|
|
598
|
-
function
|
|
508
|
+
function b(t, e, a) {
|
|
599
509
|
return new Promise((o, n) => {
|
|
600
|
-
const
|
|
510
|
+
const r = D(t, [], {
|
|
601
511
|
cwd: e,
|
|
602
512
|
shell: !0,
|
|
603
513
|
stdio: "inherit",
|
|
604
|
-
env: { ...process.env, ...
|
|
514
|
+
env: { ...process.env, ...a }
|
|
605
515
|
});
|
|
606
|
-
|
|
516
|
+
r.on("close", (c) => {
|
|
607
517
|
c === 0 ? o() : n(new Error(`Command failed with exit code ${c}`));
|
|
608
|
-
}),
|
|
518
|
+
}), r.on("error", n);
|
|
609
519
|
});
|
|
610
520
|
}
|
|
611
|
-
function
|
|
612
|
-
const
|
|
521
|
+
function O(t, e) {
|
|
522
|
+
const a = i.join(t, "src");
|
|
613
523
|
s.writeFileSync(
|
|
614
|
-
|
|
615
|
-
|
|
524
|
+
i.join(a, "app.ts"),
|
|
525
|
+
R(e)
|
|
616
526
|
), s.writeFileSync(
|
|
617
|
-
|
|
618
|
-
|
|
527
|
+
i.join(a, "seed.ts"),
|
|
528
|
+
_(e)
|
|
619
529
|
);
|
|
620
530
|
}
|
|
621
531
|
function k(t) {
|
|
@@ -628,16 +538,16 @@ function C(t) {
|
|
|
628
538
|
` + "─".repeat(50)), console.log("✅ Self-signed certificates generated with openssl"), console.log("⚠️ You may need to trust the certificate in your browser"), console.log("🔐 AuthHero server running at https://localhost:3000"), console.log("📚 API documentation available at https://localhost:3000/docs"), console.log("🌐 Portal available at https://local.authhero.net"), console.log(t ? "🏢 Multi-tenant mode enabled with control_plane tenant" : "🏠 Single-tenant mode with 'main' tenant"), console.log("─".repeat(50) + `
|
|
629
539
|
`);
|
|
630
540
|
}
|
|
631
|
-
|
|
541
|
+
I.version("1.0.0").description("Create a new AuthHero project").argument("[project-name]", "name of the project").option("-t, --template <type>", "template type: local or cloudflare").option("-e, --email <email>", "admin email address").option("-p, --password <password>", "admin password (min 8 characters)").option(
|
|
632
542
|
"--package-manager <pm>",
|
|
633
543
|
"package manager to use: npm, yarn, pnpm, or bun"
|
|
634
544
|
).option("--multi-tenant", "enable multi-tenant mode").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 (t, e) => {
|
|
635
|
-
const
|
|
545
|
+
const a = e.yes === !0;
|
|
636
546
|
console.log(`
|
|
637
547
|
🔐 Welcome to AuthHero!
|
|
638
548
|
`);
|
|
639
549
|
let o = t;
|
|
640
|
-
o || (
|
|
550
|
+
o || (a ? (o = "auth-server", console.log(`Using default project name: ${o}`)) : o = (await d.prompt([
|
|
641
551
|
{
|
|
642
552
|
type: "input",
|
|
643
553
|
name: "projectName",
|
|
@@ -646,10 +556,10 @@ P.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
646
556
|
validate: (p) => p !== "" || "Project name cannot be empty"
|
|
647
557
|
}
|
|
648
558
|
])).projectName);
|
|
649
|
-
const n =
|
|
559
|
+
const n = i.join(process.cwd(), o);
|
|
650
560
|
s.existsSync(n) && (console.error(`❌ Project "${o}" already exists.`), process.exit(1));
|
|
651
|
-
let
|
|
652
|
-
e.template ? (["local", "cloudflare"].includes(e.template) || (console.error(`❌ Invalid template: ${e.template}`), console.error("Valid options: local, cloudflare"), process.exit(1)),
|
|
561
|
+
let r;
|
|
562
|
+
e.template ? (["local", "cloudflare"].includes(e.template) || (console.error(`❌ Invalid template: ${e.template}`), console.error("Valid options: local, cloudflare"), process.exit(1)), r = e.template, console.log(`Using template: ${m[r].name}`)) : r = (await d.prompt([
|
|
653
563
|
{
|
|
654
564
|
type: "list",
|
|
655
565
|
name: "setupType",
|
|
@@ -671,7 +581,7 @@ P.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
671
581
|
}
|
|
672
582
|
])).setupType;
|
|
673
583
|
let c;
|
|
674
|
-
e.multiTenant !== void 0 ? (c = e.multiTenant, console.log(`Multi-tenant mode: ${c ? "enabled" : "disabled"}`)) :
|
|
584
|
+
e.multiTenant !== void 0 ? (c = e.multiTenant, console.log(`Multi-tenant mode: ${c ? "enabled" : "disabled"}`)) : a ? c = !1 : c = (await d.prompt([
|
|
675
585
|
{
|
|
676
586
|
type: "confirm",
|
|
677
587
|
name: "multiTenant",
|
|
@@ -680,45 +590,45 @@ P.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
680
590
|
default: !1
|
|
681
591
|
}
|
|
682
592
|
])).multiTenant;
|
|
683
|
-
const
|
|
593
|
+
const S = m[r];
|
|
684
594
|
s.mkdirSync(n, { recursive: !0 }), s.writeFileSync(
|
|
685
|
-
|
|
686
|
-
JSON.stringify(
|
|
595
|
+
i.join(n, "package.json"),
|
|
596
|
+
JSON.stringify(S.packageJson(o, c), null, 2)
|
|
687
597
|
);
|
|
688
|
-
const
|
|
598
|
+
const N = S.templateDir, A = i.join(
|
|
689
599
|
import.meta.url.replace("file://", "").replace("/create-authhero.js", ""),
|
|
690
|
-
|
|
600
|
+
N
|
|
691
601
|
);
|
|
692
|
-
if (s.existsSync(
|
|
693
|
-
const
|
|
694
|
-
s.existsSync(
|
|
695
|
-
const u =
|
|
602
|
+
if (s.existsSync(A) ? x(A, n) : (console.error(`❌ Template directory not found: ${A}`), process.exit(1)), r === "cloudflare" && O(n, c), r === "cloudflare") {
|
|
603
|
+
const l = i.join(n, "wrangler.toml"), p = i.join(n, "wrangler.local.toml");
|
|
604
|
+
s.existsSync(l) && s.copyFileSync(l, p);
|
|
605
|
+
const u = i.join(n, ".dev.vars.example"), g = i.join(n, ".dev.vars");
|
|
696
606
|
s.existsSync(u) && s.copyFileSync(u, g), console.log(
|
|
697
607
|
"📁 Created wrangler.local.toml and .dev.vars for local development"
|
|
698
608
|
);
|
|
699
609
|
}
|
|
700
610
|
let w = !1;
|
|
701
|
-
if (
|
|
611
|
+
if (r === "cloudflare" && (e.githubCi !== void 0 ? (w = e.githubCi, w && console.log("Including GitHub CI workflows with semantic versioning")) : a || (w = (await d.prompt([
|
|
702
612
|
{
|
|
703
613
|
type: "confirm",
|
|
704
614
|
name: "includeGithubCi",
|
|
705
615
|
message: "Would you like to include GitHub CI with semantic versioning?",
|
|
706
616
|
default: !1
|
|
707
617
|
}
|
|
708
|
-
])).includeGithubCi), w && (
|
|
709
|
-
const
|
|
710
|
-
s.writeFileSync(
|
|
711
|
-
const p =
|
|
712
|
-
s.writeFileSync(
|
|
618
|
+
])).includeGithubCi), w && (M(n), $(n))), r === "local") {
|
|
619
|
+
const l = E(c);
|
|
620
|
+
s.writeFileSync(i.join(n, "src/seed.ts"), l);
|
|
621
|
+
const p = j(c);
|
|
622
|
+
s.writeFileSync(i.join(n, "src/app.ts"), p);
|
|
713
623
|
}
|
|
714
|
-
const
|
|
624
|
+
const P = c ? "multi-tenant" : "single-tenant";
|
|
715
625
|
console.log(
|
|
716
626
|
`
|
|
717
|
-
✅ Project "${o}" has been created with ${
|
|
627
|
+
✅ Project "${o}" has been created with ${S.name} (${P}) setup!
|
|
718
628
|
`
|
|
719
629
|
);
|
|
720
630
|
let f;
|
|
721
|
-
if (e.skipInstall ? f = !1 :
|
|
631
|
+
if (e.skipInstall ? f = !1 : a ? f = !0 : f = (await d.prompt([
|
|
722
632
|
{
|
|
723
633
|
type: "confirm",
|
|
724
634
|
name: "shouldInstall",
|
|
@@ -726,10 +636,10 @@ P.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
726
636
|
default: !0
|
|
727
637
|
}
|
|
728
638
|
])).shouldInstall, f) {
|
|
729
|
-
let
|
|
639
|
+
let l;
|
|
730
640
|
e.packageManager ? (["npm", "yarn", "pnpm", "bun"].includes(e.packageManager) || (console.error(
|
|
731
641
|
`❌ Invalid package manager: ${e.packageManager}`
|
|
732
|
-
), console.error("Valid options: npm, yarn, pnpm, bun"), process.exit(1)),
|
|
642
|
+
), console.error("Valid options: npm, yarn, pnpm, bun"), process.exit(1)), l = e.packageManager) : a ? l = "pnpm" : l = (await d.prompt([
|
|
733
643
|
{
|
|
734
644
|
type: "list",
|
|
735
645
|
name: "packageManager",
|
|
@@ -743,17 +653,17 @@ P.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
743
653
|
default: "pnpm"
|
|
744
654
|
}
|
|
745
655
|
])).packageManager, console.log(`
|
|
746
|
-
📦 Installing dependencies with ${
|
|
656
|
+
📦 Installing dependencies with ${l}...
|
|
747
657
|
`);
|
|
748
658
|
try {
|
|
749
|
-
const p =
|
|
750
|
-
if (await v(p, n),
|
|
659
|
+
const p = l === "pnpm" ? "pnpm install --ignore-workspace" : `${l} install`;
|
|
660
|
+
if (await v(p, n), r === "local" && (console.log(`
|
|
751
661
|
🔧 Building native modules...
|
|
752
662
|
`), await v("npm rebuild better-sqlite3", n)), console.log(`
|
|
753
663
|
✅ Dependencies installed successfully!
|
|
754
|
-
`),
|
|
664
|
+
`), r === "local" || r === "cloudflare") {
|
|
755
665
|
let g;
|
|
756
|
-
if (e.skipMigrate && e.skipSeed ? g = !1 :
|
|
666
|
+
if (e.skipMigrate && e.skipSeed ? g = !1 : a ? g = !e.skipMigrate || !e.skipSeed : g = (await d.prompt([
|
|
757
667
|
{
|
|
758
668
|
type: "confirm",
|
|
759
669
|
name: "shouldSetup",
|
|
@@ -782,17 +692,17 @@ P.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
782
692
|
}
|
|
783
693
|
]), e.skipMigrate || (console.log(`
|
|
784
694
|
🔄 Running migrations...
|
|
785
|
-
`), await v(`${
|
|
695
|
+
`), await v(`${l} run migrate`, n)), e.skipSeed || (console.log(`
|
|
786
696
|
🌱 Seeding database...
|
|
787
|
-
`),
|
|
788
|
-
`${
|
|
697
|
+
`), r === "local" ? await b(
|
|
698
|
+
`${l} run seed`,
|
|
789
699
|
n,
|
|
790
700
|
{
|
|
791
701
|
ADMIN_EMAIL: h.username,
|
|
792
702
|
ADMIN_PASSWORD: h.password
|
|
793
703
|
}
|
|
794
|
-
) : await
|
|
795
|
-
`${
|
|
704
|
+
) : await b(
|
|
705
|
+
`${l} run seed:local`,
|
|
796
706
|
n,
|
|
797
707
|
{
|
|
798
708
|
ADMIN_EMAIL: h.username,
|
|
@@ -802,25 +712,25 @@ P.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
802
712
|
}
|
|
803
713
|
}
|
|
804
714
|
let u;
|
|
805
|
-
e.skipStart ||
|
|
715
|
+
e.skipStart || a ? u = !1 : u = (await d.prompt([
|
|
806
716
|
{
|
|
807
717
|
type: "confirm",
|
|
808
718
|
name: "shouldStart",
|
|
809
719
|
message: "Would you like to start the development server?",
|
|
810
720
|
default: !0
|
|
811
721
|
}
|
|
812
|
-
])).shouldStart, u && (
|
|
813
|
-
`), await v(`${
|
|
722
|
+
])).shouldStart, u && (r === "cloudflare" ? k(c) : C(c), console.log(`🚀 Starting development server...
|
|
723
|
+
`), await v(`${l} run dev`, n)), a && !u && (console.log(`
|
|
814
724
|
✅ Setup complete!`), console.log(`
|
|
815
|
-
To start the development server:`), console.log(` cd ${o}`), console.log(" npm run dev"),
|
|
725
|
+
To start the development server:`), console.log(` cd ${o}`), console.log(" npm run dev"), r === "cloudflare" ? k(c) : C(c));
|
|
816
726
|
} catch (p) {
|
|
817
727
|
console.error(`
|
|
818
728
|
❌ An error occurred:`, p), process.exit(1);
|
|
819
729
|
}
|
|
820
730
|
}
|
|
821
|
-
f || (console.log("Next steps:"), console.log(` cd ${o}`),
|
|
731
|
+
f || (console.log("Next steps:"), console.log(` cd ${o}`), r === "local" ? (console.log(" npm install"), console.log(" npm run migrate"), console.log(
|
|
822
732
|
" ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=yourpassword npm run seed"
|
|
823
|
-
), console.log(" npm run dev")) :
|
|
733
|
+
), console.log(" npm run dev")) : r === "cloudflare" && (console.log(" npm install"), console.log(
|
|
824
734
|
" npm run migrate # or npm run db:migrate:remote for production"
|
|
825
735
|
), console.log(
|
|
826
736
|
" ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=yourpassword npm run seed"
|
|
@@ -829,4 +739,4 @@ Server will be available at: https://localhost:3000`), console.log("Portal avail
|
|
|
829
739
|
For more information, visit: https://authhero.net/docs
|
|
830
740
|
`));
|
|
831
741
|
});
|
|
832
|
-
|
|
742
|
+
I.parse(process.argv);
|