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.
Files changed (288) hide show
  1. package/README.md +49 -346
  2. package/bin/wexts.cjs +2 -0
  3. package/dist/chunk-2KAQYLVN.js +0 -0
  4. package/dist/chunk-2KAQYLVN.js.map +1 -1
  5. package/dist/{chunk-O42L6HOX.js → chunk-2LJVUMXW.js} +79 -93
  6. package/dist/chunk-2LJVUMXW.js.map +1 -0
  7. package/dist/chunk-342VRT25.mjs +504 -0
  8. package/dist/chunk-342VRT25.mjs.map +1 -0
  9. package/dist/chunk-7HNQWJWV.js +504 -0
  10. package/dist/chunk-7HNQWJWV.js.map +1 -0
  11. package/dist/chunk-7QKLIVRF.js +94 -0
  12. package/dist/chunk-7QKLIVRF.js.map +1 -0
  13. package/dist/chunk-7SSCNCTW.mjs +137 -0
  14. package/dist/chunk-7SSCNCTW.mjs.map +1 -0
  15. package/dist/chunk-7TLSPR65.mjs +95 -0
  16. package/dist/chunk-7TLSPR65.mjs.map +1 -0
  17. package/dist/{chunk-FCEZDH42.mjs → chunk-7WULUGLH.mjs} +5 -3
  18. package/dist/chunk-7WULUGLH.mjs.map +1 -0
  19. package/dist/chunk-AVMQJWYD.js +95 -0
  20. package/dist/chunk-AVMQJWYD.js.map +1 -0
  21. package/dist/{chunk-WF65EDRZ.js → chunk-BG56B4DE.js} +20 -2
  22. package/dist/chunk-BG56B4DE.js.map +1 -0
  23. package/dist/chunk-CLM5PNSG.mjs +496 -0
  24. package/dist/chunk-CLM5PNSG.mjs.map +1 -0
  25. package/dist/chunk-DNLGCKTT.js +31 -0
  26. package/dist/chunk-DNLGCKTT.js.map +1 -0
  27. package/dist/{chunk-VNNVLQLJ.mjs → chunk-JHOVXH3X.mjs} +2 -2
  28. package/dist/chunk-JHOVXH3X.mjs.map +1 -0
  29. package/dist/chunk-MXINIFPC.js +105 -0
  30. package/dist/chunk-MXINIFPC.js.map +1 -0
  31. package/dist/chunk-O4II6N34.js +137 -0
  32. package/dist/chunk-O4II6N34.js.map +1 -0
  33. package/dist/chunk-SE32ZPOZ.js +496 -0
  34. package/dist/chunk-SE32ZPOZ.js.map +1 -0
  35. package/dist/{chunk-STTOPUZ2.mjs → chunk-UAL54DVV.mjs} +21 -3
  36. package/dist/chunk-UAL54DVV.mjs.map +1 -0
  37. package/dist/{chunk-3OM7CHCA.js → chunk-WCKSKU3C.js} +1 -1
  38. package/dist/chunk-WCKSKU3C.js.map +1 -0
  39. package/dist/chunk-WU6FW77M.mjs +105 -0
  40. package/dist/chunk-WU6FW77M.mjs.map +1 -0
  41. package/dist/chunk-XE4OXN2W.js +0 -0
  42. package/dist/chunk-XE4OXN2W.js.map +1 -1
  43. package/dist/chunk-YBM3IJEA.mjs +94 -0
  44. package/dist/chunk-YBM3IJEA.mjs.map +1 -0
  45. package/dist/{chunk-KXYLEUSW.mjs → chunk-YN6WIWNQ.mjs} +69 -83
  46. package/dist/chunk-YN6WIWNQ.mjs.map +1 -0
  47. package/dist/chunk-YSLEF5C5.mjs +0 -0
  48. package/dist/chunk-YSLEF5C5.mjs.map +0 -0
  49. package/dist/chunk-ZX7QIN24.mjs +31 -0
  50. package/dist/chunk-ZX7QIN24.mjs.map +1 -0
  51. package/dist/cli/index.d.mts +22 -0
  52. package/dist/cli/index.d.ts +22 -0
  53. package/dist/cli/index.js +676 -292
  54. package/dist/cli/index.js.map +1 -1
  55. package/dist/cli/index.mjs +678 -293
  56. package/dist/cli/index.mjs.map +1 -1
  57. package/dist/client/index.d.mts +10 -1
  58. package/dist/client/index.d.ts +10 -1
  59. package/dist/client/index.js +5 -2
  60. package/dist/client/index.js.map +1 -1
  61. package/dist/client/index.mjs +7 -4
  62. package/dist/client/index.mjs.map +0 -0
  63. package/dist/codegen/index.d.mts +2 -1
  64. package/dist/codegen/index.d.ts +2 -1
  65. package/dist/codegen/index.js +6 -3
  66. package/dist/codegen/index.js.map +1 -1
  67. package/dist/codegen/index.mjs +8 -5
  68. package/dist/codegen/index.mjs.map +0 -0
  69. package/dist/decorators-BT1FFqN0.d.mts +29 -0
  70. package/dist/decorators-DvS58PqC.d.ts +29 -0
  71. package/dist/dev-server/index.d.mts +1 -1
  72. package/dist/dev-server/index.d.ts +1 -1
  73. package/dist/dev-server/index.js +3 -3
  74. package/dist/dev-server/index.js.map +1 -1
  75. package/dist/dev-server/index.mjs +3 -3
  76. package/dist/dev-server/index.mjs.map +0 -0
  77. package/dist/{index-SjUaHgFr.d.ts → index-7QeQEf37.d.ts} +27 -10
  78. package/dist/{index-tFGPFVfQ.d.mts → index-7RvU-jGE.d.mts} +0 -1
  79. package/dist/{index-tFGPFVfQ.d.ts → index-7RvU-jGE.d.ts} +0 -1
  80. package/dist/{index-SjUaHgFr.d.mts → index-8nzxy0NN.d.mts} +27 -10
  81. package/dist/index-Co5ZsLqq.d.ts +58 -0
  82. package/dist/index-D94W1__r.d.mts +58 -0
  83. package/dist/index-DQmyVp6F.d.mts +27 -0
  84. package/dist/index-KL_1BrQb.d.ts +27 -0
  85. package/dist/index.d.mts +54 -7
  86. package/dist/index.d.ts +54 -7
  87. package/dist/index.js +70 -29
  88. package/dist/index.js.map +1 -1
  89. package/dist/index.mjs +62 -21
  90. package/dist/index.mjs.map +1 -1
  91. package/dist/nest/index.d.mts +3 -1
  92. package/dist/nest/index.d.ts +3 -1
  93. package/dist/nest/index.js +20 -2
  94. package/dist/nest/index.js.map +1 -1
  95. package/dist/nest/index.mjs +21 -3
  96. package/dist/nest/index.mjs.map +0 -0
  97. package/dist/next/index.d.mts +7 -2
  98. package/dist/next/index.d.ts +7 -2
  99. package/dist/next/index.js +135 -5
  100. package/dist/next/index.js.map +1 -1
  101. package/dist/next/index.mjs +133 -4
  102. package/dist/next/index.mjs.map +1 -1
  103. package/dist/rpc/index.d.mts +2 -0
  104. package/dist/rpc/index.d.ts +2 -0
  105. package/dist/rpc/index.js +23 -0
  106. package/dist/rpc/index.js.map +1 -0
  107. package/dist/rpc/index.mjs +23 -0
  108. package/dist/{chunk-7NSRDJ5C.mjs.map → rpc/index.mjs.map} +0 -0
  109. package/dist/runtime/index.d.mts +55 -0
  110. package/dist/runtime/index.d.ts +55 -0
  111. package/dist/runtime/index.js +221 -0
  112. package/dist/runtime/index.js.map +1 -0
  113. package/dist/runtime/index.mjs +221 -0
  114. package/dist/runtime/index.mjs.map +1 -0
  115. package/dist/types/index.d.mts +0 -0
  116. package/dist/types/index.d.ts +0 -0
  117. package/dist/types/index.js +0 -0
  118. package/dist/types/index.js.map +1 -1
  119. package/dist/types/index.mjs +1 -1
  120. package/dist/types/index.mjs.map +0 -0
  121. package/dist/types-7d_fC-C3.d.mts +32 -0
  122. package/dist/types-7d_fC-C3.d.ts +32 -0
  123. package/dist/vercel-builder/index.d.mts +58 -0
  124. package/dist/vercel-builder/index.d.ts +58 -0
  125. package/dist/vercel-builder/index.js +330 -0
  126. package/dist/vercel-builder/index.js.map +1 -0
  127. package/dist/vercel-builder/index.mjs +330 -0
  128. package/dist/vercel-builder/index.mjs.map +1 -0
  129. package/package.json +37 -16
  130. package/templates/.dockerignore +43 -43
  131. package/templates/.env.example +0 -0
  132. package/templates/Dockerfile +60 -60
  133. package/templates/Procfile +1 -1
  134. package/templates/README.md +67 -58
  135. package/templates/api-sdk.ts +115 -115
  136. package/templates/docker-compose.yml +34 -34
  137. package/templates/nestjs-api/.env.example +0 -0
  138. package/templates/nestjs-api/README.md +87 -79
  139. package/templates/nestjs-api/nest-cli.json +6 -6
  140. package/templates/nestjs-api/package.json +40 -40
  141. package/templates/nestjs-api/prisma/dev.db +0 -0
  142. package/templates/nestjs-api/prisma/migrations/20251123205437_init/migration.sql +0 -0
  143. package/templates/nestjs-api/prisma/migrations/migration_lock.toml +0 -0
  144. package/templates/nestjs-api/prisma/schema.prisma +29 -29
  145. package/templates/nestjs-api/src/app.module.ts +17 -17
  146. package/templates/nestjs-api/src/auth/auth.controller.ts +27 -27
  147. package/templates/nestjs-api/src/auth/auth.module.ts +37 -29
  148. package/templates/nestjs-api/src/auth/auth.service.ts +86 -86
  149. package/templates/nestjs-api/src/auth/dto/auth.dto.ts +22 -22
  150. package/templates/nestjs-api/src/auth/guards/jwt-auth.guard.ts +5 -5
  151. package/templates/nestjs-api/src/auth/strategies/jwt.strategy.ts +27 -19
  152. package/templates/nestjs-api/src/main.ts +32 -32
  153. package/templates/nestjs-api/src/prisma/prisma.module.ts +9 -9
  154. package/templates/nestjs-api/src/prisma/prisma.service.ts +14 -14
  155. package/templates/nestjs-api/src/todos/dto/todo.dto.ts +24 -24
  156. package/templates/nestjs-api/src/todos/todos.controller.ts +39 -39
  157. package/templates/nestjs-api/src/todos/todos.module.ts +11 -11
  158. package/templates/nestjs-api/src/todos/todos.service.ts +53 -53
  159. package/templates/nestjs-api/src/users/users.controller.ts +14 -14
  160. package/templates/nestjs-api/src/users/users.module.ts +12 -12
  161. package/templates/nestjs-api/src/users/users.service.ts +19 -19
  162. package/templates/nestjs-api/tsconfig.json +39 -39
  163. package/templates/nextjs-web/README.md +76 -68
  164. package/templates/nextjs-web/app/actions/auth.ts +108 -108
  165. package/templates/nextjs-web/app/dashboard/error.tsx +39 -39
  166. package/templates/nextjs-web/app/dashboard/loading.tsx +14 -14
  167. package/templates/nextjs-web/app/dashboard/page.tsx +5 -5
  168. package/templates/nextjs-web/app/globals.css +93 -93
  169. package/templates/nextjs-web/app/layout.tsx +29 -29
  170. package/templates/nextjs-web/app/login/page.tsx +5 -5
  171. package/templates/nextjs-web/app/page.tsx +28 -28
  172. package/templates/nextjs-web/app/register/page.tsx +5 -5
  173. package/templates/nextjs-web/components/ui/button.tsx +56 -56
  174. package/templates/nextjs-web/components/ui/card.tsx +79 -79
  175. package/templates/nextjs-web/components/ui/input.tsx +25 -25
  176. package/templates/nextjs-web/components/ui/label.tsx +24 -24
  177. package/templates/nextjs-web/features/auth/LoginForm.tsx +140 -140
  178. package/templates/nextjs-web/features/auth/RegisterForm.tsx +159 -159
  179. package/templates/nextjs-web/features/auth/api.ts +35 -35
  180. package/templates/nextjs-web/features/auth/index.ts +3 -3
  181. package/templates/nextjs-web/features/dashboard/DashboardView.tsx +204 -204
  182. package/templates/nextjs-web/features/dashboard/api.ts +9 -9
  183. package/templates/nextjs-web/features/dashboard/components.tsx +74 -74
  184. package/templates/nextjs-web/features/dashboard/index.ts +3 -3
  185. package/templates/nextjs-web/hooks/index.ts +4 -4
  186. package/templates/nextjs-web/lib/api-client.ts +89 -89
  187. package/templates/nextjs-web/lib/api.ts +115 -115
  188. package/templates/nextjs-web/lib/axios-global-config.ts +17 -17
  189. package/templates/nextjs-web/lib/utils.ts +6 -6
  190. package/templates/nextjs-web/lib/wexts-client.ts +4 -4
  191. package/templates/nextjs-web/next-env.d.ts +6 -6
  192. package/templates/nextjs-web/next.config.ts +20 -20
  193. package/templates/nextjs-web/package.json +37 -37
  194. package/templates/nextjs-web/postcss.config.js +6 -6
  195. package/templates/nextjs-web/tailwind.config.ts +69 -69
  196. package/templates/nextjs-web/tsconfig.json +1 -1
  197. package/templates/nixpacks.toml +11 -11
  198. package/templates/root-package.json +31 -31
  199. package/templates/server.ts +66 -66
  200. package/templates/tsconfig.json +30 -30
  201. package/dist/chunk-2MCBBWEA.js +0 -1
  202. package/dist/chunk-2MCBBWEA.js.map +0 -1
  203. package/dist/chunk-3OM7CHCA.js.map +0 -1
  204. package/dist/chunk-63MTCWU2.mjs +0 -361
  205. package/dist/chunk-63MTCWU2.mjs.map +0 -1
  206. package/dist/chunk-667BQCEM.js +0 -375
  207. package/dist/chunk-667BQCEM.js.map +0 -1
  208. package/dist/chunk-67IJ6H4J.mjs +0 -44
  209. package/dist/chunk-67IJ6H4J.mjs.map +0 -1
  210. package/dist/chunk-6SVQEGEX.mjs +0 -44
  211. package/dist/chunk-6SVQEGEX.mjs.map +0 -1
  212. package/dist/chunk-7NSRDJ5C.mjs +0 -1
  213. package/dist/chunk-ASDXAK6G.js +0 -44
  214. package/dist/chunk-ASDXAK6G.js.map +0 -1
  215. package/dist/chunk-CKZ4VSCB.mjs +0 -18
  216. package/dist/chunk-CKZ4VSCB.mjs.map +0 -1
  217. package/dist/chunk-DW6GOKMF.js +0 -57
  218. package/dist/chunk-DW6GOKMF.js.map +0 -1
  219. package/dist/chunk-EFZPSZWO.mjs +0 -1
  220. package/dist/chunk-EFZPSZWO.mjs.map +0 -1
  221. package/dist/chunk-FCEZDH42.mjs.map +0 -1
  222. package/dist/chunk-FYGXL4V7.js +0 -361
  223. package/dist/chunk-FYGXL4V7.js.map +0 -1
  224. package/dist/chunk-GKVPGKAH.js +0 -66
  225. package/dist/chunk-GKVPGKAH.js.map +0 -1
  226. package/dist/chunk-GWP6PNSP.js +0 -225
  227. package/dist/chunk-GWP6PNSP.js.map +0 -1
  228. package/dist/chunk-HQKTXE7E.mjs +0 -225
  229. package/dist/chunk-HQKTXE7E.mjs.map +0 -1
  230. package/dist/chunk-HSFLZUJN.mjs +0 -57
  231. package/dist/chunk-HSFLZUJN.mjs.map +0 -1
  232. package/dist/chunk-HU63F22V.js +0 -361
  233. package/dist/chunk-HU63F22V.js.map +0 -1
  234. package/dist/chunk-J5LGTIGS.mjs +0 -10
  235. package/dist/chunk-J5LGTIGS.mjs.map +0 -1
  236. package/dist/chunk-JMBD6DOP.js +0 -225
  237. package/dist/chunk-JMBD6DOP.js.map +0 -1
  238. package/dist/chunk-K7EIJSYQ.js +0 -1
  239. package/dist/chunk-K7EIJSYQ.js.map +0 -1
  240. package/dist/chunk-KXYLEUSW.mjs.map +0 -1
  241. package/dist/chunk-MTHKZO55.js +0 -44
  242. package/dist/chunk-MTHKZO55.js.map +0 -1
  243. package/dist/chunk-NNQFLD7O.mjs +0 -361
  244. package/dist/chunk-NNQFLD7O.mjs.map +0 -1
  245. package/dist/chunk-NU2UB242.js +0 -82
  246. package/dist/chunk-NU2UB242.js.map +0 -1
  247. package/dist/chunk-NULGSZFE.mjs +0 -57
  248. package/dist/chunk-NULGSZFE.mjs.map +0 -1
  249. package/dist/chunk-O42L6HOX.js.map +0 -1
  250. package/dist/chunk-ONXNE2A6.mjs +0 -375
  251. package/dist/chunk-ONXNE2A6.mjs.map +0 -1
  252. package/dist/chunk-OTBYRUBE.mjs +0 -225
  253. package/dist/chunk-OTBYRUBE.mjs.map +0 -1
  254. package/dist/chunk-OTSAVKLY.mjs +0 -66
  255. package/dist/chunk-OTSAVKLY.mjs.map +0 -1
  256. package/dist/chunk-PZ5AY32C.js +0 -10
  257. package/dist/chunk-PZ5AY32C.js.map +0 -1
  258. package/dist/chunk-QP2TMRLG.js +0 -57
  259. package/dist/chunk-QP2TMRLG.js.map +0 -1
  260. package/dist/chunk-RS23R3ZQ.mjs +0 -82
  261. package/dist/chunk-RS23R3ZQ.mjs.map +0 -1
  262. package/dist/chunk-STTOPUZ2.mjs.map +0 -1
  263. package/dist/chunk-VMT3LALB.mjs +0 -51
  264. package/dist/chunk-VMT3LALB.mjs.map +0 -1
  265. package/dist/chunk-VNNVLQLJ.mjs.map +0 -1
  266. package/dist/chunk-W3YRVEFQ.js +0 -66
  267. package/dist/chunk-W3YRVEFQ.js.map +0 -1
  268. package/dist/chunk-WF65EDRZ.js.map +0 -1
  269. package/dist/chunk-WMHVXEYQ.mjs +0 -66
  270. package/dist/chunk-WMHVXEYQ.mjs.map +0 -1
  271. package/dist/chunk-XVKTIYHY.js +0 -51
  272. package/dist/chunk-XVKTIYHY.js.map +0 -1
  273. package/dist/codegen-MRZDLCYI.js +0 -13
  274. package/dist/codegen-MRZDLCYI.js.map +0 -1
  275. package/dist/codegen-UI5HTMXE.mjs +0 -13
  276. package/dist/codegen-UI5HTMXE.mjs.map +0 -1
  277. package/dist/dev-server-JKRVBWPY.mjs +0 -13
  278. package/dist/dev-server-JKRVBWPY.mjs.map +0 -1
  279. package/dist/dev-server-TLL7UQMR.js +0 -13
  280. package/dist/dev-server-TLL7UQMR.js.map +0 -1
  281. package/dist/index-BsNaOUtH.d.mts +0 -44
  282. package/dist/index-BsNaOUtH.d.ts +0 -44
  283. package/dist/index-CrbXnXsO.d.ts +0 -62
  284. package/dist/index-kEbGExWM.d.mts +0 -62
  285. package/templates/nestjs-api/.env +0 -4
  286. package/templates/nestjs-api/package-lock.json +0 -5623
  287. package/templates/nextjs-web/.env +0 -1
  288. package/templates/nextjs-web/package-lock.json +0 -3254
