yyx-agent-kit 0.0.0-stage → 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.
- package/README.md +152 -3
- package/agents/chief.md +64 -0
- package/agents/qa.md +30 -0
- package/cli/bin/yyx-new.mjs +155 -0
- package/package.json +33 -4
- package/skills/flows/archive/SKILL.md +56 -0
- package/skills/flows/prd/SKILL.md +71 -0
- package/skills/flows/product-pipeline/SKILL.md +73 -0
- package/skills/flows/qa-regression/SKILL.md +58 -0
- package/skills/flows/tech-design/SKILL.md +75 -0
- package/skills/standards/nestjs/SKILL.md +29 -0
- package/skills/standards/next/SKILL.md +39 -0
- package/skills/standards/react/SKILL.md +25 -0
- package/skills/standards/workspace/SKILL.md +127 -0
- package/skills/tools/tooling/SKILL.md +39 -0
- package/templates/base/.opencode/agents/.synced.json +4 -0
- package/templates/base/.opencode/agents/chief.md +64 -0
- package/templates/base/.opencode/agents/qa.md +30 -0
- package/templates/base/.opencode/opencode.json +5 -0
- package/templates/base/AGENTS.md +51 -0
- package/templates/base/README.md +85 -0
- package/templates/base/apps/admin/index.html +12 -0
- package/templates/base/apps/admin/package.json +27 -0
- package/templates/base/apps/admin/src/App.tsx +10 -0
- package/templates/base/apps/admin/src/index.css +1 -0
- package/templates/base/apps/admin/src/main.tsx +10 -0
- package/templates/base/apps/admin/tsconfig.json +9 -0
- package/templates/base/apps/admin/vite.config.ts +15 -0
- package/templates/base/apps/client/index.html +12 -0
- package/templates/base/apps/client/package.json +27 -0
- package/templates/base/apps/client/src/App.tsx +41 -0
- package/templates/base/apps/client/src/index.css +1 -0
- package/templates/base/apps/client/src/main.tsx +10 -0
- package/templates/base/apps/client/tsconfig.json +9 -0
- package/templates/base/apps/client/vite.config.ts +15 -0
- package/templates/base/apps/portal/README.md +27 -0
- package/templates/base/apps/portal/next-env.d.ts +6 -0
- package/templates/base/apps/portal/next.config.ts +19 -0
- package/templates/base/apps/portal/package.json +26 -0
- package/templates/base/apps/portal/postcss.config.mjs +5 -0
- package/templates/base/apps/portal/src/app/README.md +19 -0
- package/templates/base/apps/portal/src/app/globals.css +1 -0
- package/templates/base/apps/portal/src/app/layout.tsx +17 -0
- package/templates/base/apps/portal/src/app/page.tsx +12 -0
- package/templates/base/apps/portal/tsconfig.json +33 -0
- package/templates/base/apps/server/package.json +22 -0
- package/templates/base/apps/server/src/app.controller.ts +15 -0
- package/templates/base/apps/server/src/app.module.ts +11 -0
- package/templates/base/apps/server/src/app.service.ts +8 -0
- package/templates/base/apps/server/src/main.ts +15 -0
- package/templates/base/apps/server/src/todos.controller.ts +15 -0
- package/templates/base/apps/server/src/todos.service.ts +18 -0
- package/templates/base/apps/server/tsconfig.json +16 -0
- package/templates/base/docs/.gitkeep +0 -0
- package/templates/base/mise.toml +2 -0
- package/templates/base/package.json +17 -0
- package/templates/base/packages/README.md +18 -0
- package/templates/base/packages/api/config.ts +26 -0
- package/templates/base/packages/api/package.json +19 -0
- package/templates/base/packages/api/src/README.md +26 -0
- package/templates/base/packages/api/src/client.ts +51 -0
- package/templates/base/packages/api/src/index.ts +2 -0
- package/templates/base/packages/api/src/types.ts +10 -0
- package/templates/base/packages/api/tsconfig.json +7 -0
- package/templates/base/packages/shared/package.json +15 -0
- package/templates/base/packages/shared/src/README.md +21 -0
- package/templates/base/packages/shared/src/index.ts +37 -0
- package/templates/base/packages/shared/tsconfig.json +4 -0
- package/templates/base/pnpm-lock.yaml +3144 -0
- package/templates/base/pnpm-workspace.yaml +6 -0
- package/templates/base/tsconfig.base.json +19 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@starter/admin",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"typecheck": "tsc --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@starter/api": "workspace:*",
|
|
14
|
+
"@starter/shared": "workspace:*",
|
|
15
|
+
"react": "^19.1.0",
|
|
16
|
+
"react-dom": "^19.1.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@tailwindcss/vite": "^4.1.0",
|
|
20
|
+
"@types/react": "^19.1.0",
|
|
21
|
+
"@types/react-dom": "^19.1.0",
|
|
22
|
+
"@vitejs/plugin-react": "^4.4.0",
|
|
23
|
+
"tailwindcss": "^4.1.0",
|
|
24
|
+
"typescript": "^5.8.0",
|
|
25
|
+
"vite": "^6.3.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { APP_NAME } from "@starter/shared";
|
|
2
|
+
|
|
3
|
+
export const App = () => {
|
|
4
|
+
return (
|
|
5
|
+
<main className="min-h-screen bg-slate-50 p-8">
|
|
6
|
+
<h1 className="text-2xl font-semibold text-slate-900">{APP_NAME} 管理端</h1>
|
|
7
|
+
<p className="mt-2 text-slate-600">流水线模板项目</p>
|
|
8
|
+
</main>
|
|
9
|
+
);
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import react from "@vitejs/plugin-react";
|
|
3
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [react(), tailwindcss()],
|
|
7
|
+
server: {
|
|
8
|
+
// 47xxx 段,避开 5173 等框架默认端口
|
|
9
|
+
port: 47174,
|
|
10
|
+
strictPort: true,
|
|
11
|
+
proxy: {
|
|
12
|
+
"/api": "http://localhost:47100",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>starter</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@starter/client",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"typecheck": "tsc --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@starter/api": "workspace:*",
|
|
14
|
+
"@starter/shared": "workspace:*",
|
|
15
|
+
"react": "^19.1.0",
|
|
16
|
+
"react-dom": "^19.1.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@tailwindcss/vite": "^4.1.0",
|
|
20
|
+
"@types/react": "^19.1.0",
|
|
21
|
+
"@types/react-dom": "^19.1.0",
|
|
22
|
+
"@vitejs/plugin-react": "^4.4.0",
|
|
23
|
+
"tailwindcss": "^4.1.0",
|
|
24
|
+
"typescript": "^5.8.0",
|
|
25
|
+
"vite": "^6.3.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { createApiClient } from "@starter/api";
|
|
3
|
+
import { APP_NAME, TODO_STATUS, formatDateTime, type Todo } from "@starter/shared";
|
|
4
|
+
|
|
5
|
+
const api = createApiClient();
|
|
6
|
+
|
|
7
|
+
export const App = () => {
|
|
8
|
+
const [todos, setTodos] = useState<Todo[]>([]);
|
|
9
|
+
const [error, setError] = useState("");
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
api
|
|
13
|
+
.todos()
|
|
14
|
+
.then(setTodos)
|
|
15
|
+
.catch((reason: unknown) => {
|
|
16
|
+
setError(reason instanceof Error ? reason.message : "加载失败");
|
|
17
|
+
});
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<main className="min-h-screen bg-slate-50 p-8">
|
|
22
|
+
<h1 className="text-2xl font-semibold text-slate-900">{APP_NAME} 客户端</h1>
|
|
23
|
+
|
|
24
|
+
{error ? <p className="mt-4 text-red-600">{error}</p> : null}
|
|
25
|
+
|
|
26
|
+
{todos.length === 0 && !error ? <p className="mt-4 text-slate-600">暂无待办</p> : null}
|
|
27
|
+
|
|
28
|
+
<ul className="mt-4 space-y-2">
|
|
29
|
+
{todos.map((todo) => (
|
|
30
|
+
<li key={todo.id} className="rounded border border-slate-200 bg-white p-3">
|
|
31
|
+
<span className="text-slate-900">{todo.title}</span>
|
|
32
|
+
<span className="ml-2 text-sm text-slate-500">
|
|
33
|
+
{todo.status === TODO_STATUS.done ? "已完成" : "待办"}
|
|
34
|
+
</span>
|
|
35
|
+
<span className="ml-2 text-xs text-slate-400">{formatDateTime(todo.createdAt)}</span>
|
|
36
|
+
</li>
|
|
37
|
+
))}
|
|
38
|
+
</ul>
|
|
39
|
+
</main>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import react from "@vitejs/plugin-react";
|
|
3
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [react(), tailwindcss()],
|
|
7
|
+
server: {
|
|
8
|
+
// 47xxx 段,避开 5173 等框架默认端口
|
|
9
|
+
port: 47173,
|
|
10
|
+
strictPort: true,
|
|
11
|
+
proxy: {
|
|
12
|
+
"/api": "http://localhost:47100",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# portal
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
|
|
5
|
+
面向**未登录访客**的公开门户站点。SEO 是首要约束,默认用服务端渲染 / 静态生成。
|
|
6
|
+
|
|
7
|
+
## 技术栈
|
|
8
|
+
|
|
9
|
+
Next.js 16(App Router)+ React 19 + Tailwind 4,端口 **47175**。
|
|
10
|
+
|
|
11
|
+
## 文件索引
|
|
12
|
+
|
|
13
|
+
| 文件 | 作用 |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `next.config.ts` | 转译 workspace 包、`/api` 反向代理 |
|
|
16
|
+
| `postcss.config.mjs` | Tailwind 4 的 PostCSS 插件 |
|
|
17
|
+
| `src/app/layout.tsx` | 根布局与 metadata |
|
|
18
|
+
| `src/app/page.tsx` | 首页 |
|
|
19
|
+
| `src/app/globals.css` | Tailwind 入口 |
|
|
20
|
+
|
|
21
|
+
## 注意事项
|
|
22
|
+
|
|
23
|
+
- 这是唯一需要 SEO 的应用:内容页优先 server component,**不要一律加 `"use client"`**。
|
|
24
|
+
- 数据获取优先在服务端完成;只有交互部分才下沉成 client component。
|
|
25
|
+
- `/api` 由 `next.config.ts` 的 rewrites 代理到后端,代码里不写后端域名。
|
|
26
|
+
- `packages/*` 是 TS 源码,已在 `transpilePackages` 里声明,新增共享包要同步加进去。
|
|
27
|
+
- `.next/` 是构建产物,已在 `.gitignore` 中,不要提交。
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="next" />
|
|
2
|
+
/// <reference types="next/image-types/global" />
|
|
3
|
+
/// <reference path="./.next/types/routes.d.ts" />
|
|
4
|
+
|
|
5
|
+
// NOTE: This file should not be edited
|
|
6
|
+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NextConfig } from "next";
|
|
2
|
+
|
|
3
|
+
const apiOrigin = process.env.API_ORIGIN ?? "http://localhost:47100";
|
|
4
|
+
|
|
5
|
+
const nextConfig: NextConfig = {
|
|
6
|
+
// packages 以 TS 源码形式被消费,需要 Next 转译
|
|
7
|
+
transpilePackages: ["@starter/shared", "@starter/api"],
|
|
8
|
+
async rewrites() {
|
|
9
|
+
// 与 client / admin 一致:前端统一走 /api,不写死后端域名
|
|
10
|
+
return [
|
|
11
|
+
{
|
|
12
|
+
source: "/api/:path*",
|
|
13
|
+
destination: `${apiOrigin}/api/:path*`,
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default nextConfig;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@starter/portal",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "next dev -p 47175",
|
|
7
|
+
"build": "next build",
|
|
8
|
+
"start": "next start -p 47175",
|
|
9
|
+
"typecheck": "tsc --noEmit"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@starter/api": "workspace:*",
|
|
13
|
+
"@starter/shared": "workspace:*",
|
|
14
|
+
"next": "^15.0.0",
|
|
15
|
+
"react": "^19.1.0",
|
|
16
|
+
"react-dom": "^19.1.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@tailwindcss/postcss": "^4.1.0",
|
|
20
|
+
"@types/node": "^22.0.0",
|
|
21
|
+
"@types/react": "^19.1.0",
|
|
22
|
+
"@types/react-dom": "^19.1.0",
|
|
23
|
+
"tailwindcss": "^4.1.0",
|
|
24
|
+
"typescript": "^5.8.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# app
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
|
|
5
|
+
Next.js App Router 目录,文件系统即路由。
|
|
6
|
+
|
|
7
|
+
## 文件索引
|
|
8
|
+
|
|
9
|
+
| 文件 | 作用 |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| `layout.tsx` | 根布局,挂全局样式与 metadata |
|
|
12
|
+
| `page.tsx` | 首页(`/`) |
|
|
13
|
+
| `globals.css` | Tailwind 入口 |
|
|
14
|
+
|
|
15
|
+
## 注意事项
|
|
16
|
+
|
|
17
|
+
- 默认是 server component;需要 `useState` / `useEffect` / 事件时才加 `"use client"`,并且尽量下沉到叶子组件。
|
|
18
|
+
- 新增路由用 `<段名>/page.tsx`,不要把所有逻辑堆在首页。
|
|
19
|
+
- 服务端组件里不要直接用 `window`、`localStorage`。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Metadata } from "next";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { APP_NAME } from "@starter/shared";
|
|
4
|
+
import "./globals.css";
|
|
5
|
+
|
|
6
|
+
export const metadata: Metadata = {
|
|
7
|
+
title: APP_NAME,
|
|
8
|
+
description: "面向外部访客的公开门户站点",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
12
|
+
return (
|
|
13
|
+
<html lang="zh-CN">
|
|
14
|
+
<body>{children}</body>
|
|
15
|
+
</html>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { APP_NAME, formatDateTime } from "@starter/shared";
|
|
2
|
+
|
|
3
|
+
// 门户面向未登录访客,内容以展示为主;后续接入接口时优先用服务端组件 + 缓存策略
|
|
4
|
+
export default function HomePage() {
|
|
5
|
+
return (
|
|
6
|
+
<main className="min-h-screen bg-slate-50 p-8">
|
|
7
|
+
<h1 className="text-2xl font-semibold text-slate-900">{APP_NAME} 门户</h1>
|
|
8
|
+
<p className="mt-2 text-slate-600">面向外部访客的公开站点。</p>
|
|
9
|
+
<p className="mt-6 text-sm text-slate-400">构建时间:{formatDateTime(new Date())}</p>
|
|
10
|
+
</main>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"lib": [
|
|
5
|
+
"ES2022",
|
|
6
|
+
"DOM",
|
|
7
|
+
"DOM.Iterable"
|
|
8
|
+
],
|
|
9
|
+
"jsx": "preserve",
|
|
10
|
+
"incremental": true,
|
|
11
|
+
"plugins": [
|
|
12
|
+
{
|
|
13
|
+
"name": "next"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"paths": {
|
|
17
|
+
"@/*": [
|
|
18
|
+
"./src/*"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
"allowJs": true,
|
|
22
|
+
"resolveJsonModule": true
|
|
23
|
+
},
|
|
24
|
+
"include": [
|
|
25
|
+
"next-env.d.ts",
|
|
26
|
+
"**/*.ts",
|
|
27
|
+
"**/*.tsx",
|
|
28
|
+
".next/types/**/*.ts"
|
|
29
|
+
],
|
|
30
|
+
"exclude": [
|
|
31
|
+
"node_modules"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@starter/server",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "tsc -w",
|
|
7
|
+
"build": "tsc -p tsconfig.json",
|
|
8
|
+
"start": "node dist/apps/server/src/main.js",
|
|
9
|
+
"typecheck": "tsc --noEmit"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@nestjs/common": "^11.0.0",
|
|
13
|
+
"@nestjs/core": "^11.0.0",
|
|
14
|
+
"@nestjs/platform-express": "^11.0.0",
|
|
15
|
+
"reflect-metadata": "^0.2.2",
|
|
16
|
+
"rxjs": "^7.8.1"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^22.0.0",
|
|
20
|
+
"typescript": "^5.8.0"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Controller, Get } from "@nestjs/common";
|
|
2
|
+
import { AppService } from "./app.service";
|
|
3
|
+
import { API_ROUTES } from "../../../packages/shared/src/index";
|
|
4
|
+
|
|
5
|
+
const HEALTH_PATH = API_ROUTES.health.replace(/^\//, "");
|
|
6
|
+
|
|
7
|
+
@Controller()
|
|
8
|
+
export class AppController {
|
|
9
|
+
constructor(private readonly appService: AppService) {}
|
|
10
|
+
|
|
11
|
+
@Get(HEALTH_PATH)
|
|
12
|
+
getHealth() {
|
|
13
|
+
return this.appService.getHealth();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Module } from "@nestjs/common";
|
|
2
|
+
import { AppController } from "./app.controller";
|
|
3
|
+
import { AppService } from "./app.service";
|
|
4
|
+
import { TodosController } from "./todos.controller";
|
|
5
|
+
import { TodosService } from "./todos.service";
|
|
6
|
+
|
|
7
|
+
@Module({
|
|
8
|
+
controllers: [AppController, TodosController],
|
|
9
|
+
providers: [AppService, TodosService],
|
|
10
|
+
})
|
|
11
|
+
export class AppModule {}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { NestFactory } from "@nestjs/core";
|
|
3
|
+
import { AppModule } from "./app.module";
|
|
4
|
+
import { API_PREFIX } from "../../../packages/shared/src/index";
|
|
5
|
+
|
|
6
|
+
// 本地固定 47100;部署环境可由 PORT 覆盖(生产前端同源部署,不走 Vite 代理)
|
|
7
|
+
const port = Number(process.env.PORT ?? 47100);
|
|
8
|
+
|
|
9
|
+
const bootstrap = async () => {
|
|
10
|
+
const app = await NestFactory.create(AppModule);
|
|
11
|
+
app.setGlobalPrefix(API_PREFIX.replace(/^\//, ""));
|
|
12
|
+
await app.listen(port);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
bootstrap();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Controller, Get } from "@nestjs/common";
|
|
2
|
+
import { TodosService } from "./todos.service";
|
|
3
|
+
import { API_ROUTES } from "../../../packages/shared/src/index";
|
|
4
|
+
|
|
5
|
+
const TODOS_PATH = API_ROUTES.todos.replace(/^\//, "");
|
|
6
|
+
|
|
7
|
+
@Controller(TODOS_PATH)
|
|
8
|
+
export class TodosController {
|
|
9
|
+
constructor(private readonly todosService: TodosService) {}
|
|
10
|
+
|
|
11
|
+
@Get()
|
|
12
|
+
findAll() {
|
|
13
|
+
return this.todosService.findAll();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Injectable } from "@nestjs/common";
|
|
2
|
+
import { TODO_STATUS, type Todo } from "../../../packages/shared/src/index";
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class TodosService {
|
|
6
|
+
private readonly todos: Todo[] = [
|
|
7
|
+
{
|
|
8
|
+
id: "1",
|
|
9
|
+
title: "验证交付流水线",
|
|
10
|
+
status: TODO_STATUS.pending,
|
|
11
|
+
createdAt: new Date().toISOString(),
|
|
12
|
+
},
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
findAll(): Todo[] {
|
|
16
|
+
return this.todos;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"rootDir": "../..",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"emitDecoratorMetadata": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"sourceMap": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*.ts", "../../packages/shared/src/**/*.ts"]
|
|
16
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "starter",
|
|
3
|
+
"private": true,
|
|
4
|
+
"packageManager": "pnpm@11.9.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev:client": "pnpm --filter @starter/client dev",
|
|
7
|
+
"dev:admin": "pnpm --filter @starter/admin dev",
|
|
8
|
+
"dev:portal": "pnpm --filter @starter/portal dev",
|
|
9
|
+
"dev:server": "pnpm --filter @starter/server dev",
|
|
10
|
+
"build": "pnpm -r --workspace-concurrency=1 build && pnpm typecheck",
|
|
11
|
+
"typecheck": "pnpm -r --workspace-concurrency=1 typecheck",
|
|
12
|
+
"lint": "oxlint apps packages --ignore-pattern \"**/next-env.d.ts\""
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"oxlint": "^1.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# packages
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
|
|
5
|
+
跨应用共享代码。`apps/*` 只放端上专属的东西(页面、路由、状态),凡是两个及以上应用要用的,都下沉到这里。
|
|
6
|
+
|
|
7
|
+
## 目录
|
|
8
|
+
|
|
9
|
+
| 目录 | 作用 | 形态 |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `shared/` | 常量、工具函数、类型 | TS 源码,Vite 直接消费,无构建产物 |
|
|
12
|
+
| `api/` | 接口层:类型、SDK、错误处理 | 同上,手写装配在 `config.ts` |
|
|
13
|
+
|
|
14
|
+
## 注意事项
|
|
15
|
+
|
|
16
|
+
- 两个包都以 TS 源码形式被消费,`exports` 是白名单:新增子路径必须同时改 `package.json` 的 `exports`,否则引用方解析不到。
|
|
17
|
+
- 不引入宿主环境依赖(`react`、`fetch`、`window`),否则小程序 / App 端无法复用。
|
|
18
|
+
- 每个包的 `src/` 都要有 README,新增目录同样要补。
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 客户端装配(手写文件,**不在 `src/` 内**)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么不放 src/:接入 OpenAPI 生成后,`src/` 会被整目录重建,手写文件会被一起删掉。
|
|
5
|
+
*
|
|
6
|
+
* 职责收敛在本文件:
|
|
7
|
+
* - `baseUrl` 固定 `/api`,开发期由 Vite 代理,生产同源部署,前端不写死后端域名。
|
|
8
|
+
* - token 注入与 401 通知通过回调交给调用方,本包不认识任何 store 或路由。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { createApiClient, type ApiClientOptions } from "./src/client";
|
|
12
|
+
|
|
13
|
+
export interface ConfigureApiClientOptions {
|
|
14
|
+
/** 取当前 access token;返回 null 表示未登录 */
|
|
15
|
+
getToken?: () => string | null;
|
|
16
|
+
/** 收到 401 时回调:清会话并跳登录。登录接口自身不触发 */
|
|
17
|
+
onUnauthorized?: () => void;
|
|
18
|
+
/** 非 Web 端注入自己的请求器 */
|
|
19
|
+
fetcher?: ApiClientOptions["fetcher"];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const configureApiClient = (options: ConfigureApiClientOptions = {}) =>
|
|
23
|
+
createApiClient({
|
|
24
|
+
baseUrl: "/api",
|
|
25
|
+
...options,
|
|
26
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@starter/api",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts",
|
|
8
|
+
"./config": "./config.ts"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"typecheck": "tsc --noEmit"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@starter/shared": "workspace:*"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"typescript": "^5.8.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# api
|
|
2
|
+
|
|
3
|
+
## 职责
|
|
4
|
+
|
|
5
|
+
接口层唯一入口:请求类型、SDK、错误处理都在这里收敛。各端业务代码**不得**自己写 fetch 或拼 URL。
|
|
6
|
+
|
|
7
|
+
路由路径来自 `@starter/shared` 的 `API_ROUTES`,本包不自己写字符串。
|
|
8
|
+
|
|
9
|
+
`package.json` 的 `exports` 是白名单,新增子路径必须同时改 `exports`。
|
|
10
|
+
|
|
11
|
+
## 文件索引
|
|
12
|
+
|
|
13
|
+
| 文件 | 作用 |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `config.ts` | 手写:装配客户端(token 注入、401 回调、baseUrl) |
|
|
16
|
+
| `src/client.ts` | 请求封装,支持注入 `fetcher` 适配非 Web 端 |
|
|
17
|
+
| `src/types.ts` | 传输层类型(Result 包装、健康检查) |
|
|
18
|
+
| `src/index.ts` | 包入口 |
|
|
19
|
+
| `src/README.md` | 本文件 |
|
|
20
|
+
|
|
21
|
+
## 注意事项
|
|
22
|
+
|
|
23
|
+
- `baseUrl` 默认 `/api`,开发期由 Vite 代理到后端;**不要写死后端域名**。
|
|
24
|
+
- 401 只负责通知调用方,清会话和跳登录由各端自己实现,传输层不感知路由。
|
|
25
|
+
- 当前是手写实现。接入 OpenAPI 生成后,生成物放 `src/`(整个目录会被重建),手写装配留在 `config.ts`,不要混进 `src/`。
|
|
26
|
+
- 小程序 / App 端没有标准 `fetch`,通过 `fetcher` 注入各自的请求器,不要改 `client.ts` 里写死实现。
|