profile-presets.ts
4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// 预设选项与浏览器安全的路径小工具。
// 注意:这些组件运行在浏览器,不能使用 node 的 `path`,这里用纯字符串处理
// Windows 风格路径(本项目服务端与前端同机,路径均为 Windows 格式)。
/** 技术栈 / 框架 预设(可自由补充,也可手填)。粒度越小越通用。 */
export const FRAMEWORK_PRESETS = [
'React 18',
'React 19',
'Vue 3',
'Next.js (App Router)',
'Next.js (Pages Router)',
'Nuxt 3',
'Svelte',
'SvelteKit',
'Angular',
'Remix',
'Astro',
'SolidJS',
'Qwik',
'其他',
];
/** 语言预设。 */
export const LANGUAGE_PRESETS = [
'TypeScript',
'JavaScript',
'TypeScript + JavaScript',
];
/** 样式策略预设。 */
export const STYLING_PRESETS = [
'Tailwind CSS',
'CSS Modules',
'styled-components',
'Emotion',
'Sass / SCSS',
'Less',
'原生 CSS(CSS Variables)',
'UnoCSS',
'Styled JSX',
'其他',
];
/** 组件库预设。 */
export const COMPONENT_LIBRARY_PRESETS = [
'Ant Design',
'Material UI (MUI)',
'Mantine',
'Chakra UI',
'shadcn/ui',
'Radix UI',
'Element Plus',
'Naive UI',
'Arco Design',
'Semi Design',
'NextUI',
'自研 / 内部组件库',
'无(原生元素)',
'其他',
];
/** 状态管理预设。 */
export const STATE_MANAGEMENT_PRESETS = [
'Redux Toolkit',
'Zustand',
'Jotai',
'Recoil',
'MobX',
'Pinia',
'Vuex',
'React Context',
'Signals',
'无(组件内状态)',
'其他',
];
/** 数据请求预设。 */
export const DATA_FETCHING_PRESETS = [
'React Query (TanStack Query)',
'SWR',
'Apollo Client',
'RTK Query',
'Axios',
'原生 fetch',
'Vue Query',
'其他',
];
/** 路由预设。 */
export const ROUTING_PRESETS = [
'React Router',
'Next.js 路由',
'Nuxt 路由',
'Vue Router',
'TanStack Router',
'Angular Router',
'文件路由(基于目录)',
'其他',
];
/* ----------------------- 技术栈预设(生成目标用) ----------------------- */
/** 一个可点选的技术栈组合(框架 + 样式 + 组件库)。 */
export interface StackPreset {
id: string;
label: string;
framework: string;
styling?: string;
componentLibrary?: string;
}
/**
* 工作台「生成目标 → 技术栈」的预设卡片。新增组合只需在此追加一项;
* 引擎侧通过 framework 字段(含 "vue" 走 Vue 策略,否则 React)决定生成策略。
*/
export const STACK_PRESETS: StackPreset[] = [
{ id: 'react-antd', label: 'React + Ant Design', framework: 'React 18', styling: 'CSS Modules', componentLibrary: 'Ant Design' },
{ id: 'react-tailwind', label: 'React + Tailwind', framework: 'React 18', styling: 'Tailwind CSS', componentLibrary: '无(原生元素)' },
{ id: 'react-shadcn', label: 'React + shadcn/ui', framework: 'React 18', styling: 'Tailwind CSS', componentLibrary: 'shadcn/ui' },
{ id: 'react-mui', label: 'React + MUI', framework: 'React 18', styling: 'Emotion', componentLibrary: 'Material UI (MUI)' },
{ id: 'vue-elementplus', label: 'Vue 3 + Element Plus', framework: 'Vue 3', styling: 'CSS', componentLibrary: 'Element Plus' },
{ id: 'vue-antdv', label: 'Vue 3 + Ant Design Vue', framework: 'Vue 3', styling: 'Less', componentLibrary: 'Ant Design Vue' },
];
/* ----------------------- 浏览器安全路径工具 ----------------------- */
function norm(p: string): string {
return p.replace(/\//g, '\\');
}
/** 拼接目录(base 末尾自动补分隔符)。 */
export function joinPath(base: string, name: string): string {
const a = norm(base).replace(/\\+$/, '');
const b = norm(name).replace(/^\\+/, '');
return `${a}\\${b}`;
}
/**
* 若 abs 位于 base 之内,返回相对 base 的路径(使用正斜杠,便于写入画像);
* 否则原样返回绝对路径。
*/
export function relativePath(base: string, abs: string): string {
if (!base) return abs;
const nb = norm(base).replace(/\\+$/, '').toLowerCase();
const na = norm(abs).toLowerCase();
if (na === nb) return '';
if (na.startsWith(nb + '\\') || na.startsWith(nb + '/')) {
return abs.slice(base.replace(/\\+$/, '').length + 1).replace(/\\/g, '/');
}
return abs;
}
/** 由相对/绝对 value 与相对基准反推弹窗起始目录(绝对)。 */
export function resolveStartDir(value: string, relativeTo?: string): string | undefined {
if (relativeTo) {
const v = value || '';
// 已是相对路径(不含盘符)则拼到基准上;绝对路径直接用
if (/^[a-zA-Z]:[\\/]/.test(v)) return v;
return v ? joinPath(relativeTo, v) : relativeTo;
}
return value || undefined; // 空 -> 顶层根
}