@@ -1,333 +1,718 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  logger
4
- } from "../chunk-VNNVLQLJ.mjs";
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-FCEZDH42.mjs";
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 { execSync } from "child_process";
17
- var program = new Command();
18
- program.name("wexts").description("Wexts Framework - Next.js 16 + NestJS 11").version("2.0.0");
19
- program.action(async () => {
20
- console.log(pc.cyan(`
21
- \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
22
- \u2551 \u2551
23
- \u2551 ${pc.bold("\u{1F680} Wexts Framework v2.0")} \u2551
24
- \u2551 \u2551
25
- \u2551 Next.js 16 + NestJS 11 Full-Stack \u2551
26
- \u2551 \u2551
27
- \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
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: parseInt(options.port),
141
- apiPort: parseInt(options.apiPort),
35
+ webPort: Number(options.port),
36
+ apiPort: Number(options.apiPort),
142
37
  useProxy: options.proxy
143
38
  });
144
- } catch (error) {
145
- logger.error("Failed to start dev server:", error.message);
146
- process.exit(1);
147
- }
148
- });
149
- program.command("build").description("Build for production").action(async () => {
150
- logger.info(pc.blue("Building Wexts project..."));
151
- logger.warn("Build not yet implemented");
152
- });
153
- program.command("generate <type> <name>").alias("g").description("Generate code (controller|module|page)").action(async (type, name) => {
154
- logger.info(pc.magenta(`Generating ${type}: ${name}`));
155
- logger.warn("Code generation not yet implemented");
156
- });
157
- program.command("codegen").description("Generate API client from NestJS controllers").option("-w, --watch", "Watch mode - regenerate on changes").option("-p, --project <path>", "Path to NestJS project", "./apps/api").option("-o, --output <path>", "Output path for generated client", "./packages/api-client/src").action(async (options) => {
158
- const { NestJSParser, ClientGenerator, CodegenWatcher } = await import("../codegen/index.mjs");
159
- if (options.watch) {
160
- logger.info(pc.cyan("Starting codegen in watch mode..."));
161
- const watcher = new CodegenWatcher();
162
- await watcher.watch({
163
- projectPath: options.project,
164
- outputPath: options.output
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
- } else {
167
- logger.info(pc.cyan("Generating API client..."));
168
- const parser = new NestJSParser(options.project);
169
- const controllers = parser.findFusionControllers();
170
- const generator = new ClientGenerator();
171
- await generator.generate({
172
- controllers,
173
- outputPath: options.output
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
- async function createProject(projectName, template) {
178
- logger.info(pc.cyan(`Creating wexts project: ${pc.bold(projectName)}`));
179
- logger.info(`Template: ${template}`);
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
- logger.error(`Directory ${projectName} already exists!`);
183
- process.exit(1);
168
+ throw new Error(`Directory already exists: ${projectName}`);
184
169
  }
185
- function getTemplatePath() {
186
- const possiblePaths = [
187
- path.join(__dirname, "../../templates"),
188
- path.join(__dirname, "../templates"),
189
- path.join(process.cwd(), "templates"),
190
- path.resolve(__dirname, "..", "..", "templates")
191
- // Absolute resolve
192
- ];
193
- for (const p of possiblePaths) {
194
- if (fs.existsSync(p)) {
195
- return p;
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
- return "";
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
- __name(getTemplatePath, "getTemplatePath");
201
- const templatePath = getTemplatePath();
202
- if (!templatePath) {
203
- logger.error(`\u274C Template directory not found!`);
204
- logger.info(`Searched in:`);
205
- logger.info(` - ${path.join(__dirname, "../../templates")}`);
206
- logger.info(` - ${path.join(__dirname, "../templates")}`);
207
- logger.info(` - ${path.join(process.cwd(), "templates")}`);
208
- logger.warn("\u26A0\uFE0F Using fallback scaffolding (empty structure)");
209
- fs.mkdirSync(projectPath, {
210
- recursive: true
211
- });
212
- fs.mkdirSync(path.join(projectPath, "apps"), {
213
- recursive: true
214
- });
215
- fs.mkdirSync(path.join(projectPath, "packages"), {
216
- recursive: true
217
- });
218
- } else {
219
- logger.info(`\u{1F4E6} Copying templates from: ${templatePath}`);
220
- fs.mkdirSync(projectPath, {
221
- recursive: true
222
- });
223
- fs.mkdirSync(path.join(projectPath, "apps"), {
224
- recursive: true
225
- });
226
- fs.mkdirSync(path.join(projectPath, "packages"), {
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
- const apiTemplatePath = path.join(templatePath, "nestjs-api");
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 packageJson = {
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
- "build": "pnpm exec turbo build",
262
- "dev": "pnpm exec turbo dev",
263
- "lint": "pnpm exec turbo lint",
264
- "format": 'prettier --write "**/*.{ts,tsx,md}"'
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
- "turbo": "^2.6.1",
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
- fs.writeFileSync(path.join(projectPath, "turbo.json"), JSON.stringify(turboJson, null, 2));
296
- const pnpmWorkspace = `packages:
297
- - 'apps/*'
298
- - 'packages/*'
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
- try {
305
- execSync("pnpm --version", {
306
- stdio: "ignore"
307
- });
308
- } catch {
309
- logger.info("Installing pnpm...");
310
- execSync("npm install -g pnpm", {
311
- stdio: "ignore"
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
- execSync("pnpm install", {
315
- cwd: projectPath,
316
- stdio: "inherit"
593
+ fs.mkdirSync(path.dirname(absolutePath), {
594
+ recursive: true
317
595
  });
318
- logger.success("\u2705 Dependencies installed");
319
- logger.info(pc.green(`
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(createProject, "createProject");
332
- program.parse();
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