wexts 3.0.2 → 4.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/README.md +49 -346
- package/bin/wexts.cjs +2 -0
- package/dist/chunk-2KAQYLVN.js +0 -0
- package/dist/chunk-2KAQYLVN.js.map +1 -1
- package/dist/{chunk-O42L6HOX.js → chunk-2LJVUMXW.js} +79 -93
- package/dist/chunk-2LJVUMXW.js.map +1 -0
- package/dist/chunk-342VRT25.mjs +504 -0
- package/dist/chunk-342VRT25.mjs.map +1 -0
- package/dist/chunk-7HNQWJWV.js +504 -0
- package/dist/chunk-7HNQWJWV.js.map +1 -0
- package/dist/chunk-7QKLIVRF.js +94 -0
- package/dist/chunk-7QKLIVRF.js.map +1 -0
- package/dist/chunk-7SSCNCTW.mjs +137 -0
- package/dist/chunk-7SSCNCTW.mjs.map +1 -0
- package/dist/chunk-7TLSPR65.mjs +95 -0
- package/dist/chunk-7TLSPR65.mjs.map +1 -0
- package/dist/{chunk-FCEZDH42.mjs → chunk-7WULUGLH.mjs} +5 -3
- package/dist/chunk-7WULUGLH.mjs.map +1 -0
- package/dist/chunk-AVMQJWYD.js +95 -0
- package/dist/chunk-AVMQJWYD.js.map +1 -0
- package/dist/{chunk-WF65EDRZ.js → chunk-BG56B4DE.js} +20 -2
- package/dist/chunk-BG56B4DE.js.map +1 -0
- package/dist/chunk-CLM5PNSG.mjs +496 -0
- package/dist/chunk-CLM5PNSG.mjs.map +1 -0
- package/dist/chunk-DNLGCKTT.js +31 -0
- package/dist/chunk-DNLGCKTT.js.map +1 -0
- package/dist/{chunk-VNNVLQLJ.mjs → chunk-JHOVXH3X.mjs} +2 -2
- package/dist/chunk-JHOVXH3X.mjs.map +1 -0
- package/dist/chunk-MXINIFPC.js +105 -0
- package/dist/chunk-MXINIFPC.js.map +1 -0
- package/dist/chunk-O4II6N34.js +137 -0
- package/dist/chunk-O4II6N34.js.map +1 -0
- package/dist/chunk-SE32ZPOZ.js +496 -0
- package/dist/chunk-SE32ZPOZ.js.map +1 -0
- package/dist/{chunk-STTOPUZ2.mjs → chunk-UAL54DVV.mjs} +21 -3
- package/dist/chunk-UAL54DVV.mjs.map +1 -0
- package/dist/{chunk-3OM7CHCA.js → chunk-WCKSKU3C.js} +1 -1
- package/dist/chunk-WCKSKU3C.js.map +1 -0
- package/dist/chunk-WU6FW77M.mjs +105 -0
- package/dist/chunk-WU6FW77M.mjs.map +1 -0
- package/dist/chunk-XE4OXN2W.js +0 -0
- package/dist/chunk-XE4OXN2W.js.map +1 -1
- package/dist/chunk-YBM3IJEA.mjs +94 -0
- package/dist/chunk-YBM3IJEA.mjs.map +1 -0
- package/dist/{chunk-KXYLEUSW.mjs → chunk-YN6WIWNQ.mjs} +69 -83
- package/dist/chunk-YN6WIWNQ.mjs.map +1 -0
- package/dist/chunk-YSLEF5C5.mjs +0 -0
- package/dist/chunk-YSLEF5C5.mjs.map +0 -0
- package/dist/chunk-ZX7QIN24.mjs +31 -0
- package/dist/chunk-ZX7QIN24.mjs.map +1 -0
- package/dist/cli/index.d.mts +22 -0
- package/dist/cli/index.d.ts +22 -0
- package/dist/cli/index.js +676 -292
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +678 -293
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/index.d.mts +10 -1
- package/dist/client/index.d.ts +10 -1
- package/dist/client/index.js +5 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +7 -4
- package/dist/client/index.mjs.map +0 -0
- package/dist/codegen/index.d.mts +2 -1
- package/dist/codegen/index.d.ts +2 -1
- package/dist/codegen/index.js +6 -3
- package/dist/codegen/index.js.map +1 -1
- package/dist/codegen/index.mjs +8 -5
- package/dist/codegen/index.mjs.map +0 -0
- package/dist/decorators-BT1FFqN0.d.mts +29 -0
- package/dist/decorators-DvS58PqC.d.ts +29 -0
- package/dist/dev-server/index.d.mts +1 -1
- package/dist/dev-server/index.d.ts +1 -1
- package/dist/dev-server/index.js +3 -3
- package/dist/dev-server/index.js.map +1 -1
- package/dist/dev-server/index.mjs +3 -3
- package/dist/dev-server/index.mjs.map +0 -0
- package/dist/{index-SjUaHgFr.d.ts → index-7QeQEf37.d.ts} +27 -10
- package/dist/{index-tFGPFVfQ.d.mts → index-7RvU-jGE.d.mts} +0 -1
- package/dist/{index-tFGPFVfQ.d.ts → index-7RvU-jGE.d.ts} +0 -1
- package/dist/{index-SjUaHgFr.d.mts → index-8nzxy0NN.d.mts} +27 -10
- package/dist/index-Co5ZsLqq.d.ts +58 -0
- package/dist/index-D94W1__r.d.mts +58 -0
- package/dist/index-DQmyVp6F.d.mts +27 -0
- package/dist/index-KL_1BrQb.d.ts +27 -0
- package/dist/index.d.mts +54 -7
- package/dist/index.d.ts +54 -7
- package/dist/index.js +70 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -21
- package/dist/index.mjs.map +1 -1
- package/dist/nest/index.d.mts +3 -1
- package/dist/nest/index.d.ts +3 -1
- package/dist/nest/index.js +20 -2
- package/dist/nest/index.js.map +1 -1
- package/dist/nest/index.mjs +21 -3
- package/dist/nest/index.mjs.map +0 -0
- package/dist/next/index.d.mts +7 -2
- package/dist/next/index.d.ts +7 -2
- package/dist/next/index.js +135 -5
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +133 -4
- package/dist/next/index.mjs.map +1 -1
- package/dist/rpc/index.d.mts +2 -0
- package/dist/rpc/index.d.ts +2 -0
- package/dist/rpc/index.js +23 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/rpc/index.mjs +23 -0
- package/dist/{chunk-7NSRDJ5C.mjs.map → rpc/index.mjs.map} +0 -0
- package/dist/runtime/index.d.mts +55 -0
- package/dist/runtime/index.d.ts +55 -0
- package/dist/runtime/index.js +221 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/index.mjs +221 -0
- package/dist/runtime/index.mjs.map +1 -0
- package/dist/types/index.d.mts +0 -0
- package/dist/types/index.d.ts +0 -0
- package/dist/types/index.js +0 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/index.mjs.map +0 -0
- package/dist/types-7d_fC-C3.d.mts +32 -0
- package/dist/types-7d_fC-C3.d.ts +32 -0
- package/dist/vercel-builder/index.d.mts +58 -0
- package/dist/vercel-builder/index.d.ts +58 -0
- package/dist/vercel-builder/index.js +330 -0
- package/dist/vercel-builder/index.js.map +1 -0
- package/dist/vercel-builder/index.mjs +330 -0
- package/dist/vercel-builder/index.mjs.map +1 -0
- package/package.json +37 -16
- package/templates/.dockerignore +43 -43
- package/templates/.env.example +0 -0
- package/templates/Dockerfile +60 -60
- package/templates/Procfile +1 -1
- package/templates/README.md +67 -58
- package/templates/api-sdk.ts +115 -115
- package/templates/docker-compose.yml +34 -34
- package/templates/nestjs-api/.env.example +0 -0
- package/templates/nestjs-api/README.md +87 -79
- package/templates/nestjs-api/nest-cli.json +6 -6
- package/templates/nestjs-api/package.json +40 -40
- package/templates/nestjs-api/prisma/dev.db +0 -0
- package/templates/nestjs-api/prisma/migrations/20251123205437_init/migration.sql +0 -0
- package/templates/nestjs-api/prisma/migrations/migration_lock.toml +0 -0
- package/templates/nestjs-api/prisma/schema.prisma +29 -29
- package/templates/nestjs-api/src/app.module.ts +17 -17
- package/templates/nestjs-api/src/auth/auth.controller.ts +27 -27
- package/templates/nestjs-api/src/auth/auth.module.ts +37 -29
- package/templates/nestjs-api/src/auth/auth.service.ts +86 -86
- package/templates/nestjs-api/src/auth/dto/auth.dto.ts +22 -22
- package/templates/nestjs-api/src/auth/guards/jwt-auth.guard.ts +5 -5
- package/templates/nestjs-api/src/auth/strategies/jwt.strategy.ts +27 -19
- package/templates/nestjs-api/src/main.ts +32 -32
- package/templates/nestjs-api/src/prisma/prisma.module.ts +9 -9
- package/templates/nestjs-api/src/prisma/prisma.service.ts +14 -14
- package/templates/nestjs-api/src/todos/dto/todo.dto.ts +24 -24
- package/templates/nestjs-api/src/todos/todos.controller.ts +39 -39
- package/templates/nestjs-api/src/todos/todos.module.ts +11 -11
- package/templates/nestjs-api/src/todos/todos.service.ts +53 -53
- package/templates/nestjs-api/src/users/users.controller.ts +14 -14
- package/templates/nestjs-api/src/users/users.module.ts +12 -12
- package/templates/nestjs-api/src/users/users.service.ts +19 -19
- package/templates/nestjs-api/tsconfig.json +39 -39
- package/templates/nextjs-web/README.md +76 -68
- package/templates/nextjs-web/app/actions/auth.ts +108 -108
- package/templates/nextjs-web/app/dashboard/error.tsx +39 -39
- package/templates/nextjs-web/app/dashboard/loading.tsx +14 -14
- package/templates/nextjs-web/app/dashboard/page.tsx +5 -5
- package/templates/nextjs-web/app/globals.css +93 -93
- package/templates/nextjs-web/app/layout.tsx +29 -29
- package/templates/nextjs-web/app/login/page.tsx +5 -5
- package/templates/nextjs-web/app/page.tsx +28 -28
- package/templates/nextjs-web/app/register/page.tsx +5 -5
- package/templates/nextjs-web/components/ui/button.tsx +56 -56
- package/templates/nextjs-web/components/ui/card.tsx +79 -79
- package/templates/nextjs-web/components/ui/input.tsx +25 -25
- package/templates/nextjs-web/components/ui/label.tsx +24 -24
- package/templates/nextjs-web/features/auth/LoginForm.tsx +140 -140
- package/templates/nextjs-web/features/auth/RegisterForm.tsx +159 -159
- package/templates/nextjs-web/features/auth/api.ts +35 -35
- package/templates/nextjs-web/features/auth/index.ts +3 -3
- package/templates/nextjs-web/features/dashboard/DashboardView.tsx +204 -204
- package/templates/nextjs-web/features/dashboard/api.ts +9 -9
- package/templates/nextjs-web/features/dashboard/components.tsx +74 -74
- package/templates/nextjs-web/features/dashboard/index.ts +3 -3
- package/templates/nextjs-web/hooks/index.ts +4 -4
- package/templates/nextjs-web/lib/api-client.ts +89 -89
- package/templates/nextjs-web/lib/api.ts +115 -115
- package/templates/nextjs-web/lib/axios-global-config.ts +17 -17
- package/templates/nextjs-web/lib/utils.ts +6 -6
- package/templates/nextjs-web/lib/wexts-client.ts +4 -4
- package/templates/nextjs-web/next-env.d.ts +6 -6
- package/templates/nextjs-web/next.config.ts +20 -20
- package/templates/nextjs-web/package.json +37 -37
- package/templates/nextjs-web/postcss.config.js +6 -6
- package/templates/nextjs-web/tailwind.config.ts +69 -69
- package/templates/nextjs-web/tsconfig.json +1 -1
- package/templates/nixpacks.toml +11 -11
- package/templates/root-package.json +31 -31
- package/templates/server.ts +66 -66
- package/templates/tsconfig.json +30 -30
- package/dist/chunk-2MCBBWEA.js +0 -1
- package/dist/chunk-2MCBBWEA.js.map +0 -1
- package/dist/chunk-3OM7CHCA.js.map +0 -1
- package/dist/chunk-63MTCWU2.mjs +0 -361
- package/dist/chunk-63MTCWU2.mjs.map +0 -1
- package/dist/chunk-667BQCEM.js +0 -375
- package/dist/chunk-667BQCEM.js.map +0 -1
- package/dist/chunk-67IJ6H4J.mjs +0 -44
- package/dist/chunk-67IJ6H4J.mjs.map +0 -1
- package/dist/chunk-6SVQEGEX.mjs +0 -44
- package/dist/chunk-6SVQEGEX.mjs.map +0 -1
- package/dist/chunk-7NSRDJ5C.mjs +0 -1
- package/dist/chunk-ASDXAK6G.js +0 -44
- package/dist/chunk-ASDXAK6G.js.map +0 -1
- package/dist/chunk-CKZ4VSCB.mjs +0 -18
- package/dist/chunk-CKZ4VSCB.mjs.map +0 -1
- package/dist/chunk-DW6GOKMF.js +0 -57
- package/dist/chunk-DW6GOKMF.js.map +0 -1
- package/dist/chunk-EFZPSZWO.mjs +0 -1
- package/dist/chunk-EFZPSZWO.mjs.map +0 -1
- package/dist/chunk-FCEZDH42.mjs.map +0 -1
- package/dist/chunk-FYGXL4V7.js +0 -361
- package/dist/chunk-FYGXL4V7.js.map +0 -1
- package/dist/chunk-GKVPGKAH.js +0 -66
- package/dist/chunk-GKVPGKAH.js.map +0 -1
- package/dist/chunk-GWP6PNSP.js +0 -225
- package/dist/chunk-GWP6PNSP.js.map +0 -1
- package/dist/chunk-HQKTXE7E.mjs +0 -225
- package/dist/chunk-HQKTXE7E.mjs.map +0 -1
- package/dist/chunk-HSFLZUJN.mjs +0 -57
- package/dist/chunk-HSFLZUJN.mjs.map +0 -1
- package/dist/chunk-HU63F22V.js +0 -361
- package/dist/chunk-HU63F22V.js.map +0 -1
- package/dist/chunk-J5LGTIGS.mjs +0 -10
- package/dist/chunk-J5LGTIGS.mjs.map +0 -1
- package/dist/chunk-JMBD6DOP.js +0 -225
- package/dist/chunk-JMBD6DOP.js.map +0 -1
- package/dist/chunk-K7EIJSYQ.js +0 -1
- package/dist/chunk-K7EIJSYQ.js.map +0 -1
- package/dist/chunk-KXYLEUSW.mjs.map +0 -1
- package/dist/chunk-MTHKZO55.js +0 -44
- package/dist/chunk-MTHKZO55.js.map +0 -1
- package/dist/chunk-NNQFLD7O.mjs +0 -361
- package/dist/chunk-NNQFLD7O.mjs.map +0 -1
- package/dist/chunk-NU2UB242.js +0 -82
- package/dist/chunk-NU2UB242.js.map +0 -1
- package/dist/chunk-NULGSZFE.mjs +0 -57
- package/dist/chunk-NULGSZFE.mjs.map +0 -1
- package/dist/chunk-O42L6HOX.js.map +0 -1
- package/dist/chunk-ONXNE2A6.mjs +0 -375
- package/dist/chunk-ONXNE2A6.mjs.map +0 -1
- package/dist/chunk-OTBYRUBE.mjs +0 -225
- package/dist/chunk-OTBYRUBE.mjs.map +0 -1
- package/dist/chunk-OTSAVKLY.mjs +0 -66
- package/dist/chunk-OTSAVKLY.mjs.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-QP2TMRLG.js +0 -57
- package/dist/chunk-QP2TMRLG.js.map +0 -1
- package/dist/chunk-RS23R3ZQ.mjs +0 -82
- package/dist/chunk-RS23R3ZQ.mjs.map +0 -1
- package/dist/chunk-STTOPUZ2.mjs.map +0 -1
- package/dist/chunk-VMT3LALB.mjs +0 -51
- package/dist/chunk-VMT3LALB.mjs.map +0 -1
- package/dist/chunk-VNNVLQLJ.mjs.map +0 -1
- package/dist/chunk-W3YRVEFQ.js +0 -66
- package/dist/chunk-W3YRVEFQ.js.map +0 -1
- package/dist/chunk-WF65EDRZ.js.map +0 -1
- package/dist/chunk-WMHVXEYQ.mjs +0 -66
- package/dist/chunk-WMHVXEYQ.mjs.map +0 -1
- package/dist/chunk-XVKTIYHY.js +0 -51
- package/dist/chunk-XVKTIYHY.js.map +0 -1
- package/dist/codegen-MRZDLCYI.js +0 -13
- package/dist/codegen-MRZDLCYI.js.map +0 -1
- package/dist/codegen-UI5HTMXE.mjs +0 -13
- package/dist/codegen-UI5HTMXE.mjs.map +0 -1
- package/dist/dev-server-JKRVBWPY.mjs +0 -13
- package/dist/dev-server-JKRVBWPY.mjs.map +0 -1
- package/dist/dev-server-TLL7UQMR.js +0 -13
- package/dist/dev-server-TLL7UQMR.js.map +0 -1
- package/dist/index-BsNaOUtH.d.mts +0 -44
- package/dist/index-BsNaOUtH.d.ts +0 -44
- package/dist/index-CrbXnXsO.d.ts +0 -62
- package/dist/index-kEbGExWM.d.mts +0 -62
- package/templates/nestjs-api/.env +0 -4
- package/templates/nestjs-api/package-lock.json +0 -5623
- package/templates/nextjs-web/.env +0 -1
- package/templates/nextjs-web/package-lock.json +0 -3254
package/dist/cli/index.mjs
CHANGED
|
@@ -1,333 +1,718 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
logger
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-JHOVXH3X.mjs";
|
|
5
|
+
import {
|
|
6
|
+
WextsError,
|
|
7
|
+
formatWextsError
|
|
8
|
+
} from "../chunk-7TLSPR65.mjs";
|
|
5
9
|
import {
|
|
6
10
|
__dirname,
|
|
11
|
+
__filename,
|
|
7
12
|
__name
|
|
8
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-7WULUGLH.mjs";
|
|
9
14
|
|
|
10
15
|
// src/cli/index.ts
|
|
11
16
|
import { Command } from "commander";
|
|
12
|
-
import * as pc from "picocolors";
|
|
13
|
-
import inquirer from "inquirer";
|
|
14
17
|
import * as fs from "fs";
|
|
15
18
|
import * as path from "path";
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
program
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const { action } = await inquirer.prompt([
|
|
30
|
-
{
|
|
31
|
-
type: "list",
|
|
32
|
-
name: "action",
|
|
33
|
-
message: "What would you like to do?",
|
|
34
|
-
choices: [
|
|
35
|
-
{
|
|
36
|
-
name: "\u{1F4E6} Create a new project",
|
|
37
|
-
value: "create"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: "\u{1F680} Start development server",
|
|
41
|
-
value: "dev"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: "\u{1F528} Build for production",
|
|
45
|
-
value: "build"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: "\u26A1 Generate code",
|
|
49
|
-
value: "generate"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: "\u{1F916} Generate API client",
|
|
53
|
-
value: "codegen"
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: "\u274C Exit",
|
|
57
|
-
value: "exit"
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
]);
|
|
62
|
-
if (action === "exit") {
|
|
63
|
-
logger.info("Goodbye! \u{1F44B}");
|
|
64
|
-
process.exit(0);
|
|
65
|
-
}
|
|
66
|
-
if (action === "create") {
|
|
67
|
-
const { projectName, template } = await inquirer.prompt([
|
|
68
|
-
{
|
|
69
|
-
type: "input",
|
|
70
|
-
name: "projectName",
|
|
71
|
-
message: "Project name:",
|
|
72
|
-
default: "my-wexts-app"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
type: "list",
|
|
76
|
-
name: "template",
|
|
77
|
-
message: "Select template:",
|
|
78
|
-
choices: [
|
|
79
|
-
{
|
|
80
|
-
name: "\u{1F4E6} Monorepo (Next.js + NestJS)",
|
|
81
|
-
value: "monorepo"
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
name: "\u{1F3AF} API only (NestJS)",
|
|
85
|
-
value: "api"
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
name: "\u{1F310} Web only (Next.js)",
|
|
89
|
-
value: "web"
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
]);
|
|
94
|
-
await createProject(projectName, template);
|
|
95
|
-
} else if (action === "dev") {
|
|
96
|
-
logger.info(pc.green("\u{1F680} Starting development servers...\n"));
|
|
97
|
-
logger.warn("Dev server not yet implemented");
|
|
98
|
-
} else if (action === "build") {
|
|
99
|
-
logger.info(pc.blue("\u{1F528} Building project...\n"));
|
|
100
|
-
logger.warn("Build not yet implemented");
|
|
101
|
-
} else if (action === "generate") {
|
|
102
|
-
const { type, name } = await inquirer.prompt([
|
|
103
|
-
{
|
|
104
|
-
type: "list",
|
|
105
|
-
name: "type",
|
|
106
|
-
message: "What to generate?",
|
|
107
|
-
choices: [
|
|
108
|
-
"controller",
|
|
109
|
-
"module",
|
|
110
|
-
"service",
|
|
111
|
-
"page"
|
|
112
|
-
]
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
type: "input",
|
|
116
|
-
name: "name",
|
|
117
|
-
message: "Name:"
|
|
118
|
-
}
|
|
119
|
-
]);
|
|
120
|
-
logger.info(pc.magenta(`
|
|
121
|
-
\u26A1 Generating ${type}: ${name}
|
|
122
|
-
`));
|
|
123
|
-
logger.warn("Code generation not yet implemented");
|
|
124
|
-
} else if (action === "codegen") {
|
|
125
|
-
logger.info(pc.cyan("\n\u{1F916} Generating API client...\n"));
|
|
126
|
-
logger.warn("Codegen not yet implemented");
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
program.command("create <project-name>").description("Create a new wexts project").option("-t, --template <template>", "Template to use (monorepo|api|web)", "monorepo").action(async (projectName, options) => {
|
|
130
|
-
await createProject(projectName, options.template);
|
|
131
|
-
});
|
|
132
|
-
program.command("dev").description("Start development servers").option("-a, --api <path>", "Path to API project", "./apps/api").option("-w, --web <path>", "Path to Web project", "./apps/web").option("-p, --port <port>", "Port for web server", "3000").option("--api-port <port>", "Port for API server", "5050").option("--no-proxy", "Disable proxy server").action(async (options) => {
|
|
133
|
-
logger.info(pc.green("\u{1F680} Starting Wexts development servers...\n"));
|
|
134
|
-
const { FusionDevServer } = await import("../dev-server/index.mjs");
|
|
135
|
-
const server = new FusionDevServer();
|
|
136
|
-
try {
|
|
19
|
+
import { spawnSync } from "child_process";
|
|
20
|
+
import { createRequire } from "module";
|
|
21
|
+
function createCliProgram() {
|
|
22
|
+
const program = new Command();
|
|
23
|
+
program.name("wexts").description("Wexts - production-focused single-runtime Next.js + NestJS toolkit").version(readPackageVersion());
|
|
24
|
+
program.command("create <project-name>").description("Create a verified Wexts starter").option("-t, --template <template>", "Template to use (starter|legacy)", "starter").option("--skip-install", "Skip dependency installation", false).action(async (projectName, options) => {
|
|
25
|
+
await createProject(projectName, options.template, {
|
|
26
|
+
skipInstall: options.skipInstall
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
program.command("dev").description("Start local development processes").option("-a, --api <path>", "Path to API project", "./apps/api").option("-w, --web <path>", "Path to Web project", "./apps/web").option("-p, --port <port>", "Port for web server", "3000").option("--api-port <port>", "Port for API server", "5050").option("--proxy", "Enable development proxy on a separate proxy port", false).action(async (options) => {
|
|
30
|
+
const { FusionDevServer } = await import("../dev-server/index.mjs");
|
|
31
|
+
const server = new FusionDevServer();
|
|
137
32
|
await server.start({
|
|
138
33
|
apiPath: options.api,
|
|
139
34
|
webPath: options.web,
|
|
140
|
-
webPort:
|
|
141
|
-
apiPort:
|
|
35
|
+
webPort: Number(options.port),
|
|
36
|
+
apiPort: Number(options.apiPort),
|
|
142
37
|
useProxy: options.proxy
|
|
143
38
|
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
39
|
+
});
|
|
40
|
+
program.command("generate [type] [name]").alias("g").description("Generate RPC manifest/client, or scaffold a minimal RPC service").option("-p, --project <path>", "Path to NestJS project", "./apps/api").option("-o, --output <path>", "Output directory for generated RPC client", "./apps/web/lib/wexts").option("--force", "Overwrite generated files if they already exist", false).action(async (type, name, options) => {
|
|
41
|
+
if (!type || type === "rpc" && !name) {
|
|
42
|
+
const { generateRpcClient } = await import("../codegen/index.mjs");
|
|
43
|
+
const manifest = await generateRpcClient({
|
|
44
|
+
projectPath: path.resolve(options.project),
|
|
45
|
+
outputPath: path.resolve(options.output)
|
|
46
|
+
});
|
|
47
|
+
logger.success(`Generated Wexts RPC client for ${manifest.services.length} service(s).`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (isScaffoldGenerator(type)) {
|
|
51
|
+
const targetRoot = type === "config" ? process.cwd() : path.resolve(options.project);
|
|
52
|
+
const changedFiles = await scaffoldGenerator({
|
|
53
|
+
type,
|
|
54
|
+
name,
|
|
55
|
+
targetRoot,
|
|
56
|
+
force: options.force
|
|
57
|
+
});
|
|
58
|
+
for (const file of changedFiles) logger.info(`created ${path.relative(process.cwd(), file)}`);
|
|
59
|
+
logger.success(`Generated ${type}${name ? ` ${name}` : ""}.`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
throw new Error(`Unknown generator "${type}". Supported generators: rpc, service, module, entity, guard, config.`);
|
|
63
|
+
});
|
|
64
|
+
program.command("codegen").description("Alias for wexts generate rpc").option("-p, --project <path>", "Path to NestJS project", "./apps/api").option("-o, --output <path>", "Output directory for generated RPC client", "./apps/web/lib/wexts").action(async (options) => {
|
|
65
|
+
const { generateRpcClient } = await import("../codegen/index.mjs");
|
|
66
|
+
const manifest = await generateRpcClient({
|
|
67
|
+
projectPath: path.resolve(options.project),
|
|
68
|
+
outputPath: path.resolve(options.output)
|
|
165
69
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
70
|
+
logger.success(`Generated Wexts RPC client for ${manifest.services.length} service(s).`);
|
|
71
|
+
});
|
|
72
|
+
program.command("build").description("Build a Wexts project for production").option("--skip-generate", "Skip RPC generation before build", false).option("-p, --project <path>", "Path to NestJS project", "./apps/api").option("-o, --output <path>", "Output directory for generated RPC client", "./apps/web/lib/wexts").action(async (options) => {
|
|
73
|
+
if (!options.skipGenerate && fs.existsSync(options.project)) {
|
|
74
|
+
const { generateRpcClient } = await import("../codegen/index.mjs");
|
|
75
|
+
await generateRpcClient({
|
|
76
|
+
projectPath: path.resolve(options.project),
|
|
77
|
+
outputPath: path.resolve(options.output)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
runScript("build", {
|
|
81
|
+
cwd: process.cwd()
|
|
174
82
|
});
|
|
83
|
+
});
|
|
84
|
+
program.command("start").description("Start the production Wexts runtime").option("-c, --config <path>", "Runtime config module path", "./wexts.runtime.js").option("-p, --port <port>", "Port to listen on", process.env.PORT ?? "3000").action(async (options) => {
|
|
85
|
+
const { startWextsRuntime } = await import("../runtime/index.mjs");
|
|
86
|
+
const configPath = path.resolve(options.config);
|
|
87
|
+
const runtimeConfig = fs.existsSync(configPath) ? await loadRuntimeConfig(configPath) : {};
|
|
88
|
+
await startWextsRuntime({
|
|
89
|
+
...runtimeConfig,
|
|
90
|
+
port: Number(options.port),
|
|
91
|
+
dev: false
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
program.command("vercel-build").description("Build for Vercel using Build Output API v3").option("-p, --project <path>", "Path to NestJS project", "./apps/api").option("-o, --output <path>", "Output dir for RPC client", "./apps/web/lib/wexts").option("-c, --config <path>", "Runtime config module path", "./wexts.runtime.js").option("--skip-codegen", "Skip RPC generation", false).option("--skip-build", "Skip project build step", false).option("--node-version <version>", "Node.js version for Vercel function", "20").option("--max-duration <seconds>", "Max duration for serverless function", "30").action(async (options) => {
|
|
95
|
+
const { buildVercelOutput } = await import("../vercel-builder/index.mjs");
|
|
96
|
+
const result = await buildVercelOutput({
|
|
97
|
+
rootDir: process.cwd(),
|
|
98
|
+
apiProjectPath: options.project,
|
|
99
|
+
rpcOutputPath: options.output,
|
|
100
|
+
runtimeConfigPath: options.config,
|
|
101
|
+
skipCodegen: options.skipCodegen,
|
|
102
|
+
skipBuild: options.skipBuild,
|
|
103
|
+
nodeVersion: options.nodeVersion,
|
|
104
|
+
maxDuration: Number(options.maxDuration)
|
|
105
|
+
});
|
|
106
|
+
if (result.warnings.length > 0) {
|
|
107
|
+
for (const warning of result.warnings) logger.warn(warning);
|
|
108
|
+
}
|
|
109
|
+
if (result.errors.length > 0) {
|
|
110
|
+
for (const error of result.errors) logger.error(error);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
logger.success("Vercel build output ready at .vercel/output");
|
|
114
|
+
});
|
|
115
|
+
program.command("doctor").description("Validate Wexts project configuration").option("--security", "Run security-specific checks", false).action(async (options) => {
|
|
116
|
+
const result = runDoctor(process.cwd(), options.security);
|
|
117
|
+
for (const warning of result.warnings) logger.warn(warning);
|
|
118
|
+
for (const error of result.errors) logger.error(error);
|
|
119
|
+
if (result.errors.length > 0) process.exit(1);
|
|
120
|
+
logger.success(options.security ? "Security doctor passed." : "Doctor passed.");
|
|
121
|
+
});
|
|
122
|
+
return program;
|
|
123
|
+
}
|
|
124
|
+
__name(createCliProgram, "createCliProgram");
|
|
125
|
+
function runDoctor(cwd, security = false) {
|
|
126
|
+
const result = {
|
|
127
|
+
errors: [],
|
|
128
|
+
warnings: []
|
|
129
|
+
};
|
|
130
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
131
|
+
if (!fs.existsSync(pkgPath)) {
|
|
132
|
+
result.errors.push("package.json not found.");
|
|
133
|
+
return result;
|
|
175
134
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
135
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
136
|
+
if (!pkg.packageManager?.startsWith("pnpm@")) {
|
|
137
|
+
result.warnings.push("packageManager should pin pnpm.");
|
|
138
|
+
}
|
|
139
|
+
for (const dir of [
|
|
140
|
+
"apps/api",
|
|
141
|
+
"apps/web"
|
|
142
|
+
]) {
|
|
143
|
+
if (!fs.existsSync(path.join(cwd, dir))) {
|
|
144
|
+
result.warnings.push(`${dir} not found; some Wexts commands may need explicit paths.`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (fs.existsSync(path.join(cwd, "apps/api")) && fs.existsSync(path.join(cwd, "apps/web"))) {
|
|
148
|
+
result.warnings.push("Development mode starts separate web/API processes. Single-port serving is the production `wexts start` runtime path.");
|
|
149
|
+
}
|
|
150
|
+
if (security) {
|
|
151
|
+
const source = readAllText(cwd, [
|
|
152
|
+
"apps/api/src",
|
|
153
|
+
"packages/templates/nestjs-api/src"
|
|
154
|
+
]);
|
|
155
|
+
if (source.includes("default-secret")) {
|
|
156
|
+
result.errors.push('JWT fallback "default-secret" found. Production apps must fail without a strong JWT_SECRET.');
|
|
157
|
+
}
|
|
158
|
+
if (/origin:\s*['"]\*['"]/.test(source)) {
|
|
159
|
+
result.errors.push("Wildcard CORS origin found. Use an explicit origin allowlist.");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
__name(runDoctor, "runDoctor");
|
|
165
|
+
async function createProject(projectName, template, options) {
|
|
180
166
|
const projectPath = path.join(process.cwd(), projectName);
|
|
181
167
|
if (fs.existsSync(projectPath)) {
|
|
182
|
-
|
|
183
|
-
process.exit(1);
|
|
168
|
+
throw new Error(`Directory already exists: ${projectName}`);
|
|
184
169
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
170
|
+
fs.mkdirSync(projectPath, {
|
|
171
|
+
recursive: true
|
|
172
|
+
});
|
|
173
|
+
if (template === "starter") {
|
|
174
|
+
await createVerifiedStarter(projectPath, projectName, options.wextsDependency ?? resolveCreateWextsDependency(projectPath));
|
|
175
|
+
} else if (template === "legacy") {
|
|
176
|
+
createLegacyProject(projectPath, projectName);
|
|
177
|
+
} else {
|
|
178
|
+
throw new Error(`Unknown template "${template}". Supported templates: starter, legacy.`);
|
|
179
|
+
}
|
|
180
|
+
if (!options.skipInstall) {
|
|
181
|
+
runCommand(detectPackageManager(projectPath), [
|
|
182
|
+
"install"
|
|
183
|
+
], projectPath);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
__name(createProject, "createProject");
|
|
187
|
+
async function createVerifiedStarter(projectPath, projectName, wextsDependency) {
|
|
188
|
+
const files = {
|
|
189
|
+
"pnpm-workspace.yaml": "packages:\n - 'apps/*'\n",
|
|
190
|
+
"package.json": JSON.stringify({
|
|
191
|
+
name: projectName,
|
|
192
|
+
version: "0.1.0",
|
|
193
|
+
private: true,
|
|
194
|
+
packageManager: "pnpm@10.22.0",
|
|
195
|
+
scripts: {
|
|
196
|
+
dev: "wexts dev",
|
|
197
|
+
generate: "wexts generate -p apps/api -o apps/web/lib/wexts",
|
|
198
|
+
build: "pnpm run generate && tsc -p apps/api/tsconfig.json && next build apps/web",
|
|
199
|
+
start: "wexts start -c ./wexts.runtime.js",
|
|
200
|
+
"vercel-build": "wexts vercel-build -p apps/api -o apps/web/lib/wexts -c ./wexts.runtime.js",
|
|
201
|
+
doctor: "wexts doctor",
|
|
202
|
+
"doctor:security": "wexts doctor --security"
|
|
203
|
+
},
|
|
204
|
+
dependencies: {
|
|
205
|
+
"@nestjs/common": "^11.1.19",
|
|
206
|
+
"@nestjs/core": "^11.1.19",
|
|
207
|
+
"@nestjs/platform-fastify": "^11.1.19",
|
|
208
|
+
next: "16.2.4",
|
|
209
|
+
react: "^19.2.5",
|
|
210
|
+
"react-dom": "^19.2.5",
|
|
211
|
+
"reflect-metadata": "^0.2.2",
|
|
212
|
+
rxjs: "^7.8.1",
|
|
213
|
+
wexts: wextsDependency
|
|
214
|
+
},
|
|
215
|
+
devDependencies: {
|
|
216
|
+
"@types/node": "^22.19.1",
|
|
217
|
+
"@types/react": "^19.2.14",
|
|
218
|
+
"@types/react-dom": "^19.2.3",
|
|
219
|
+
typescript: "^5.9.3"
|
|
196
220
|
}
|
|
197
|
-
}
|
|
198
|
-
|
|
221
|
+
}, null, 2),
|
|
222
|
+
"apps/api/package.json": JSON.stringify({
|
|
223
|
+
name: `${projectName}-api`,
|
|
224
|
+
private: true,
|
|
225
|
+
scripts: {
|
|
226
|
+
"start:dev": "tsc -w -p tsconfig.json"
|
|
227
|
+
}
|
|
228
|
+
}, null, 2),
|
|
229
|
+
"apps/api/tsconfig.json": JSON.stringify({
|
|
230
|
+
compilerOptions: {
|
|
231
|
+
target: "ES2023",
|
|
232
|
+
module: "NodeNext",
|
|
233
|
+
moduleResolution: "NodeNext",
|
|
234
|
+
experimentalDecorators: true,
|
|
235
|
+
emitDecoratorMetadata: true,
|
|
236
|
+
strict: true,
|
|
237
|
+
esModuleInterop: true,
|
|
238
|
+
skipLibCheck: true,
|
|
239
|
+
outDir: "dist",
|
|
240
|
+
rootDir: "src"
|
|
241
|
+
},
|
|
242
|
+
include: [
|
|
243
|
+
"src/**/*.ts"
|
|
244
|
+
]
|
|
245
|
+
}, null, 2),
|
|
246
|
+
"apps/api/src/hello.service.ts": `import { Injectable } from '@nestjs/common';
|
|
247
|
+
import { RpcMethod, RpcService } from 'wexts/nest';
|
|
248
|
+
|
|
249
|
+
@Injectable()
|
|
250
|
+
@RpcService({ name: 'hello', requireAuth: false })
|
|
251
|
+
export class HelloService {
|
|
252
|
+
@RpcMethod()
|
|
253
|
+
async sayHello(name: string): Promise<string> {
|
|
254
|
+
return \`Hello, \${name}!\`;
|
|
199
255
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
256
|
+
}
|
|
257
|
+
`,
|
|
258
|
+
"apps/web/package.json": JSON.stringify({
|
|
259
|
+
name: `${projectName}-web`,
|
|
260
|
+
private: true,
|
|
261
|
+
scripts: {
|
|
262
|
+
dev: "next dev -p 3000"
|
|
263
|
+
}
|
|
264
|
+
}, null, 2),
|
|
265
|
+
"apps/web/tsconfig.json": JSON.stringify({
|
|
266
|
+
compilerOptions: {
|
|
267
|
+
target: "ES2022",
|
|
268
|
+
lib: [
|
|
269
|
+
"dom",
|
|
270
|
+
"dom.iterable",
|
|
271
|
+
"es2022"
|
|
272
|
+
],
|
|
273
|
+
allowJs: false,
|
|
274
|
+
skipLibCheck: true,
|
|
275
|
+
strict: true,
|
|
276
|
+
noEmit: true,
|
|
277
|
+
esModuleInterop: true,
|
|
278
|
+
module: "esnext",
|
|
279
|
+
moduleResolution: "bundler",
|
|
280
|
+
resolveJsonModule: true,
|
|
281
|
+
isolatedModules: true,
|
|
282
|
+
jsx: "react-jsx",
|
|
283
|
+
incremental: true,
|
|
284
|
+
plugins: [
|
|
285
|
+
{
|
|
286
|
+
name: "next"
|
|
287
|
+
}
|
|
288
|
+
]
|
|
289
|
+
},
|
|
290
|
+
include: [
|
|
291
|
+
"next-env.d.ts",
|
|
292
|
+
"**/*.ts",
|
|
293
|
+
"**/*.tsx",
|
|
294
|
+
".next/types/**/*.ts",
|
|
295
|
+
".next/dev/types/**/*.ts"
|
|
296
|
+
],
|
|
297
|
+
exclude: [
|
|
298
|
+
"node_modules"
|
|
299
|
+
]
|
|
300
|
+
}, null, 2),
|
|
301
|
+
"apps/web/next-env.d.ts": `/// <reference types="next" />
|
|
302
|
+
/// <reference types="next/image-types/global" />
|
|
303
|
+
|
|
304
|
+
// This file is generated by Next.js. Do not edit.
|
|
305
|
+
`,
|
|
306
|
+
"apps/web/next.config.ts": `import type { NextConfig } from 'next';
|
|
307
|
+
|
|
308
|
+
const nextConfig: NextConfig = {
|
|
309
|
+
output: 'standalone',
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export default nextConfig;
|
|
313
|
+
`,
|
|
314
|
+
"apps/web/app/layout.tsx": `import type { ReactNode } from 'react';
|
|
315
|
+
import { WextsProvider } from '../lib/wexts-provider';
|
|
316
|
+
|
|
317
|
+
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
318
|
+
return (
|
|
319
|
+
<html lang="en">
|
|
320
|
+
<body>
|
|
321
|
+
<WextsProvider>{children}</WextsProvider>
|
|
322
|
+
</body>
|
|
323
|
+
</html>
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
`,
|
|
327
|
+
"apps/web/app/page.tsx": `'use client';
|
|
328
|
+
|
|
329
|
+
import { useState } from 'react';
|
|
330
|
+
import { useWexts } from '../lib/wexts-provider';
|
|
331
|
+
|
|
332
|
+
export default function Page() {
|
|
333
|
+
const wexts = useWexts();
|
|
334
|
+
const [message, setMessage] = useState('Not called yet');
|
|
335
|
+
|
|
336
|
+
return (
|
|
337
|
+
<main>
|
|
338
|
+
<h1>Wexts Hello RPC</h1>
|
|
339
|
+
<button
|
|
340
|
+
type="button"
|
|
341
|
+
onClick={async () => {
|
|
342
|
+
setMessage(await wexts.hello.sayHello('Bob'));
|
|
343
|
+
}}
|
|
344
|
+
>
|
|
345
|
+
Call RPC
|
|
346
|
+
</button>
|
|
347
|
+
<p>{message}</p>
|
|
348
|
+
</main>
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
`,
|
|
352
|
+
"apps/web/lib/wexts-provider.tsx": `'use client';
|
|
353
|
+
|
|
354
|
+
import { FusionProvider, useWexts as useGeneratedWexts } from 'wexts/next';
|
|
355
|
+
import { createWextsClient, type WextsClient } from './wexts/client';
|
|
356
|
+
|
|
357
|
+
export function WextsProvider({ children }: { children: React.ReactNode }) {
|
|
358
|
+
return (
|
|
359
|
+
<FusionProvider rpcClient={createWextsClient({ baseUrl: '/rpc' })}>
|
|
360
|
+
{children}
|
|
361
|
+
</FusionProvider>
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export function useWexts(): WextsClient {
|
|
366
|
+
return useGeneratedWexts<WextsClient>();
|
|
367
|
+
}
|
|
368
|
+
`,
|
|
369
|
+
"wexts.runtime.js": `const { HelloService } = require('./apps/api/dist/hello.service.js');
|
|
370
|
+
|
|
371
|
+
module.exports = {
|
|
372
|
+
nextDir: './apps/web',
|
|
373
|
+
rpcManifestPath: './apps/web/lib/wexts/wexts.rpc.manifest.json',
|
|
374
|
+
rpcServices: {
|
|
375
|
+
hello: new HelloService(),
|
|
376
|
+
},
|
|
377
|
+
security: {
|
|
378
|
+
allowedOrigins: ['http://localhost:3000'],
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
`,
|
|
382
|
+
"README.md": `# ${projectName}
|
|
383
|
+
|
|
384
|
+
Verified Wexts starter with a generated Hello RPC client.
|
|
385
|
+
|
|
386
|
+
\`\`\`bash
|
|
387
|
+
pnpm install
|
|
388
|
+
pnpm run generate
|
|
389
|
+
pnpm run build
|
|
390
|
+
pnpm run doctor
|
|
391
|
+
pnpm run doctor:security
|
|
392
|
+
pnpm run start
|
|
393
|
+
\`\`\`
|
|
394
|
+
`
|
|
395
|
+
};
|
|
396
|
+
for (const [relativePath, content] of Object.entries(files)) {
|
|
397
|
+
const absolutePath = path.join(projectPath, relativePath);
|
|
398
|
+
fs.mkdirSync(path.dirname(absolutePath), {
|
|
227
399
|
recursive: true
|
|
228
400
|
});
|
|
229
|
-
|
|
230
|
-
const apiDestPath = path.join(projectPath, "apps/api");
|
|
231
|
-
if (fs.existsSync(apiTemplatePath)) {
|
|
232
|
-
fs.cpSync(apiTemplatePath, apiDestPath, {
|
|
233
|
-
recursive: true
|
|
234
|
-
});
|
|
235
|
-
logger.success(" - Copied API template");
|
|
236
|
-
const envExamplePath = path.join(apiDestPath, ".env.example");
|
|
237
|
-
const envPath = path.join(apiDestPath, ".env");
|
|
238
|
-
if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
|
|
239
|
-
fs.copyFileSync(envExamplePath, envPath);
|
|
240
|
-
logger.success(" - Created .env from .env.example");
|
|
241
|
-
}
|
|
242
|
-
} else {
|
|
243
|
-
logger.warn(` \u26A0\uFE0F API template not found at ${apiTemplatePath}`);
|
|
244
|
-
}
|
|
245
|
-
const webTemplatePath = path.join(templatePath, "nextjs-web");
|
|
246
|
-
const webDestPath = path.join(projectPath, "apps/web");
|
|
247
|
-
if (fs.existsSync(webTemplatePath)) {
|
|
248
|
-
fs.cpSync(webTemplatePath, webDestPath, {
|
|
249
|
-
recursive: true
|
|
250
|
-
});
|
|
251
|
-
logger.success(" - Copied Web template");
|
|
252
|
-
} else {
|
|
253
|
-
logger.warn(` \u26A0\uFE0F Web template not found at ${webTemplatePath}`);
|
|
254
|
-
}
|
|
401
|
+
fs.writeFileSync(absolutePath, content);
|
|
255
402
|
}
|
|
256
|
-
const
|
|
403
|
+
const { generateRpcClient } = await import("../codegen/index.mjs");
|
|
404
|
+
await generateRpcClient({
|
|
405
|
+
projectPath: path.join(projectPath, "apps/api"),
|
|
406
|
+
outputPath: path.join(projectPath, "apps/web/lib/wexts")
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
__name(createVerifiedStarter, "createVerifiedStarter");
|
|
410
|
+
function createLegacyProject(projectPath, projectName) {
|
|
411
|
+
const templatePath = findTemplatePath();
|
|
412
|
+
if (!templatePath) {
|
|
413
|
+
throw new Error("Template directory not found in package.");
|
|
414
|
+
}
|
|
415
|
+
fs.mkdirSync(path.join(projectPath, "apps"), {
|
|
416
|
+
recursive: true
|
|
417
|
+
});
|
|
418
|
+
fs.cpSync(path.join(templatePath, "nestjs-api"), path.join(projectPath, "apps/api"), {
|
|
419
|
+
recursive: true
|
|
420
|
+
});
|
|
421
|
+
fs.cpSync(path.join(templatePath, "nextjs-web"), path.join(projectPath, "apps/web"), {
|
|
422
|
+
recursive: true
|
|
423
|
+
});
|
|
424
|
+
fs.rmSync(path.join(projectPath, "apps/web/package-lock.json"), {
|
|
425
|
+
force: true
|
|
426
|
+
});
|
|
427
|
+
fs.rmSync(path.join(projectPath, "apps/api/package-lock.json"), {
|
|
428
|
+
force: true
|
|
429
|
+
});
|
|
430
|
+
fs.writeFileSync(path.join(projectPath, "pnpm-workspace.yaml"), "packages:\n - 'apps/*'\n");
|
|
431
|
+
fs.writeFileSync(path.join(projectPath, "package.json"), JSON.stringify({
|
|
257
432
|
name: projectName,
|
|
258
|
-
version: "0.0.0",
|
|
259
433
|
private: true,
|
|
434
|
+
packageManager: "pnpm@10.22.0",
|
|
260
435
|
scripts: {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
436
|
+
dev: "wexts dev",
|
|
437
|
+
generate: "wexts generate",
|
|
438
|
+
build: "wexts build",
|
|
439
|
+
start: "wexts start",
|
|
440
|
+
doctor: "wexts doctor"
|
|
265
441
|
},
|
|
266
442
|
devDependencies: {
|
|
267
|
-
|
|
268
|
-
"prettier": "latest",
|
|
269
|
-
"typescript": "^5.9.3",
|
|
270
|
-
"wexts": "latest"
|
|
271
|
-
},
|
|
272
|
-
packageManager: "pnpm@10.0.0"
|
|
273
|
-
};
|
|
274
|
-
fs.writeFileSync(path.join(projectPath, "package.json"), JSON.stringify(packageJson, null, 2));
|
|
275
|
-
const turboJson = {
|
|
276
|
-
"$schema": "https://turbo.build/schema.json",
|
|
277
|
-
"tasks": {
|
|
278
|
-
"build": {
|
|
279
|
-
"dependsOn": [
|
|
280
|
-
"^build"
|
|
281
|
-
],
|
|
282
|
-
"outputs": [
|
|
283
|
-
".next/**",
|
|
284
|
-
"!.next/cache/**",
|
|
285
|
-
"dist/**"
|
|
286
|
-
]
|
|
287
|
-
},
|
|
288
|
-
"lint": {},
|
|
289
|
-
"dev": {
|
|
290
|
-
"cache": false,
|
|
291
|
-
"persistent": true
|
|
292
|
-
}
|
|
443
|
+
wexts: `^${readPackageVersion()}`
|
|
293
444
|
}
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
fs.writeFileSync(path.join(projectPath, "pnpm-workspace.yaml"), pnpmWorkspace);
|
|
301
|
-
logger.success("\u2705 Project structure created");
|
|
302
|
-
logger.info("\u{1F4E6} Installing dependencies...");
|
|
445
|
+
}, null, 2));
|
|
446
|
+
}
|
|
447
|
+
__name(createLegacyProject, "createLegacyProject");
|
|
448
|
+
function resolveCreateWextsDependency(projectPath) {
|
|
449
|
+
const packageRoot = path.resolve(__dirname, "../..");
|
|
450
|
+
const cwdLocalPackage = path.join(process.cwd(), "node_modules/wexts");
|
|
303
451
|
try {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
452
|
+
if (fs.existsSync(cwdLocalPackage) && fs.realpathSync(cwdLocalPackage) === fs.realpathSync(packageRoot)) {
|
|
453
|
+
return `file:${path.relative(projectPath, cwdLocalPackage)}`;
|
|
454
|
+
}
|
|
455
|
+
} catch {
|
|
456
|
+
}
|
|
457
|
+
return `^${readPackageVersion()}`;
|
|
458
|
+
}
|
|
459
|
+
__name(resolveCreateWextsDependency, "resolveCreateWextsDependency");
|
|
460
|
+
async function scaffoldGenerator(options) {
|
|
461
|
+
if (options.type !== "config" && !options.name) {
|
|
462
|
+
throw new WextsError({
|
|
463
|
+
code: "WEXTS_CLI_GENERATOR_NAME_REQUIRED",
|
|
464
|
+
message: `Generator "${options.type}" requires a name.`,
|
|
465
|
+
suggestedFix: `Run \`wexts generate ${options.type} hello\` or use \`wexts generate config\`.`,
|
|
466
|
+
docsSlug: "cli"
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
if (options.type === "config") {
|
|
470
|
+
return writeGeneratedFiles(options.targetRoot, [
|
|
471
|
+
{
|
|
472
|
+
relativePath: "wexts.runtime.js",
|
|
473
|
+
content: `/** @type {import('wexts/runtime').WextsRuntimeConfig} */
|
|
474
|
+
module.exports = {
|
|
475
|
+
rootDir: __dirname,
|
|
476
|
+
port: Number(process.env.PORT || 3000),
|
|
477
|
+
rpcManifestPath: 'apps/web/lib/wexts/wexts.rpc.manifest.json',
|
|
478
|
+
security: {
|
|
479
|
+
enabled: true,
|
|
480
|
+
production: process.env.NODE_ENV === 'production',
|
|
481
|
+
allowedOrigins: process.env.WEXTS_ALLOWED_ORIGINS?.split(',').filter(Boolean) || [],
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
`
|
|
485
|
+
}
|
|
486
|
+
], Boolean(options.force));
|
|
487
|
+
}
|
|
488
|
+
const rawName = options.name;
|
|
489
|
+
const name = toKebabCase(rawName);
|
|
490
|
+
const classBase = toPascalCase(name);
|
|
491
|
+
const srcRoot = path.join(options.targetRoot, "src");
|
|
492
|
+
const filesByType = {
|
|
493
|
+
rpc: rpcServiceFiles(name, classBase),
|
|
494
|
+
service: [
|
|
495
|
+
{
|
|
496
|
+
relativePath: path.join("src", name, `${name}.service.ts`),
|
|
497
|
+
content: `import { Injectable } from '@nestjs/common';
|
|
498
|
+
|
|
499
|
+
@Injectable()
|
|
500
|
+
export class ${classBase}Service {
|
|
501
|
+
async execute(): Promise<string> {
|
|
502
|
+
return '${toCamelCase(name)}';
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
`
|
|
506
|
+
}
|
|
507
|
+
],
|
|
508
|
+
module: [
|
|
509
|
+
{
|
|
510
|
+
relativePath: path.join("src", name, `${name}.module.ts`),
|
|
511
|
+
content: `import { Module } from '@nestjs/common';
|
|
512
|
+
|
|
513
|
+
@Module({})
|
|
514
|
+
export class ${classBase}Module {}
|
|
515
|
+
`
|
|
516
|
+
}
|
|
517
|
+
],
|
|
518
|
+
entity: [
|
|
519
|
+
{
|
|
520
|
+
relativePath: path.join("src", name, `${name}.entity.ts`),
|
|
521
|
+
content: `export interface ${classBase}Entity {
|
|
522
|
+
id: string;
|
|
523
|
+
createdAt: Date;
|
|
524
|
+
updatedAt: Date;
|
|
525
|
+
}
|
|
526
|
+
`
|
|
527
|
+
}
|
|
528
|
+
],
|
|
529
|
+
guard: [
|
|
530
|
+
{
|
|
531
|
+
relativePath: path.join("src", name, `${name}.guard.ts`),
|
|
532
|
+
content: `import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
|
533
|
+
|
|
534
|
+
@Injectable()
|
|
535
|
+
export class ${classBase}Guard implements CanActivate {
|
|
536
|
+
canActivate(_context: ExecutionContext): boolean {
|
|
537
|
+
return true;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
`
|
|
541
|
+
}
|
|
542
|
+
]
|
|
543
|
+
};
|
|
544
|
+
fs.mkdirSync(srcRoot, {
|
|
545
|
+
recursive: true
|
|
546
|
+
});
|
|
547
|
+
return writeGeneratedFiles(options.targetRoot, filesByType[options.type], Boolean(options.force));
|
|
548
|
+
}
|
|
549
|
+
__name(scaffoldGenerator, "scaffoldGenerator");
|
|
550
|
+
function isScaffoldGenerator(type) {
|
|
551
|
+
return [
|
|
552
|
+
"rpc",
|
|
553
|
+
"service",
|
|
554
|
+
"module",
|
|
555
|
+
"entity",
|
|
556
|
+
"guard",
|
|
557
|
+
"config"
|
|
558
|
+
].includes(type);
|
|
559
|
+
}
|
|
560
|
+
__name(isScaffoldGenerator, "isScaffoldGenerator");
|
|
561
|
+
function rpcServiceFiles(serviceName, classBase) {
|
|
562
|
+
return [
|
|
563
|
+
{
|
|
564
|
+
relativePath: path.join("src", serviceName, `${serviceName}.service.ts`),
|
|
565
|
+
content: `import { Injectable } from '@nestjs/common';
|
|
566
|
+
import { RpcMethod, RpcService } from 'wexts/nest';
|
|
567
|
+
|
|
568
|
+
@Injectable()
|
|
569
|
+
@RpcService({ name: '${toCamelCase(serviceName)}', requireAuth: false })
|
|
570
|
+
export class ${classBase}Service {
|
|
571
|
+
@RpcMethod()
|
|
572
|
+
async sayHello(name: string): Promise<string> {
|
|
573
|
+
return \`Hello, \${name}!\`;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
`
|
|
577
|
+
}
|
|
578
|
+
];
|
|
579
|
+
}
|
|
580
|
+
__name(rpcServiceFiles, "rpcServiceFiles");
|
|
581
|
+
function writeGeneratedFiles(root, files, force) {
|
|
582
|
+
const changedFiles = [];
|
|
583
|
+
for (const file of files) {
|
|
584
|
+
const absolutePath = path.join(root, file.relativePath);
|
|
585
|
+
if (fs.existsSync(absolutePath) && !force) {
|
|
586
|
+
throw new WextsError({
|
|
587
|
+
code: "WEXTS_CLI_GENERATOR_FILE_EXISTS",
|
|
588
|
+
message: `Refusing to overwrite existing file: ${absolutePath}`,
|
|
589
|
+
suggestedFix: "Review the file, then rerun with --force if overwriting is intentional.",
|
|
590
|
+
docsSlug: "cli"
|
|
312
591
|
});
|
|
313
592
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
stdio: "inherit"
|
|
593
|
+
fs.mkdirSync(path.dirname(absolutePath), {
|
|
594
|
+
recursive: true
|
|
317
595
|
});
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
\u{1F389} Project ${projectName} created successfully!`));
|
|
321
|
-
logger.info(`
|
|
322
|
-
To get started:
|
|
323
|
-
`);
|
|
324
|
-
logger.info(pc.cyan(` cd ${projectName}`));
|
|
325
|
-
logger.info(pc.cyan(` pnpm dev
|
|
326
|
-
`));
|
|
327
|
-
} catch (error) {
|
|
328
|
-
logger.error("Failed to install dependencies");
|
|
596
|
+
fs.writeFileSync(absolutePath, file.content);
|
|
597
|
+
changedFiles.push(absolutePath);
|
|
329
598
|
}
|
|
599
|
+
return changedFiles;
|
|
330
600
|
}
|
|
331
|
-
__name(
|
|
332
|
-
|
|
601
|
+
__name(writeGeneratedFiles, "writeGeneratedFiles");
|
|
602
|
+
function runScript(script, options) {
|
|
603
|
+
const cwd = options.cwd ?? process.cwd();
|
|
604
|
+
const packageManager = detectPackageManager(cwd);
|
|
605
|
+
const args = packageManager === "npm" ? [
|
|
606
|
+
"run",
|
|
607
|
+
script
|
|
608
|
+
] : [
|
|
609
|
+
"run",
|
|
610
|
+
script
|
|
611
|
+
];
|
|
612
|
+
runCommand(packageManager, args, cwd);
|
|
613
|
+
}
|
|
614
|
+
__name(runScript, "runScript");
|
|
615
|
+
function runCommand(command, args, cwd) {
|
|
616
|
+
const result = spawnSync(command, args, {
|
|
617
|
+
cwd,
|
|
618
|
+
stdio: "inherit",
|
|
619
|
+
shell: process.platform === "win32"
|
|
620
|
+
});
|
|
621
|
+
if (result.status !== 0) {
|
|
622
|
+
throw new Error(`${command} ${args.join(" ")} failed with exit code ${result.status}`);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
__name(runCommand, "runCommand");
|
|
626
|
+
function detectPackageManager(cwd) {
|
|
627
|
+
const packageJsonPath = path.join(cwd, "package.json");
|
|
628
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
629
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
630
|
+
if (pkg.packageManager?.startsWith("pnpm@")) return "pnpm";
|
|
631
|
+
}
|
|
632
|
+
if (fs.existsSync(path.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
633
|
+
if (fs.existsSync(path.join(cwd, "pnpm-workspace.yaml"))) return "pnpm";
|
|
634
|
+
return "npm";
|
|
635
|
+
}
|
|
636
|
+
__name(detectPackageManager, "detectPackageManager");
|
|
637
|
+
function findTemplatePath() {
|
|
638
|
+
const candidates = [
|
|
639
|
+
path.resolve(__dirname, "../../templates"),
|
|
640
|
+
path.resolve(__dirname, "../templates"),
|
|
641
|
+
path.resolve(process.cwd(), "packages/templates")
|
|
642
|
+
];
|
|
643
|
+
return candidates.find((candidate) => fs.existsSync(candidate));
|
|
644
|
+
}
|
|
645
|
+
__name(findTemplatePath, "findTemplatePath");
|
|
646
|
+
function readPackageVersion() {
|
|
647
|
+
const packageJsonPath = path.resolve(__dirname, "../../package.json");
|
|
648
|
+
if (!fs.existsSync(packageJsonPath)) return "0.0.0";
|
|
649
|
+
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).version;
|
|
650
|
+
}
|
|
651
|
+
__name(readPackageVersion, "readPackageVersion");
|
|
652
|
+
function readAllText(cwd, dirs) {
|
|
653
|
+
let text = "";
|
|
654
|
+
for (const dir of dirs) {
|
|
655
|
+
const absolute = path.join(cwd, dir);
|
|
656
|
+
if (!fs.existsSync(absolute)) continue;
|
|
657
|
+
for (const file of walk(absolute)) {
|
|
658
|
+
if (file.endsWith(".ts") || file.endsWith(".tsx") || file.endsWith(".js")) {
|
|
659
|
+
text += fs.readFileSync(file, "utf8");
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return text;
|
|
664
|
+
}
|
|
665
|
+
__name(readAllText, "readAllText");
|
|
666
|
+
function walk(dir) {
|
|
667
|
+
return fs.readdirSync(dir, {
|
|
668
|
+
withFileTypes: true
|
|
669
|
+
}).flatMap((entry) => {
|
|
670
|
+
const absolute = path.join(dir, entry.name);
|
|
671
|
+
if (entry.isDirectory()) return walk(absolute);
|
|
672
|
+
return [
|
|
673
|
+
absolute
|
|
674
|
+
];
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
__name(walk, "walk");
|
|
678
|
+
function toKebabCase(value) {
|
|
679
|
+
return value.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
|
|
680
|
+
}
|
|
681
|
+
__name(toKebabCase, "toKebabCase");
|
|
682
|
+
function toPascalCase(value) {
|
|
683
|
+
return toKebabCase(value).split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
684
|
+
}
|
|
685
|
+
__name(toPascalCase, "toPascalCase");
|
|
686
|
+
function toCamelCase(value) {
|
|
687
|
+
const pascal = toPascalCase(value);
|
|
688
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
689
|
+
}
|
|
690
|
+
__name(toCamelCase, "toCamelCase");
|
|
691
|
+
function pathToFileUrl(filePath) {
|
|
692
|
+
return `file://${filePath}`;
|
|
693
|
+
}
|
|
694
|
+
__name(pathToFileUrl, "pathToFileUrl");
|
|
695
|
+
async function loadRuntimeConfig(configPath) {
|
|
696
|
+
if (configPath.endsWith(".mjs")) {
|
|
697
|
+
const mod2 = await import(pathToFileUrl(configPath));
|
|
698
|
+
return mod2.default ?? mod2;
|
|
699
|
+
}
|
|
700
|
+
const require2 = createRequire(__filename);
|
|
701
|
+
const mod = require2(configPath);
|
|
702
|
+
return mod.default ?? mod;
|
|
703
|
+
}
|
|
704
|
+
__name(loadRuntimeConfig, "loadRuntimeConfig");
|
|
705
|
+
var invokedAsCli = process.argv[1] && (path.basename(process.argv[1]) === "wexts" || path.basename(process.argv[1]) === "wexts.cjs" || path.resolve(process.argv[1]).includes(`${path.sep}dist${path.sep}cli${path.sep}index`));
|
|
706
|
+
if (invokedAsCli && !process.env.VITEST) {
|
|
707
|
+
createCliProgram().parseAsync(process.argv).catch((error) => {
|
|
708
|
+
logger.error(formatWextsError(error));
|
|
709
|
+
process.exit(1);
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
export {
|
|
713
|
+
createCliProgram,
|
|
714
|
+
createProject,
|
|
715
|
+
runDoctor,
|
|
716
|
+
scaffoldGenerator
|
|
717
|
+
};
|
|
333
718
|
//# sourceMappingURL=index.mjs.map
|