217 lines
6.7 KiB
JavaScript
217 lines
6.7 KiB
JavaScript
// 二级菜单 - 项目类型
|
||
export const projectTypes = [
|
||
{ name: "前端", desc: "React/Vue项目" },
|
||
{ name: "后端", desc: "Node.js服务端" },
|
||
{ name: "全栈", desc: "前后端一体化" },
|
||
];
|
||
|
||
// 框架选项
|
||
export const frameworkOptions = {
|
||
前端: [
|
||
{ value: "vue", label: "Vue(Vite + Vue)" },
|
||
{ value: "react", label: "React(Vite + React)" },
|
||
],
|
||
后端: [
|
||
{ value: "bun", label: "Bun(Bun运行时)" },
|
||
{ value: "node", label: "Node.js(Node运行时)" },
|
||
],
|
||
全栈: [
|
||
{ value: "nextjs", label: "Next.js(React全栈框架)" },
|
||
{ value: "nuxt", label: "Nuxt(Vue全栈框架)" },
|
||
],
|
||
};
|
||
|
||
const bunComponents = {
|
||
框架: [
|
||
{ value: "normal", label: "原生" },
|
||
{ value: "elysia", label: "Elysia(官方亲儿子)" },
|
||
{ value: "hono", label: "Hono(轻量级)" },
|
||
]
|
||
};
|
||
|
||
const nodeComponents = {
|
||
框架: [
|
||
{ value: "nestjs", label: "NestJS(企业级框架)" },
|
||
{ value: "express", label: "Express(Express Generator)" },
|
||
{ value: "koa", label: "Koa(Koa Generator)" },
|
||
{ value: "egg", label: "Egg(阿里Egg.js)" },
|
||
{ value: "midway", label: "Midway(阿里Midway)" },
|
||
{ value: "fastify", label: "Fastify(高性能框架)" },
|
||
{ value: "adonisjs", label: "AdonisJS(全功能MVC)" },
|
||
]
|
||
};
|
||
//后端公共框架
|
||
const backendCommonComponents = {
|
||
数据库: [
|
||
{ value: "none", label: "不需要数据库" },
|
||
{ value: "mongoose", label: "MongoDB + Mongoose" },
|
||
{ value: "prisma", label: "Prisma(支持 MySQL / PostgreSQL / SQLite)" },
|
||
{ value: "typeorm", label: "TypeORM(支持 MySQL / PostgreSQL 等)" },
|
||
]
|
||
};
|
||
|
||
|
||
|
||
// 组件选项 - 按框架分类
|
||
const reactComponents = {
|
||
路由: [
|
||
{ value: "none", label: "不需要路由" },
|
||
{ value: "react-router", label: "React Router" },
|
||
{ value: "tanstack-router", label: "TanStack Router" },
|
||
],
|
||
状态管理: [
|
||
{ value: "none", label: "不需要状态管理" },
|
||
{ value: "zustand", label: "Zustand(轻量级推荐)" },
|
||
{ value: "redux", label: "Redux Toolkit" },
|
||
{ value: "jotai", label: "Jotai(原子化)" },
|
||
{ value: "mobx", label: "MobX" },
|
||
],
|
||
UI组件库: [
|
||
{ value: "none", label: "不需要UI库" },
|
||
{ value: "antd", label: "Ant Design" },
|
||
{ value: "arco", label: "Arco Design" },
|
||
{ value: "shadcn", label: "shadcn/ui" },
|
||
{ value: "mui", label: "Material UI" },
|
||
],
|
||
表单验证: [
|
||
{ value: "none", label: "不需要表单验证" },
|
||
{ value: "react-hook-form", label: "React Hook Form" },
|
||
{ value: "formik", label: "Formik" },
|
||
{ value: "zod", label: "Zod" },
|
||
],
|
||
工具库: [
|
||
{ value: "ahooks", label: "ahooks(React Hooks库)" },
|
||
{ value: "lodash", label: "Lodash" },
|
||
{ value: "dayjs", label: "Day.js" },
|
||
{ value: "iconify", label: "Iconify图标" },
|
||
],
|
||
国际化: [
|
||
{ value: "none", label: "不需要国际化" },
|
||
{ value: "i18next", label: "i18next" },
|
||
],
|
||
};
|
||
|
||
const vueComponents = {
|
||
路由: [
|
||
{ value: "none", label: "不需要路由" },
|
||
{ value: "vue-router", label: "Vue Router" },
|
||
],
|
||
状态管理: [
|
||
{ value: "none", label: "不需要状态管理" },
|
||
{ value: "pinia", label: "Pinia(官方推荐)" },
|
||
],
|
||
UI组件库: [
|
||
{ value: "none", label: "不需要UI库" },
|
||
{ value: "element-plus", label: "Element Plus" },
|
||
{ value: "naive-ui", label: "Naive UI" },
|
||
{ value: "arco-vue", label: "Arco Design Vue" },
|
||
{ value: "ant-design-vue", label: "Ant Design Vue" },
|
||
],
|
||
表单验证: [
|
||
{ value: "none", label: "不需要表单验证" },
|
||
{ value: "vee-validate", label: "VeeValidate" },
|
||
{ value: "vuelidate", label: "Vuelidate" },
|
||
{ value: "zod", label: "Zod" },
|
||
],
|
||
工具库: [
|
||
{ value: "vueuse", label: "VueUse(组合式工具)" },
|
||
{ value: "lodash", label: "Lodash" },
|
||
{ value: "dayjs", label: "Day.js" },
|
||
{ value: "iconify", label: "Iconify图标" },
|
||
], 国际化: [
|
||
{ value: "none", label: "不需要国际化" },
|
||
{ value: "vue-i18n", label: "Vue-i18n" },
|
||
],
|
||
};
|
||
|
||
// 通用组件(React和Vue共用)
|
||
const commonComponents = {
|
||
HTTP请求: [
|
||
{ value: "none", label: "不需要HTTP库" },
|
||
{ value: "axios", label: "Axios" },
|
||
{ value: "ky", label: "Ky(轻量级)" },
|
||
{ value: "ofetch", label: "ofetch" },
|
||
],
|
||
CSS方案: [
|
||
{ value: "none", label: "原生CSS" },
|
||
{ value: "tailwind", label: "Tailwind CSS" },
|
||
{ value: "unocss", label: "UnoCSS" },
|
||
{ value: "sass", label: "Sass/SCSS" },
|
||
{ value: "less", label: "Less" },
|
||
],
|
||
代码规范: [
|
||
{ value: "eslint", label: "ESLint" },
|
||
{ value: "prettier", label: "Prettier" },
|
||
{ value: "husky", label: "Husky" },
|
||
{ value: "lint-staged", label: "lint-staged" },
|
||
],
|
||
其他: [
|
||
{ value: "mock", label: "Mock.js" },
|
||
{ value: "pwa", label: "PWA支持" },
|
||
{ value: "storage", label: "持久化存储" },
|
||
{ value: "threejs", label: "3D集成(Three.js)" },
|
||
{ value: "babylonjs", label: "3D集成(Babylon.js)" },
|
||
],
|
||
};
|
||
|
||
// 根据框架获取组件配置
|
||
export const getComponentsByFramework = (framework) => {
|
||
if (!framework || framework === "none") return {};
|
||
|
||
const isReact = ["react", "nextjs"].includes(framework);
|
||
const isVue = ["vue", "nuxt"].includes(framework);
|
||
const isBun = framework === "bun";
|
||
const isNode = framework === "node";
|
||
|
||
if (isReact) {
|
||
return { ...reactComponents, ...commonComponents };
|
||
} else if (isVue) {
|
||
return { ...vueComponents, ...commonComponents };
|
||
} else if (isBun) {
|
||
return { ...bunComponents, ...backendCommonComponents };
|
||
} else if (isNode) {
|
||
return { ...nodeComponents, ...backendCommonComponents };
|
||
}
|
||
|
||
return {};
|
||
};
|
||
|
||
// 获取默认框架
|
||
const getDefaultFramework = (projectType) => {
|
||
const opts = frameworkOptions[projectType];
|
||
return opts?.[0]?.value || "none";
|
||
};
|
||
|
||
// 生成前端/全栈项目的步骤配置
|
||
export const generateSteps = (projectType, selectedFramework) => {
|
||
const defaultFramework = getDefaultFramework(projectType);
|
||
const framework = selectedFramework || defaultFramework;
|
||
|
||
const steps = [
|
||
{
|
||
name: "运行时",
|
||
type: "select",
|
||
message: "选择项目框架",
|
||
options: frameworkOptions[projectType] || [],
|
||
default: defaultFramework
|
||
}
|
||
];
|
||
|
||
const components = getComponentsByFramework(framework);
|
||
const componentNames = Object.keys(components);
|
||
|
||
componentNames.forEach(name => {
|
||
const isMulti = ["工具库", "代码规范", "其他"].includes(name);
|
||
const opts = components[name] || [];
|
||
steps.push({
|
||
name,
|
||
type: isMulti ? "multiselect" : "select",
|
||
message: `选择${name}`,
|
||
options: opts,
|
||
default: isMulti ? [] : opts[0]?.value
|
||
});
|
||
});
|
||
|
||
return steps;
|
||
};
|