create-fullstack-scaffold 0.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 (530) hide show
  1. package/README.md +154 -0
  2. package/dist/cli/index.d.ts +2 -0
  3. package/dist/cli/index.js +439 -0
  4. package/dist/cli/index.js.map +1 -0
  5. package/package.json +171 -0
  6. package/template/.agents/skills/writing-hookify-rules/SKILL.md +408 -0
  7. package/template/.ai-context.md +368 -0
  8. package/template/.claude/hookify.block-dangerous-commands.local.md +41 -0
  9. package/template/.claude/hookify.check-api-types.local.md +111 -0
  10. package/template/.claude/hookify.check-duplicate-types.local.md +287 -0
  11. package/template/.claude/hookify.check-test-assertions.local.md +93 -0
  12. package/template/.claude/hookify.remind-add-tests.local.md +209 -0
  13. package/template/.claude/hookify.remind-db-migration.local.md +58 -0
  14. package/template/.claude/hookify.remind-run-tests.local.md +52 -0
  15. package/template/.claude/hookify.warn-any-type.local.md +203 -0
  16. package/template/.claude/hookify.warn-console-log.local.md +73 -0
  17. package/template/.claude/rules/00-project-config.md +147 -0
  18. package/template/.claude/rules/01-file-types.md +127 -0
  19. package/template/.claude/rules/02-git-workflow.md +167 -0
  20. package/template/.claude/rules/10-api-type-inference.md +555 -0
  21. package/template/.claude/rules/20-server-api.md +349 -0
  22. package/template/.claude/rules/21-server-entrypoint.md +257 -0
  23. package/template/.claude/rules/30-client-components.md +314 -0
  24. package/template/.claude/rules/31-client-services.md +768 -0
  25. package/template/.claude/rules/32-client-state-zustand.md +324 -0
  26. package/template/.claude/rules/33-client-app-entry.md +276 -0
  27. package/template/.claude/rules/34-client-admin-module.md +445 -0
  28. package/template/.claude/rules/35-cli-module.md +259 -0
  29. package/template/.claude/rules/40-admin-module.md +495 -0
  30. package/template/.claude/rules/40-shared-types.md +450 -0
  31. package/template/.claude/rules/50-websocket.md +245 -0
  32. package/template/.claude/rules/51-sse.md +372 -0
  33. package/template/.claude/rules/52-cloudflare-realtime.md +384 -0
  34. package/template/.claude/rules/60-testing-standards.md +245 -0
  35. package/template/.claude/rules/61-hono-testing.md +200 -0
  36. package/template/.claude/scripts/README.md +187 -0
  37. package/template/.claude/scripts/check-duplicate-types.ts +188 -0
  38. package/template/.claude/scripts/post-edit-check-incremental.sh +61 -0
  39. package/template/.claude/scripts/post-edit-check.sh +22 -0
  40. package/template/.claude/scripts/pre-tool-use-check.sh +86 -0
  41. package/template/.claude/scripts/test-pre-tool-use.sh +73 -0
  42. package/template/.claude/scripts/validate-git-changes.sh +38 -0
  43. package/template/.claude/settings.json +32 -0
  44. package/template/.claude/skills/writing-hookify-rules/SKILL.md +408 -0
  45. package/template/.dev-context-compact.md +54 -0
  46. package/template/.dev-context.md +621 -0
  47. package/template/.dev-guide.md +243 -0
  48. package/template/.env.example +60 -0
  49. package/template/.eslintrc.routes.json +39 -0
  50. package/template/.husky/_/husky.sh +27 -0
  51. package/template/.husky/commit-msg +4 -0
  52. package/template/.husky/post-commit +4 -0
  53. package/template/.husky/pre-commit +19 -0
  54. package/template/.husky/pre-push +12 -0
  55. package/template/.prettierignore +22 -0
  56. package/template/.prettierrc +8 -0
  57. package/template/.sessions/3/2026-03-26T05-41-09-154Z_03bb597f-3898-4a2e-8c08-5746bbe8d95e.jsonl +18 -0
  58. package/template/.sessions/3/2026-03-26T05-48-30-052Z_12de4774-9cb3-494c-9852-bd1e6b0003c3.jsonl +6 -0
  59. package/template/.vscode/extensions.json +8 -0
  60. package/template/.vscode/settings.json +4 -0
  61. package/template/.workspaces/3/hello.py +1 -0
  62. package/template/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/803c2e37182b913f8857edf6d8776515cef4af6d48fcb25913e457f4b14ffa97.sqlite +0 -0
  63. package/template/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/803c2e37182b913f8857edf6d8776515cef4af6d48fcb25913e457f4b14ffa97.sqlite-shm +0 -0
  64. package/template/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/803c2e37182b913f8857edf6d8776515cef4af6d48fcb25913e457f4b14ffa97.sqlite-wal +0 -0
  65. package/template/CLAUDE.md +296 -0
  66. package/template/DESIGN.md +260 -0
  67. package/template/DEV_CONTEXT_GUIDE.md +366 -0
  68. package/template/DEV_TOOLS_README.md +396 -0
  69. package/template/FRAMEWORK_HISTORY.md +34 -0
  70. package/template/PROJECT_SUMMARY.md +325 -0
  71. package/template/QUICKSTART.md +305 -0
  72. package/template/README.md +154 -0
  73. package/template/STRUCTURE.txt +81 -0
  74. package/template/admin.html +13 -0
  75. package/template/auth-inject.html +33 -0
  76. package/template/commitlint.config.js +12 -0
  77. package/template/docs/PERMISSION_ARCHITECTURE.md +279 -0
  78. package/template/docs/PERMISSION_EXAMPLES.md +230 -0
  79. package/template/docs/PERMISSION_SYSTEM.md +301 -0
  80. package/template/docs/SMART_TEST.md +171 -0
  81. package/template/docs/runtime-abstract.md +253 -0
  82. package/template/drizzle/0000_rainy_boomer.sql +101 -0
  83. package/template/drizzle/0001_add_todo_attachments.sql +12 -0
  84. package/template/drizzle/0002_chilly_magneto.sql +89 -0
  85. package/template/drizzle/meta/0000_snapshot.json +652 -0
  86. package/template/drizzle/meta/0001_snapshot.json +735 -0
  87. package/template/drizzle/meta/0002_snapshot.json +1198 -0
  88. package/template/drizzle/meta/_journal.json +27 -0
  89. package/template/drizzle.config.ts +13 -0
  90. package/template/eslint-rules/README-no-middleware-in-routes.md +154 -0
  91. package/template/eslint-rules/__tests__/enforce-valid-method.test.ts +251 -0
  92. package/template/eslint-rules/__tests__/layer-boundary.test.ts +102 -0
  93. package/template/eslint-rules/__tests__/module-boundary.test.ts +77 -0
  94. package/template/eslint-rules/__tests__/no-direct-zod-import-in-file-routes.test.ts +45 -0
  95. package/template/eslint-rules/__tests__/no-new-old-service-naming.test.ts +76 -0
  96. package/template/eslint-rules/e2e-test-location.js +153 -0
  97. package/template/eslint-rules/enforce-valid-method.js +217 -0
  98. package/template/eslint-rules/flat-routes-services.js +69 -0
  99. package/template/eslint-rules/framework-protect.js +186 -0
  100. package/template/eslint-rules/layer-boundary.js +164 -0
  101. package/template/eslint-rules/limit-type-complexity.js +130 -0
  102. package/template/eslint-rules/middleware-location.js +162 -0
  103. package/template/eslint-rules/module-boundary.js +125 -0
  104. package/template/eslint-rules/no-ambiguous-file-paths.js +64 -0
  105. package/template/eslint-rules/no-any-on-apiclient.js +173 -0
  106. package/template/eslint-rules/no-boolean-success.js +43 -0
  107. package/template/eslint-rules/no-deep-relative-imports.js +69 -0
  108. package/template/eslint-rules/no-direct-fetch.js +122 -0
  109. package/template/eslint-rules/no-direct-ws-sse.js +57 -0
  110. package/template/eslint-rules/no-direct-zod-import-in-file-routes.js +54 -0
  111. package/template/eslint-rules/no-disable-direct-fetch.js +57 -0
  112. package/template/eslint-rules/no-disable-type-safe-client.js +58 -0
  113. package/template/eslint-rules/no-inline-schema.js +220 -0
  114. package/template/eslint-rules/no-middleware-in-routes.js +81 -0
  115. package/template/eslint-rules/no-new-old-service-naming.js +123 -0
  116. package/template/eslint-rules/no-type-assertion-in-rpc.js +99 -0
  117. package/template/eslint-rules/no-type-assertion-on-shared-types.js +109 -0
  118. package/template/eslint-rules/no-util-functions-in-service.js +128 -0
  119. package/template/eslint-rules/prefer-shared-types.js +352 -0
  120. package/template/eslint-rules/protect-ws-sse-interface.js +66 -0
  121. package/template/eslint-rules/require-antd-generic-types.js +73 -0
  122. package/template/eslint-rules/require-file-openapi-props.js +114 -0
  123. package/template/eslint-rules/require-hono-chain-syntax.js +129 -0
  124. package/template/eslint-rules/require-nullable-for-optional.js +99 -0
  125. package/template/eslint-rules/require-response-helpers.js +140 -0
  126. package/template/eslint-rules/require-type-safe-test-client.js +106 -0
  127. package/template/eslint-rules/route-location.js +72 -0
  128. package/template/eslint.config.js +231 -0
  129. package/template/index.html +17 -0
  130. package/template/lint-scripts/DIRECTORY_RULES.md +335 -0
  131. package/template/lint-scripts/README.md +299 -0
  132. package/template/lint-scripts/TESTING.md +273 -0
  133. package/template/lint-scripts/ai-context-generator.ts +159 -0
  134. package/template/lint-scripts/check-framework-modify.sh +8 -0
  135. package/template/lint-scripts/check-menu-permissions.js +242 -0
  136. package/template/lint-scripts/check-refs.ts +165 -0
  137. package/template/lint-scripts/check-route-auth-complete.js +260 -0
  138. package/template/lint-scripts/check-route-auth.js +212 -0
  139. package/template/lint-scripts/check-route-permissions.js +210 -0
  140. package/template/lint-scripts/config/project.config.ts +358 -0
  141. package/template/lint-scripts/dev-context-analyzer.ts +707 -0
  142. package/template/lint-scripts/dev-guide-generator.ts +830 -0
  143. package/template/lint-scripts/dev-server.ts +58 -0
  144. package/template/lint-scripts/eslint-route-auth.js +158 -0
  145. package/template/lint-scripts/eslint-routes-permission.js +147 -0
  146. package/template/lint-scripts/fix-route-auth.js +245 -0
  147. package/template/lint-scripts/framework/check-modify.ts +152 -0
  148. package/template/lint-scripts/framework/hash-utils.ts +180 -0
  149. package/template/lint-scripts/framework/init-baseline.ts +84 -0
  150. package/template/lint-scripts/framework/update-baseline.ts +148 -0
  151. package/template/lint-scripts/post-commit-track.ts +66 -0
  152. package/template/lint-scripts/quick-test.sh +27 -0
  153. package/template/lint-scripts/smart-test.ts +268 -0
  154. package/template/lint-scripts/test-history.ts +360 -0
  155. package/template/lint-scripts/test-tracker.ts +350 -0
  156. package/template/lint-scripts/validate-all.ts +250 -0
  157. package/template/lint-scripts/validators/api-coverage.validator.ts +355 -0
  158. package/template/lint-scripts/validators/client-rpc.validator.ts +190 -0
  159. package/template/lint-scripts/validators/client-tests.validator.ts +155 -0
  160. package/template/lint-scripts/validators/console-log.validator.ts +122 -0
  161. package/template/lint-scripts/validators/directory-structure.validator.ts +181 -0
  162. package/template/lint-scripts/validators/imports.validator.ts +180 -0
  163. package/template/lint-scripts/validators/index.ts +271 -0
  164. package/template/lint-scripts/validators/md-refs.validator.ts +165 -0
  165. package/template/lint-scripts/validators/module-tests.validator.ts +112 -0
  166. package/template/lint-scripts/validators/sensitive.validator.ts +185 -0
  167. package/template/lint-scripts/validators/server-rpc.validator.ts +141 -0
  168. package/template/lint-scripts/validators/test-quality.validator.ts +257 -0
  169. package/template/lint-scripts/validators/todos.validator.ts +126 -0
  170. package/template/lint-scripts/watch-validator.ts +131 -0
  171. package/template/modules.config.ts +71 -0
  172. package/template/package-lock.json +14554 -0
  173. package/template/package.json +158 -0
  174. package/template/patches/@hono+zod-openapi+1.2.2.patch +67 -0
  175. package/template/patches/@hono+zod-validator+0.7.6.patch +13 -0
  176. package/template/patches/hono+4.12.16.patch +246 -0
  177. package/template/patches/typescript+5.8.3.patch +26 -0
  178. package/template/playwright.config.ts +60 -0
  179. package/template/pnpm-lock.yaml +7137 -0
  180. package/template/postcss.config.js +6 -0
  181. package/template/scripts/create-template.ts +1724 -0
  182. package/template/src/admin/App.tsx +59 -0
  183. package/template/src/admin/components/AccountSwitcher.tsx +104 -0
  184. package/template/src/admin/components/CaptchaModal.tsx +150 -0
  185. package/template/src/admin/components/NotificationDrawer.tsx +213 -0
  186. package/template/src/admin/components/PageHeader.tsx +45 -0
  187. package/template/src/admin/components/PermissionConfigEditor.tsx +237 -0
  188. package/template/src/admin/components/PermissionGuard.tsx +108 -0
  189. package/template/src/admin/components/PermissionTree.tsx +193 -0
  190. package/template/src/admin/components/ProtectedRoute.tsx +33 -0
  191. package/template/src/admin/components/StatsCard.tsx +44 -0
  192. package/template/src/admin/components/UserFormModal.tsx +67 -0
  193. package/template/src/admin/components/UserTable.tsx +72 -0
  194. package/template/src/admin/components/__tests__/PageHeader.test.tsx +48 -0
  195. package/template/src/admin/components/__tests__/PermissionConfigEditor.test.tsx +147 -0
  196. package/template/src/admin/components/__tests__/PermissionGuard.test.tsx +221 -0
  197. package/template/src/admin/components/__tests__/PermissionTree.test.tsx +187 -0
  198. package/template/src/admin/components/__tests__/ProtectedRoute.test.tsx +129 -0
  199. package/template/src/admin/components/__tests__/StatsCard.test.tsx +44 -0
  200. package/template/src/admin/components/__tests__/UserFormModal.test.tsx +125 -0
  201. package/template/src/admin/components/__tests__/UserTable.test.tsx +89 -0
  202. package/template/src/admin/components/index.ts +7 -0
  203. package/template/src/admin/hooks/__tests__/useAuditLogs.test.ts +109 -0
  204. package/template/src/admin/hooks/__tests__/usePermissions.test.tsx +327 -0
  205. package/template/src/admin/hooks/__tests__/usePermissionsBranches.test.ts +198 -0
  206. package/template/src/admin/hooks/__tests__/useRoles.test.ts +261 -0
  207. package/template/src/admin/hooks/useAdminNotifications.ts +156 -0
  208. package/template/src/admin/hooks/useAuditLogs.ts +44 -0
  209. package/template/src/admin/hooks/useConfig.ts +168 -0
  210. package/template/src/admin/hooks/usePermissions.ts +156 -0
  211. package/template/src/admin/hooks/useRoles.ts +120 -0
  212. package/template/src/admin/layouts/Header.tsx +93 -0
  213. package/template/src/admin/layouts/Layout.tsx +23 -0
  214. package/template/src/admin/layouts/Sidebar.tsx +120 -0
  215. package/template/src/admin/main.tsx +18 -0
  216. package/template/src/admin/pages/ContentPage.tsx +252 -0
  217. package/template/src/admin/pages/DashboardPage.tsx +141 -0
  218. package/template/src/admin/pages/DisputesPage.tsx +261 -0
  219. package/template/src/admin/pages/LoginPage.tsx +121 -0
  220. package/template/src/admin/pages/MediaTestPage.tsx +524 -0
  221. package/template/src/admin/pages/OrdersPage.tsx +302 -0
  222. package/template/src/admin/pages/PermissionsPage.tsx +95 -0
  223. package/template/src/admin/pages/RegisterPage.tsx +103 -0
  224. package/template/src/admin/pages/RolesPage.tsx +330 -0
  225. package/template/src/admin/pages/SettingsPage.tsx +73 -0
  226. package/template/src/admin/pages/SystemLogsPage.tsx +218 -0
  227. package/template/src/admin/pages/TestCaptchaPage.tsx +120 -0
  228. package/template/src/admin/pages/TicketsPage.tsx +292 -0
  229. package/template/src/admin/pages/UsersPage.tsx +282 -0
  230. package/template/src/admin/pages/__tests__/ContentPage.test.tsx +213 -0
  231. package/template/src/admin/pages/__tests__/DashboardPage.test.tsx +153 -0
  232. package/template/src/admin/pages/__tests__/DisputesPage.test.tsx +196 -0
  233. package/template/src/admin/pages/__tests__/LoginPage.test.tsx +112 -0
  234. package/template/src/admin/pages/__tests__/OrdersPage.test.tsx +217 -0
  235. package/template/src/admin/pages/__tests__/PermissionsPage.test.tsx +119 -0
  236. package/template/src/admin/pages/__tests__/RegisterPage.test.tsx +179 -0
  237. package/template/src/admin/pages/__tests__/RolesPage.test.tsx +256 -0
  238. package/template/src/admin/pages/__tests__/SettingsPage.test.tsx +66 -0
  239. package/template/src/admin/pages/__tests__/SystemLogsPage.test.tsx +125 -0
  240. package/template/src/admin/pages/__tests__/TicketsPage.test.tsx +202 -0
  241. package/template/src/admin/pages/__tests__/UsersPage.test.tsx +229 -0
  242. package/template/src/admin/services/README.md +263 -0
  243. package/template/src/admin/services/TESTING.md +323 -0
  244. package/template/src/admin/services/__tests__/skipLoading.test.ts +146 -0
  245. package/template/src/admin/services/apiClient.ts +66 -0
  246. package/template/src/admin/services/requestInterceptor.ts +127 -0
  247. package/template/src/admin/services/types.ts +5 -0
  248. package/template/src/admin/stores/__tests__/adminStore.test.ts +184 -0
  249. package/template/src/admin/stores/__tests__/adminStoreBranches.test.ts +148 -0
  250. package/template/src/admin/stores/__tests__/captchaStore.test.ts +75 -0
  251. package/template/src/admin/stores/__tests__/captchaStoreBranches.test.ts +37 -0
  252. package/template/src/admin/stores/__tests__/loadingStore.test.ts +68 -0
  253. package/template/src/admin/stores/adminStore.ts +88 -0
  254. package/template/src/admin/stores/captchaStore.ts +47 -0
  255. package/template/src/admin/stores/loadingStore.ts +27 -0
  256. package/template/src/cli/index.ts +22 -0
  257. package/template/src/cli/modules/config/index.ts +132 -0
  258. package/template/src/cli/modules/index.ts +12 -0
  259. package/template/src/cli/modules/notification/index.ts +86 -0
  260. package/template/src/cli/modules/todo/index.ts +60 -0
  261. package/template/src/cli/rpc/client.ts +23 -0
  262. package/template/src/cli/rpc/index.ts +1 -0
  263. package/template/src/cli/utils/api.ts +17 -0
  264. package/template/src/cli/utils/auto-command.ts +229 -0
  265. package/template/src/cli/utils/index.ts +8 -0
  266. package/template/src/cli/utils/logger.ts +79 -0
  267. package/template/src/client/App.tsx +24 -0
  268. package/template/src/client/Layout.tsx +27 -0
  269. package/template/src/client/components/AuthButton.tsx +41 -0
  270. package/template/src/client/components/ConnectionStatus.tsx +75 -0
  271. package/template/src/client/components/EmptyState.tsx +26 -0
  272. package/template/src/client/components/Footer.tsx +17 -0
  273. package/template/src/client/components/LoadingSpinner.tsx +26 -0
  274. package/template/src/client/components/MessageCard.tsx +61 -0
  275. package/template/src/client/components/Navigation.tsx +65 -0
  276. package/template/src/client/components/StatusBadge.tsx +50 -0
  277. package/template/src/client/components/__tests__/App.test.tsx +79 -0
  278. package/template/src/client/components/__tests__/AuthButton.test.tsx +119 -0
  279. package/template/src/client/components/__tests__/ConnectionStatus.test.tsx +188 -0
  280. package/template/src/client/components/__tests__/EmptyState.test.tsx +70 -0
  281. package/template/src/client/components/__tests__/Footer.test.tsx +22 -0
  282. package/template/src/client/components/__tests__/LoadingSpinner.test.tsx +75 -0
  283. package/template/src/client/components/__tests__/MessageCard.test.tsx +142 -0
  284. package/template/src/client/components/__tests__/Navigation.test.tsx +40 -0
  285. package/template/src/client/components/__tests__/StatusBadge.test.tsx +107 -0
  286. package/template/src/client/components/index.ts +6 -0
  287. package/template/src/client/index.css +27 -0
  288. package/template/src/client/main.tsx +25 -0
  289. package/template/src/client/pages/ContentDetailPage.tsx +142 -0
  290. package/template/src/client/pages/ContentListPage.tsx +169 -0
  291. package/template/src/client/pages/NotificationPage.tsx +288 -0
  292. package/template/src/client/pages/TodoPage.tsx +389 -0
  293. package/template/src/client/pages/WebSocketPage.tsx +239 -0
  294. package/template/src/client/pages/__tests__/ContentDetailPage.test.tsx +176 -0
  295. package/template/src/client/pages/__tests__/ContentListPage.test.tsx +202 -0
  296. package/template/src/client/pages/__tests__/NotificationPage.test.tsx +246 -0
  297. package/template/src/client/pages/__tests__/TodoPage.test.tsx +433 -0
  298. package/template/src/client/pages/__tests__/WebSocketPage.test.tsx +378 -0
  299. package/template/src/client/services/apiClient.ts +66 -0
  300. package/template/src/client/stores/__tests__/authStore.test.ts +139 -0
  301. package/template/src/client/stores/__tests__/chatWSStore.test.ts +416 -0
  302. package/template/src/client/stores/__tests__/notificationStore.test.ts +453 -0
  303. package/template/src/client/stores/__tests__/todoStore.test.ts +509 -0
  304. package/template/src/client/stores/authStore.ts +51 -0
  305. package/template/src/client/stores/chatWSStore.ts +122 -0
  306. package/template/src/client/stores/notificationStore.ts +199 -0
  307. package/template/src/client/stores/todoStore.ts +207 -0
  308. package/template/src/server/__tests__/integration/todos-api.test.ts +138 -0
  309. package/template/src/server/app.ts +105 -0
  310. package/template/src/server/config.ts +86 -0
  311. package/template/src/server/core/__tests__/realtime-core.test.ts +329 -0
  312. package/template/src/server/core/__tests__/realtime-scanner.test.ts +210 -0
  313. package/template/src/server/core/__tests__/runtime-node.test.ts +330 -0
  314. package/template/src/server/core/__tests__/runtime.test.ts +219 -0
  315. package/template/src/server/core/__tests__/typed-runtime.test.ts +178 -0
  316. package/template/src/server/core/durable-objects/RealtimeDO.ts +206 -0
  317. package/template/src/server/core/index.ts +83 -0
  318. package/template/src/server/core/module-loader.ts +281 -0
  319. package/template/src/server/core/realtime-core.ts +152 -0
  320. package/template/src/server/core/realtime-scanner.ts +99 -0
  321. package/template/src/server/core/runtime-cloudflare.ts +207 -0
  322. package/template/src/server/core/runtime-node.ts +170 -0
  323. package/template/src/server/core/runtime.ts +129 -0
  324. package/template/src/server/core/typed-runtime.ts +80 -0
  325. package/template/src/server/db/__tests__/driver.test.ts +203 -0
  326. package/template/src/server/db/config.ts +1 -0
  327. package/template/src/server/db/driver-cloudflare.ts +50 -0
  328. package/template/src/server/db/driver.ts +116 -0
  329. package/template/src/server/db/index.ts +3 -0
  330. package/template/src/server/db/init.ts +412 -0
  331. package/template/src/server/db/schema/api-endpoints.ts +23 -0
  332. package/template/src/server/db/schema/contents.ts +31 -0
  333. package/template/src/server/db/schema/disputes.ts +39 -0
  334. package/template/src/server/db/schema/index.ts +14 -0
  335. package/template/src/server/db/schema/notifications.ts +16 -0
  336. package/template/src/server/db/schema/orders.ts +30 -0
  337. package/template/src/server/db/schema/permission-audit-logs.ts +17 -0
  338. package/template/src/server/db/schema/permission-route-mappings.ts +22 -0
  339. package/template/src/server/db/schema/permissions.ts +17 -0
  340. package/template/src/server/db/schema/role-permissions.ts +22 -0
  341. package/template/src/server/db/schema/roles.ts +17 -0
  342. package/template/src/server/db/schema/tickets.ts +62 -0
  343. package/template/src/server/db/schema/todo-attachments.ts +22 -0
  344. package/template/src/server/db/schema/todos.ts +21 -0
  345. package/template/src/server/db/schema/user-roles.ts +17 -0
  346. package/template/src/server/db/seeds/index.ts +1 -0
  347. package/template/src/server/db/seeds/permission-data.ts +354 -0
  348. package/template/src/server/db/test-setup.ts +647 -0
  349. package/template/src/server/entries/cloudflare.ts +71 -0
  350. package/template/src/server/entries/node.ts +190 -0
  351. package/template/src/server/index.ts +62 -0
  352. package/template/src/server/middleware/__tests__/auth-simple.test.ts +147 -0
  353. package/template/src/server/middleware/__tests__/auth.test.ts +276 -0
  354. package/template/src/server/middleware/__tests__/captcha.test.ts +258 -0
  355. package/template/src/server/middleware/__tests__/error-handler.test.ts +364 -0
  356. package/template/src/server/middleware/__tests__/error-response-format.test.ts +80 -0
  357. package/template/src/server/middleware/__tests__/permission.test.ts +312 -0
  358. package/template/src/server/middleware/audit-log.ts +101 -0
  359. package/template/src/server/middleware/auth.ts +235 -0
  360. package/template/src/server/middleware/captcha.ts +166 -0
  361. package/template/src/server/middleware/cors.ts +30 -0
  362. package/template/src/server/middleware/error-handler.ts +135 -0
  363. package/template/src/server/middleware/index.ts +24 -0
  364. package/template/src/server/middleware/logger.ts +73 -0
  365. package/template/src/server/middleware/permission.ts +127 -0
  366. package/template/src/server/middleware/rate-limit.ts +69 -0
  367. package/template/src/server/middleware/realtime-env.ts +12 -0
  368. package/template/src/server/module-admin/__tests__/admin-routes.test.ts +360 -0
  369. package/template/src/server/module-admin/__tests__/admin-service.test.ts +222 -0
  370. package/template/src/server/module-admin/__tests__/audit-log-routes.test.ts +261 -0
  371. package/template/src/server/module-admin/__tests__/export-routes.test.ts +160 -0
  372. package/template/src/server/module-admin/__tests__/media-routes.test.ts +122 -0
  373. package/template/src/server/module-admin/module.ts +40 -0
  374. package/template/src/server/module-admin/routes/admin-notification-routes.ts +197 -0
  375. package/template/src/server/module-admin/routes/admin-routes.ts +20 -0
  376. package/template/src/server/module-admin/routes/auth-routes.ts +86 -0
  377. package/template/src/server/module-admin/routes/export-routes.ts +207 -0
  378. package/template/src/server/module-admin/routes/media-routes.ts +78 -0
  379. package/template/src/server/module-admin/routes/system-routes.ts +89 -0
  380. package/template/src/server/module-admin/routes/user-management-routes.ts +143 -0
  381. package/template/src/server/module-admin/services/admin-service.ts +268 -0
  382. package/template/src/server/module-captcha/__tests__/captcha-route.test.ts +35 -0
  383. package/template/src/server/module-captcha/__tests__/captcha-service.test.ts +53 -0
  384. package/template/src/server/module-captcha/module.ts +35 -0
  385. package/template/src/server/module-captcha/routes/captcha-routes.ts +68 -0
  386. package/template/src/server/module-captcha/services/captcha-service.ts +3 -0
  387. package/template/src/server/module-chat/__tests__/chat-routes.test.ts +39 -0
  388. package/template/src/server/module-chat/__tests__/chat-rpc.test.ts +185 -0
  389. package/template/src/server/module-chat/__tests__/chat-service.test.ts +64 -0
  390. package/template/src/server/module-chat/module.ts +27 -0
  391. package/template/src/server/module-chat/routes/chat-routes.ts +46 -0
  392. package/template/src/server/module-chat/services/chat-service.ts +38 -0
  393. package/template/src/server/module-content/__tests__/content-route.test.ts +40 -0
  394. package/template/src/server/module-content/__tests__/content-service.test.ts +107 -0
  395. package/template/src/server/module-content/module.ts +39 -0
  396. package/template/src/server/module-content/routes/content-routes.ts +182 -0
  397. package/template/src/server/module-content/routes/public-content-routes.ts +58 -0
  398. package/template/src/server/module-content/services/content-service.ts +224 -0
  399. package/template/src/server/module-dispute/__tests__/dispute-route.test.ts +43 -0
  400. package/template/src/server/module-dispute/__tests__/dispute-service.test.ts +135 -0
  401. package/template/src/server/module-dispute/module.ts +30 -0
  402. package/template/src/server/module-dispute/routes/dispute-routes.ts +153 -0
  403. package/template/src/server/module-dispute/services/dispute-service.ts +255 -0
  404. package/template/src/server/module-file/__tests__/file-routes.test.ts +284 -0
  405. package/template/src/server/module-file/__tests__/file-storage-service.test.ts +323 -0
  406. package/template/src/server/module-file/module.ts +28 -0
  407. package/template/src/server/module-file/routes/file-routes.ts +288 -0
  408. package/template/src/server/module-notifications/__tests__/notification-route-rpc.test.ts +375 -0
  409. package/template/src/server/module-notifications/__tests__/notification-service.test.ts +241 -0
  410. package/template/src/server/module-notifications/__tests__/sse-rpc.test.ts +289 -0
  411. package/template/src/server/module-notifications/module.ts +32 -0
  412. package/template/src/server/module-notifications/routes/notification-routes.ts +190 -0
  413. package/template/src/server/module-notifications/services/notification-service.ts +104 -0
  414. package/template/src/server/module-order/__tests__/order-route.test.ts +258 -0
  415. package/template/src/server/module-order/__tests__/order-service.test.ts +222 -0
  416. package/template/src/server/module-order/module.ts +30 -0
  417. package/template/src/server/module-order/routes/order-routes.ts +202 -0
  418. package/template/src/server/module-order/services/order-service.ts +268 -0
  419. package/template/src/server/module-permission/__tests__/permission-middleware.test.ts +90 -0
  420. package/template/src/server/module-permission/__tests__/permission-routes.test.ts +330 -0
  421. package/template/src/server/module-permission/__tests__/permission-service-impl.test.ts +388 -0
  422. package/template/src/server/module-permission/__tests__/permission-service.test.ts +190 -0
  423. package/template/src/server/module-permission/__tests__/role-routes.test.ts +215 -0
  424. package/template/src/server/module-permission/module.ts +68 -0
  425. package/template/src/server/module-permission/routes/audit-log-routes.ts +76 -0
  426. package/template/src/server/module-permission/routes/permission-routes.ts +184 -0
  427. package/template/src/server/module-permission/routes/role-routes.ts +263 -0
  428. package/template/src/server/module-permission/services/audit-log-service.ts +108 -0
  429. package/template/src/server/module-permission/services/permission-service-impl.ts +233 -0
  430. package/template/src/server/module-permission/services/permission-service.ts +256 -0
  431. package/template/src/server/module-permission/services/role-service.ts +122 -0
  432. package/template/src/server/module-ticket/__tests__/ticket-route.test.ts +173 -0
  433. package/template/src/server/module-ticket/__tests__/ticket-service.test.ts +201 -0
  434. package/template/src/server/module-ticket/module.ts +30 -0
  435. package/template/src/server/module-ticket/routes/ticket-routes.ts +210 -0
  436. package/template/src/server/module-ticket/services/ticket-service.ts +297 -0
  437. package/template/src/server/module-todos/__tests__/todo-service.test.ts +196 -0
  438. package/template/src/server/module-todos/__tests__/todos-file-upload.test.ts +439 -0
  439. package/template/src/server/module-todos/__tests__/todos-route-rpc.test.ts +575 -0
  440. package/template/src/server/module-todos/module.ts +30 -0
  441. package/template/src/server/module-todos/routes/todos-routes.ts +260 -0
  442. package/template/src/server/module-todos/services/todo-service.ts +202 -0
  443. package/template/src/server/route-registry.ts +47 -0
  444. package/template/src/server/test-utils/test-client.ts +66 -0
  445. package/template/src/server/test-utils/test-server.ts +131 -0
  446. package/template/src/server/types/bindings.ts +10 -0
  447. package/template/src/server/utils/__tests__/app-error.test.ts +374 -0
  448. package/template/src/server/utils/__tests__/auth.test.ts +76 -0
  449. package/template/src/server/utils/__tests__/captcha.test.ts +80 -0
  450. package/template/src/server/utils/__tests__/file-storage.test.ts +472 -0
  451. package/template/src/server/utils/__tests__/logger.test.ts +221 -0
  452. package/template/src/server/utils/__tests__/route-helpers.test.ts +264 -0
  453. package/template/src/server/utils/app-error.ts +355 -0
  454. package/template/src/server/utils/auth.ts +65 -0
  455. package/template/src/server/utils/captcha.ts +119 -0
  456. package/template/src/server/utils/date.ts +50 -0
  457. package/template/src/server/utils/env.ts +4 -0
  458. package/template/src/server/utils/file-storage.ts +462 -0
  459. package/template/src/server/utils/generate.ts +26 -0
  460. package/template/src/server/utils/id-helpers.ts +5 -0
  461. package/template/src/server/utils/logger.ts +139 -0
  462. package/template/src/server/utils/permission-utils.ts +6 -0
  463. package/template/src/server/utils/response.ts +40 -0
  464. package/template/src/server/utils/route-helpers.ts +200 -0
  465. package/template/src/server/utils/uuid.ts +8 -0
  466. package/template/src/server/utils/ws-helper.ts +30 -0
  467. package/template/src/shared/constants/index.ts +1 -0
  468. package/template/src/shared/constants/resource-types.ts +72 -0
  469. package/template/src/shared/core/__tests__/sse-client.test.ts +376 -0
  470. package/template/src/shared/core/__tests__/ws-client.test.ts +468 -0
  471. package/template/src/shared/core/api-request.ts +192 -0
  472. package/template/src/shared/core/api-schemas.ts +41 -0
  473. package/template/src/shared/core/index.ts +37 -0
  474. package/template/src/shared/core/module-manifest.ts +120 -0
  475. package/template/src/shared/core/protocol-types.ts +26 -0
  476. package/template/src/shared/core/sse-client.ts +185 -0
  477. package/template/src/shared/core/ws-client.ts +236 -0
  478. package/template/src/shared/hooks/index.ts +2 -0
  479. package/template/src/shared/hooks/useSSE.ts +57 -0
  480. package/template/src/shared/hooks/useWebSocket.ts +66 -0
  481. package/template/src/shared/index.ts +5 -0
  482. package/template/src/shared/modules/admin/index.ts +1 -0
  483. package/template/src/shared/modules/admin/schemas.ts +100 -0
  484. package/template/src/shared/modules/audit/index.ts +1 -0
  485. package/template/src/shared/modules/audit/schemas.ts +24 -0
  486. package/template/src/shared/modules/captcha/index.ts +1 -0
  487. package/template/src/shared/modules/captcha/schemas.ts +19 -0
  488. package/template/src/shared/modules/chat/index.ts +38 -0
  489. package/template/src/shared/modules/content/index.ts +1 -0
  490. package/template/src/shared/modules/content/schemas.ts +53 -0
  491. package/template/src/shared/modules/dispute/index.ts +1 -0
  492. package/template/src/shared/modules/dispute/schemas.ts +62 -0
  493. package/template/src/shared/modules/files/index.ts +11 -0
  494. package/template/src/shared/modules/files/schemas.ts +44 -0
  495. package/template/src/shared/modules/index.ts +70 -0
  496. package/template/src/shared/modules/notifications/index.ts +26 -0
  497. package/template/src/shared/modules/notifications/schemas.ts +73 -0
  498. package/template/src/shared/modules/order/index.ts +1 -0
  499. package/template/src/shared/modules/order/schemas.ts +63 -0
  500. package/template/src/shared/modules/permission/index.ts +42 -0
  501. package/template/src/shared/modules/permission/permission-dependencies.ts +50 -0
  502. package/template/src/shared/modules/permission/permissions.ts +275 -0
  503. package/template/src/shared/modules/permission/schemas.ts +92 -0
  504. package/template/src/shared/modules/permission/types.ts +23 -0
  505. package/template/src/shared/modules/role/index.ts +1 -0
  506. package/template/src/shared/modules/role/schemas.ts +46 -0
  507. package/template/src/shared/modules/ticket/index.ts +1 -0
  508. package/template/src/shared/modules/ticket/schemas.ts +77 -0
  509. package/template/src/shared/modules/todos/index.ts +20 -0
  510. package/template/src/shared/modules/todos/schemas.ts +65 -0
  511. package/template/src/shared/schemas/index.ts +79 -0
  512. package/template/src/types/global.d.ts +14 -0
  513. package/template/src/vite-env.d.ts +21 -0
  514. package/template/tailwind.config.js +11 -0
  515. package/template/tests/e2e/admin-crud.spec.ts +81 -0
  516. package/template/tests/e2e/case-o1.spec.ts +108 -0
  517. package/template/tests/e2e/global-setup.ts +73 -0
  518. package/template/tests/e2e/global-teardown.ts +28 -0
  519. package/template/tests/e2e/notification.spec.ts +458 -0
  520. package/template/tests/e2e/todo.spec.ts +623 -0
  521. package/template/tests/e2e/websocket.spec.ts +254 -0
  522. package/template/tsconfig.json +35 -0
  523. package/template/tsup.config.ts +95 -0
  524. package/template/vite-plugins.ts +113 -0
  525. package/template/vite.config.ts +96 -0
  526. package/template/vitest.config.ts +53 -0
  527. package/template/vitest.integration.config.ts +24 -0
  528. package/template/vitest.integration.setup.ts +22 -0
  529. package/template/vitest.setup.ts +74 -0
  530. package/template/wrangler.toml +33 -0
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { readFileSync, existsSync, writeFileSync } from 'fs'
4
+ import { join } from 'path'
5
+ import { execSync } from 'child_process'
6
+
7
+ const PROJECT_ROOT = process.cwd()
8
+
9
+ function generateAIContext(): string {
10
+ const lines: string[] = [
11
+ '# é”¹ē›®äøŠäø‹ę–‡ļ¼ˆē”ØäŗŽ AI ä¼ščÆļ¼‰',
12
+ '',
13
+ '## 锹目俔息',
14
+ '',
15
+ `- **ē±»åž‹**: React + Hono å…Øę ˆåŗ”ē”Ø`,
16
+ `- **ęŠ€ęœÆę ˆ**: React, TypeScript, Hono, Drizzle ORM, Zustand`,
17
+ `- **ęž¶ęž„**: ęØ”å—åŒ–ęž¶ęž„ļ¼Œå‰åŽē«Æåˆ†ē¦»`,
18
+ '',
19
+ '## ē›®å½•ē»“ęž„',
20
+ '',
21
+ '```',
22
+ 'src/',
23
+ 'ā”œā”€ā”€ client/ # React å‰ē«Æ',
24
+ '│ ā”œā”€ā”€ components/ # UI 组件',
25
+ '│ ā”œā”€ā”€ stores/ # Zustand ēŠ¶ę€ē®”ē†',
26
+ '│ └── services/ # API 客户端',
27
+ 'ā”œā”€ā”€ server/ # Hono åŽē«Æ',
28
+ '│ ā”œā”€ā”€ module-*/ # äøšåŠ”ęØ”å—',
29
+ '│ │ ā”œā”€ā”€ routes/ # API č·Æē”±',
30
+ '│ │ ā”œā”€ā”€ services/# äøšåŠ”é€»č¾‘',
31
+ '│ │ └── __tests__/# 测试',
32
+ '│ ā”œā”€ā”€ middleware/ # äø­é—“ä»¶',
33
+ '│ └── db/schema/ # ę•°ę®åŗ“č”Ø',
34
+ '└── shared/ # å…±äŗ«ē±»åž‹',
35
+ ' ā”œā”€ā”€ core/ # ę”†ęž¶å±‚ļ¼ˆäøåÆäæ®ę”¹ļ¼‰',
36
+ ' └── modules/ # äøšåŠ”å±‚ Schema',
37
+ '```',
38
+ '',
39
+ ]
40
+
41
+ const compactContextPath = join(PROJECT_ROOT, '.dev-context-compact.md')
42
+ if (existsSync(compactContextPath)) {
43
+ const compactContext = readFileSync(compactContextPath, 'utf-8')
44
+ lines.push('## é”¹ē›®ē»Ÿč®”')
45
+ lines.push('')
46
+ lines.push(compactContext.split('\n').slice(4).join('\n'))
47
+ }
48
+
49
+ const guidePath = join(PROJECT_ROOT, '.dev-guide.md')
50
+ if (existsSync(guidePath)) {
51
+ const guide = readFileSync(guidePath, 'utf-8')
52
+ lines.push('')
53
+ lines.push('## å¼€å‘ęŒ‡å¼•')
54
+ lines.push('')
55
+ lines.push(guide)
56
+ }
57
+
58
+ lines.push('')
59
+ lines.push('## å¼€å‘č§„čŒƒ')
60
+ lines.push('')
61
+ lines.push('### å…³é”®č§„åˆ™')
62
+ lines.push('')
63
+ lines.push('1. **äø­é—“ä»¶ä½ē½®**: äø­é—“ä»¶åæ…é”»åœØ `src/server/middleware/` 目录')
64
+ lines.push('2. **č·Æē”±ä½ē½®**: č·Æē”±åæ…é”»åœØ `src/server/module-*/routes/` 目录')
65
+ lines.push('3. **中闓件应用**: äø­é—“ä»¶åŖčƒ½åœØ `app.ts` äø­åŗ”ē”Øļ¼Œäøčƒ½åœØč·Æē”±ę–‡ä»¶äø­åŗ”ē”Ø')
66
+ lines.push('4. **ē±»åž‹å®‰å…Ø**: 使用 Zod Schema å®šä¹‰ē±»åž‹ļ¼Œē¦ę­¢ä½æē”Ø `any`')
67
+ lines.push('5. **åˆ†å±‚ęž¶ęž„**: č·Æē”±č°ƒē”ØęœåŠ”ļ¼ŒęœåŠ”å¤„ē†äøšåŠ”é€»č¾‘')
68
+ lines.push('6. **巄具函数**: å·„å…·å‡½ę•°ę”¾åœØ `utils/` ē›®å½•ļ¼Œäøč¦ę”¾åœØ service äø­')
69
+ lines.push('')
70
+ lines.push('### API å¼€å‘ęµēØ‹')
71
+ lines.push('')
72
+ lines.push('```')
73
+ lines.push('1. 定义 Schema (src/shared/modules/{feature}/schemas.ts)')
74
+ lines.push('2. åˆ›å»ŗę•°ę®åŗ“č”Ø (src/server/db/schema/{feature}.ts)')
75
+ lines.push('3. å®žēŽ°ęœåŠ”å±‚ (src/server/module-{feature}/services/{feature}-service.ts)')
76
+ lines.push('4. å®šä¹‰č·Æē”± (src/server/module-{feature}/routes/{feature}-routes.ts)')
77
+ lines.push('5. ę³Øå†Œč·Æē”± (src/server/app.ts)')
78
+ lines.push('6. 编写测试 (src/server/module-{feature}/__tests__/)')
79
+ lines.push('```')
80
+ lines.push('')
81
+ lines.push('### å‰ē«Æå¼€å‘ęµēØ‹')
82
+ lines.push('')
83
+ lines.push('```')
84
+ lines.push('1. åˆ›å»ŗ API 客户端 (src/client/services/apiClient.ts)')
85
+ lines.push('2. åˆ›å»ŗēŠ¶ę€ē®”ē† (src/client/stores/{feature}Store.ts)')
86
+ lines.push('3. åˆ›å»ŗē»„ä»¶ (src/client/components/{feature}/)')
87
+ lines.push('4. åˆ›å»ŗé”µé¢ (src/client/pages/{feature}Page.tsx)')
88
+ lines.push('```')
89
+ lines.push('')
90
+ lines.push('## 常用命令')
91
+ lines.push('')
92
+ lines.push('```bash')
93
+ lines.push('npm run dev # åÆåŠØå¼€å‘ęœåŠ”å™Ø')
94
+ lines.push('npm test # čæč”Œęµ‹čÆ•')
95
+ lines.push('npm run typecheck # ē±»åž‹ę£€ęŸ„')
96
+ lines.push('npm run lint # ä»£ē ę£€ęŸ„')
97
+ lines.push('npm run db:generate # ē”Ÿęˆę•°ę®åŗ“čæē§»')
98
+ lines.push('npm run db:migrate # ę‰§č”Œę•°ę®åŗ“čæē§»')
99
+ lines.push('```')
100
+ lines.push('')
101
+
102
+ return lines.join('\n')
103
+ }
104
+
105
+ function copyToClipboard(text: string): void {
106
+ try {
107
+ const platform = process.platform
108
+
109
+ if (platform === 'darwin') {
110
+ execSync('pbcopy', { input: text })
111
+ } else if (platform === 'linux') {
112
+ execSync('xclip -selection clipboard', { input: text })
113
+ } else if (platform === 'win32') {
114
+ execSync('clip', { input: text })
115
+ } else {
116
+ console.log('āš ļø äøę”ÆęŒēš„ę“ä½œē³»ē»Ÿļ¼Œę— ę³•č‡ŖåŠØå¤åˆ¶åˆ°å‰Ŗč““ęæ')
117
+ console.log('čÆ·ę‰‹åŠØå¤åˆ¶ä»„äø‹å†…å®¹ļ¼š\n')
118
+ console.log(text)
119
+ return
120
+ }
121
+
122
+ console.log('āœ… äøŠäø‹ę–‡å·²å¤åˆ¶åˆ°å‰Ŗč““ęæļ¼')
123
+ console.log('šŸ’” ēŽ°åœØåÆä»„ē›“ęŽ„ē²˜č““åˆ° AI ä¼ščÆäø­\n')
124
+ } catch (error) {
125
+ console.log('āš ļø ę— ę³•å¤åˆ¶åˆ°å‰Ŗč““ęæļ¼ŒčÆ·ę‰‹åŠØå¤åˆ¶ä»„äø‹å†…å®¹ļ¼š\n')
126
+ console.log(text)
127
+ }
128
+ }
129
+
130
+ function main(): void {
131
+ const args = process.argv.slice(2)
132
+ const shouldCopy = !args.includes('--no-copy')
133
+
134
+ console.log('šŸ” ē”Ÿęˆ AI ä¼ščÆäøŠäø‹ę–‡...\n')
135
+
136
+ const context = generateAIContext()
137
+
138
+ const outputPath = join(PROJECT_ROOT, '.ai-context.md')
139
+ writeFileSync(outputPath, context, 'utf-8')
140
+ console.log(`āœ… äøŠäø‹ę–‡å·²äæå­˜åˆ°: ${outputPath}\n`)
141
+
142
+ if (shouldCopy) {
143
+ copyToClipboard(context)
144
+ } else {
145
+ console.log(context)
146
+ }
147
+
148
+ console.log('šŸ“– 使用方法:')
149
+ console.log(' 1. 在 AI ä¼ščÆäø­ē²˜č““äøŠäø‹ę–‡')
150
+ console.log(' 2. ęčæ°ä½ ēš„å¼€å‘éœ€ę±‚')
151
+ console.log(' 3. AI ä¼šę ¹ę®äøŠäø‹ę–‡ęä¾›ē²¾å‡†ēš„åø®åŠ©\n')
152
+
153
+ console.log('šŸ’” ē¤ŗä¾‹åÆ¹čÆ:')
154
+ console.log(' ē”Øęˆ·: ęˆ‘ę­£åœØå¼€å‘äø€äøŖ React + Hono é”¹ē›®ć€‚čæ™ę˜Æé”¹ē›®äøŠäø‹ę–‡ļ¼š')
155
+ console.log(' [ē²˜č““äøŠäø‹ę–‡]')
156
+ console.log(' ęˆ‘éœ€č¦å¼€å‘äø€äøŖč®¢å•ē®”ē†ęŽ„å£ļ¼ŒčÆ·åø®ęˆ‘å®žēŽ°ć€‚\n')
157
+ }
158
+
159
+ main()
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+
3
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
5
+
6
+ cd "$PROJECT_ROOT"
7
+
8
+ npx tsx lint-scripts/framework/check-modify.ts
@@ -0,0 +1,242 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * čœå•ęƒé™ę£€ęŸ„č„šęœ¬
5
+ *
6
+ * čæ™äøŖč„šęœ¬ę£€ęŸ„čœå•é…ē½®ļ¼Œē”®äæļ¼š
7
+ * 1. ęÆäøŖčœå•é”¹éƒ½ęœ‰ęƒé™é…ē½®
8
+ * 2. ęƒé™é…ē½®äøäøŗē©ŗę•°ē»„ļ¼ˆé™¤éžę˜Æå…¬å¼€čœå•ļ¼‰
9
+ * 3. ęƒé™é…ē½®ēš„ęƒé™éƒ½å­˜åœØ
10
+ */
11
+
12
+ import fs from 'fs'
13
+ import path from 'path'
14
+ import { fileURLToPath } from 'url'
15
+
16
+ const __filename = fileURLToPath(import.meta.url)
17
+ const __dirname = path.dirname(__filename)
18
+
19
+ const PUBLIC_MENUS = ['/dashboard']
20
+
21
+ const REQUIRED_PERMISSIONS = {
22
+ '/users': ['user:view'],
23
+ '/orders': ['order:view'],
24
+ '/tickets': ['ticket:view'],
25
+ '/disputes': ['ticket:view'],
26
+ '/content': ['content:view'],
27
+ '/system/settings': ['system:settings'],
28
+ '/system/logs': ['system:logs'],
29
+ '/system/monitor': ['system:monitor'],
30
+ '/system/permissions': ['role:view'],
31
+ '/system/roles': ['role:view'],
32
+ }
33
+
34
+ function extractMenuConfig(content) {
35
+ const menuConfigMatch = content.match(/const MENU_CONFIG:\s*MenuItem\[\]\s*=\s*\[/)
36
+ if (!menuConfigMatch) {
37
+ return null
38
+ }
39
+
40
+ let braceCount = 0
41
+ let inString = false
42
+ let stringChar = null
43
+ let config = ''
44
+ let i = menuConfigMatch.index + menuConfigMatch[0].length - 1
45
+
46
+ while (i < content.length) {
47
+ const char = content[i]
48
+
49
+ if (!inString && (char === '"' || char === "'" || char === '`')) {
50
+ inString = true
51
+ stringChar = char
52
+ } else if (inString && char === stringChar && content[i - 1] !== '\\') {
53
+ inString = false
54
+ stringChar = null
55
+ }
56
+
57
+ if (!inString) {
58
+ if (char === '[') {
59
+ braceCount++
60
+ } else if (char === ']') {
61
+ braceCount--
62
+ if (braceCount === 0) {
63
+ config += char
64
+ break
65
+ }
66
+ }
67
+ }
68
+
69
+ config += char
70
+ i++
71
+ }
72
+
73
+ return config
74
+ }
75
+
76
+ function parseMenuItems(configStr) {
77
+ const items = []
78
+ const itemRegex = /{\s*path:\s*['"`]([^'"`]+)['"`]/g
79
+ let match
80
+
81
+ while ((match = itemRegex.exec(configStr)) !== null) {
82
+ const path = match[1]
83
+ const itemStart = match.index
84
+ const itemEnd = findItemEnd(configStr, itemStart)
85
+ const itemStr = configStr.substring(itemStart, itemEnd)
86
+
87
+ const permissionsMatch = itemStr.match(/permissions:\s*\[([^\]]*)\]/)
88
+ const permissions = permissionsMatch
89
+ ? permissionsMatch[1]
90
+ .split(',')
91
+ .map(p => p.trim().replace(/['"`]/g, ''))
92
+ .filter(p => p && p !== 'Permission.')
93
+ : []
94
+
95
+ const labelMatch = itemStr.match(/label:\s*['"`]([^'"`]+)['"`]/)
96
+ const label = labelMatch ? labelMatch[1] : ''
97
+
98
+ items.push({ path, label, permissions, itemStr })
99
+ }
100
+
101
+ return items
102
+ }
103
+
104
+ function findItemEnd(str, start) {
105
+ let braceCount = 0
106
+ let inString = false
107
+ let stringChar = null
108
+
109
+ for (let i = start; i < str.length; i++) {
110
+ const char = str[i]
111
+
112
+ if (!inString && (char === '"' || char === "'" || char === '`')) {
113
+ inString = true
114
+ stringChar = char
115
+ } else if (inString && char === stringChar && str[i - 1] !== '\\') {
116
+ inString = false
117
+ stringChar = null
118
+ }
119
+
120
+ if (!inString) {
121
+ if (char === '{') {
122
+ braceCount++
123
+ } else if (char === '}') {
124
+ braceCount--
125
+ if (braceCount === 0) {
126
+ return i + 1
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ return str.length
133
+ }
134
+
135
+ function checkMenuPermissions(filePath) {
136
+ const content = fs.readFileSync(filePath, 'utf-8')
137
+ const errors = []
138
+ const warnings = []
139
+
140
+ const menuConfig = extractMenuConfig(content)
141
+ if (!menuConfig) {
142
+ warnings.push({
143
+ file: filePath,
144
+ message: 'ęœŖę‰¾åˆ° MENU_CONFIG é…ē½®',
145
+ })
146
+ return { errors, warnings }
147
+ }
148
+
149
+ const items = parseMenuItems(menuConfig)
150
+
151
+ for (const item of items) {
152
+ const isPublic = PUBLIC_MENUS.includes(item.path)
153
+
154
+ if (isPublic) {
155
+ if (item.permissions.length > 0) {
156
+ warnings.push({
157
+ file: filePath,
158
+ path: item.path,
159
+ label: item.label,
160
+ message: `å…¬å¼€čœå• "${item.label}" (${item.path}) äøåŗ”čÆ„ęœ‰ęƒé™é…ē½®`,
161
+ })
162
+ }
163
+ } else {
164
+ if (item.permissions.length === 0) {
165
+ const requiredPerms = REQUIRED_PERMISSIONS[item.path] || []
166
+ errors.push({
167
+ file: filePath,
168
+ path: item.path,
169
+ label: item.label,
170
+ message: `čœå• "${item.label}" (${item.path}) ē¼ŗå°‘ęƒé™é…ē½®ć€‚å»ŗč®®ę·»åŠ : [${requiredPerms.map(p => `Permission.${p.toUpperCase().replace(/:/g, '_')}`).join(', ')}]`,
171
+ })
172
+ } else {
173
+ const requiredPerms = REQUIRED_PERMISSIONS[item.path] || []
174
+ const missingPerms = requiredPerms.filter(p => {
175
+ const permCode = `Permission.${p.toUpperCase().replace(/:/g, '_')}`
176
+ return !item.permissions.some(perm => perm.includes(p.toUpperCase().replace(/:/g, '_')))
177
+ })
178
+
179
+ if (missingPerms.length > 0) {
180
+ warnings.push({
181
+ file: filePath,
182
+ path: item.path,
183
+ label: item.label,
184
+ message: `čœå• "${item.label}" (${item.path}) ē¼ŗå°‘ęŽØčęƒé™: [${missingPerms.map(p => `Permission.${p.toUpperCase().replace(/:/g, '_')}`).join(', ')}]`,
185
+ })
186
+ }
187
+ }
188
+ }
189
+ }
190
+
191
+ return { errors, warnings }
192
+ }
193
+
194
+ function main() {
195
+ const srcDir = path.join(__dirname, '..', 'src')
196
+ const menuConfigFile = path.join(
197
+ srcDir,
198
+ 'server',
199
+ 'module-permission',
200
+ 'services',
201
+ 'permission-service.ts'
202
+ )
203
+
204
+ console.log('šŸ” ę£€ęŸ„čœå•ęƒé™é…ē½®...\n')
205
+
206
+ if (!fs.existsSync(menuConfigFile)) {
207
+ console.log('āŒ ęœŖę‰¾åˆ°čœå•é…ē½®ę–‡ä»¶:', menuConfigFile)
208
+ process.exit(1)
209
+ }
210
+
211
+ const { errors, warnings } = checkMenuPermissions(menuConfigFile)
212
+
213
+ if (errors.length > 0 || warnings.length > 0) {
214
+ console.log(`šŸ“„ ${path.relative(path.join(__dirname, '..'), menuConfigFile)}\n`)
215
+
216
+ for (const error of errors) {
217
+ console.log(` āŒ ${error.message}`)
218
+ }
219
+
220
+ for (const warning of warnings) {
221
+ console.log(` āš ļø ${warning.message}`)
222
+ }
223
+
224
+ console.log()
225
+ }
226
+
227
+ console.log('==================================================')
228
+ console.log(`šŸ“Š ę£€ęŸ„ē»“ęžœ:`)
229
+ console.log(` āŒ 错误: ${errors.length}`)
230
+ console.log(` āš ļø č­¦å‘Š: ${warnings.length}`)
231
+ console.log('==================================================\n')
232
+
233
+ if (errors.length > 0) {
234
+ console.log('āŒ å‘ēŽ°čœå•ęƒé™é…ē½®é”™čÆÆļ¼čÆ·äæ®å¤åŽå†ęäŗ¤ä»£ē ć€‚')
235
+ process.exit(1)
236
+ } else {
237
+ console.log('āœ… ę‰€ęœ‰čœå•ęƒé™é…ē½®ę­£ē”®ļ¼')
238
+ process.exit(0)
239
+ }
240
+ }
241
+
242
+ main()
@@ -0,0 +1,165 @@
1
+ /**
2
+ * ę£€ęŸ„é”¹ē›®äø­ę‰€ęœ‰ md ę–‡ä»¶ēš„å¼•ē”Øč·Æå¾„ę˜Æå¦ę­£ē”®
3
+ *
4
+ * 运蔌: npm run check:refs
5
+ */
6
+
7
+ import fs from 'fs'
8
+ import path from 'path'
9
+ import { fileURLToPath } from 'url'
10
+ import { glob } from 'glob'
11
+
12
+ const __filename = fileURLToPath(import.meta.url)
13
+ const __dirname = path.dirname(__filename)
14
+ const templateDir = path.resolve(__dirname, '..')
15
+
16
+ const MD_FILE_PATTERN = /\.md$/
17
+ const MD_LINK_PATTERN = /\[([^\]]+)\]\(([^)]+)\)/g
18
+
19
+ const GLOB_CHARS = ['*', '?', '[', '{']
20
+ const PLACEHOLDER_PATTERN = /\{[a-zA-Z_]+\}/
21
+ const EXCLUDED_PROTOCOLS = ['http://', 'https://', 'mailto:']
22
+
23
+ interface CheckResult {
24
+ file: string
25
+ line: number
26
+ ref: string
27
+ resolvedPath: string
28
+ exists: boolean
29
+ isGlob: boolean
30
+ }
31
+
32
+ function isGlobPattern(p: string): boolean {
33
+ return GLOB_CHARS.some(char => p.includes(char))
34
+ }
35
+
36
+ function isPlaceholder(p: string): boolean {
37
+ return PLACEHOLDER_PATTERN.test(p)
38
+ }
39
+
40
+ function shouldExclude(refPath: string): boolean {
41
+ if (refPath.startsWith('#')) return true
42
+ if (EXCLUDED_PROTOCOLS.some(proto => refPath.startsWith(proto))) return true
43
+ return false
44
+ }
45
+
46
+ function findAllMdFiles(dir: string): string[] {
47
+ const results: string[] = []
48
+ const entries = fs.readdirSync(dir, { withFileTypes: true })
49
+
50
+ for (const entry of entries) {
51
+ const fullPath = path.join(dir, entry.name)
52
+ if (entry.isDirectory()) {
53
+ if (!['node_modules', 'dist', '.git', '.pi'].includes(entry.name)) {
54
+ results.push(...findAllMdFiles(fullPath))
55
+ }
56
+ } else if (entry.isFile() && MD_FILE_PATTERN.test(entry.name)) {
57
+ results.push(fullPath)
58
+ }
59
+ }
60
+
61
+ return results
62
+ }
63
+
64
+ function checkGlobPattern(baseDir: string, pattern: string): boolean {
65
+ try {
66
+ const fullPattern = path.isAbsolute(pattern) ? pattern : path.join(baseDir, pattern)
67
+ const matchedFiles = glob.sync(fullPattern, {
68
+ cwd: templateDir,
69
+ nodir: true,
70
+ })
71
+ return matchedFiles.length > 0
72
+ } catch {
73
+ return false
74
+ }
75
+ }
76
+
77
+ function checkFileExists(baseDir: string, refPath: string): boolean {
78
+ const fullPath = path.isAbsolute(refPath) ? refPath : path.join(baseDir, refPath)
79
+ return fs.existsSync(fullPath)
80
+ }
81
+
82
+ function checkReferences(): CheckResult[] {
83
+ const results: CheckResult[] = []
84
+ const mdFiles = findAllMdFiles(templateDir)
85
+
86
+ for (const filePath of mdFiles) {
87
+ const content = fs.readFileSync(filePath, 'utf-8')
88
+ const lines = content.split('\n')
89
+ const fileDir = path.dirname(filePath)
90
+ const relativePath = path.relative(templateDir, filePath)
91
+
92
+ lines.forEach((line, index) => {
93
+ const lineNum = index + 1
94
+
95
+ MD_LINK_PATTERN.lastIndex = 0
96
+ let match
97
+ while ((match = MD_LINK_PATTERN.exec(line)) !== null) {
98
+ const linkText = match[1]
99
+ const refPath = match[2]
100
+
101
+ if (shouldExclude(refPath)) continue
102
+ if (isPlaceholder(refPath)) continue
103
+
104
+ const resolvedPath = refPath.startsWith('/')
105
+ ? path.join(templateDir, refPath.slice(1))
106
+ : path.resolve(fileDir, refPath)
107
+
108
+ const resolvedRelative = path.relative(templateDir, resolvedPath)
109
+
110
+ if (isGlobPattern(refPath)) {
111
+ const exists = checkGlobPattern(refPath.startsWith('/') ? templateDir : fileDir, refPath)
112
+ results.push({
113
+ file: relativePath,
114
+ line: lineNum,
115
+ ref: refPath,
116
+ resolvedPath: resolvedRelative,
117
+ exists,
118
+ isGlob: true,
119
+ })
120
+ } else {
121
+ const exists = checkFileExists(fileDir, refPath)
122
+ results.push({
123
+ file: relativePath,
124
+ line: lineNum,
125
+ ref: refPath,
126
+ resolvedPath: resolvedRelative,
127
+ exists,
128
+ isGlob: false,
129
+ })
130
+ }
131
+ }
132
+ })
133
+ }
134
+
135
+ return results
136
+ }
137
+
138
+ function main(): void {
139
+ const results = checkReferences()
140
+ const broken = results.filter(r => !r.exists)
141
+
142
+ if (broken.length > 0) {
143
+ console.log(`\nāŒ Broken references (${broken.length}):\n`)
144
+ const grouped = new Map<string, CheckResult[]>()
145
+ for (const r of broken) {
146
+ const key = `${r.file}`
147
+ if (!grouped.has(key)) grouped.set(key, [])
148
+ grouped.get(key)!.push(r)
149
+ }
150
+ for (const [file, refs] of Array.from(grouped.entries())) {
151
+ console.log(` šŸ“„ ${file}`)
152
+ for (const r of refs) {
153
+ if (r.isGlob) {
154
+ console.log(` L${r.line}: ${r.ref} (NO MATCHES)`)
155
+ } else {
156
+ console.log(` L${r.line}: ${r.ref} -> ${r.resolvedPath} (NOT FOUND)`)
157
+ }
158
+ }
159
+ }
160
+ console.log()
161
+ process.exit(1)
162
+ }
163
+ }
164
+
165
+ main()