重构成功
This commit is contained in:
@ -155,7 +155,7 @@ const commonComponents = {
|
||||
};
|
||||
|
||||
// 根据框架获取组件配置
|
||||
export function getComponentsByFramework(framework) {
|
||||
export const getComponentsByFramework = (framework) => {
|
||||
if (!framework || framework === "none") return {};
|
||||
|
||||
const isReact = ["react", "nextjs"].includes(framework);
|
||||
@ -174,16 +174,16 @@ export function getComponentsByFramework(framework) {
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
// 获取默认框架
|
||||
function getDefaultFramework(projectType) {
|
||||
const getDefaultFramework = (projectType) => {
|
||||
const opts = frameworkOptions[projectType];
|
||||
return opts?.[0]?.value || "none";
|
||||
}
|
||||
};
|
||||
|
||||
// 生成前端/全栈项目的步骤配置
|
||||
export function generateSteps(projectType, selectedFramework) {
|
||||
export const generateSteps = (projectType, selectedFramework) => {
|
||||
const defaultFramework = getDefaultFramework(projectType);
|
||||
const framework = selectedFramework || defaultFramework;
|
||||
|
||||
@ -213,4 +213,4 @@ export function generateSteps(projectType, selectedFramework) {
|
||||
});
|
||||
|
||||
return steps;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import color from "picocolors";
|
||||
import { projectTypes } from "./config.js";
|
||||
import { gridSelect } from "../../grid.js";
|
||||
import { createScaffoldUI, formatResults, waitKey } from "./ui.js";
|
||||
import { createScaffoldUI, formatResults, waitKey } from "./service.js";
|
||||
|
||||
async function run() {
|
||||
const run = async () => {
|
||||
while (true) {
|
||||
// 二级菜单 - 项目类型
|
||||
const typeResult = await gridSelect({
|
||||
@ -32,7 +32,7 @@ async function run() {
|
||||
await waitKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
id: "scaffold",
|
||||
|
||||
@ -1,21 +1,18 @@
|
||||
import color from "picocolors";
|
||||
import { initKeypress, onKey, stopKeypress } from "../../keyboard.js";
|
||||
import { createStepUI } from "../../utils/stepui.js";
|
||||
import { generateSteps } from "./config.js";
|
||||
import { initKeypress, onKey, stopKeypress } from "../../keyboard.js";
|
||||
|
||||
// 框架 + 组件配置 UI
|
||||
export function createScaffoldUI(projectType) {
|
||||
export const createScaffoldUI = (projectType) => {
|
||||
return createStepUI({
|
||||
title: `${projectType} - 项目配置`,
|
||||
getSteps: () => generateSteps(projectType, null),
|
||||
onStepChange: framework => generateSteps(projectType, framework),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 解析配置结果
|
||||
export function formatResults(steps, results) {
|
||||
export const formatResults = (steps, results) => {
|
||||
const summary = [];
|
||||
|
||||
results.forEach((val, i) => {
|
||||
if (Array.isArray(val) && val.length > 0) {
|
||||
summary.push(`${steps[i].name}: ${val.join(", ")}`);
|
||||
@ -23,14 +20,11 @@ export function formatResults(steps, results) {
|
||||
summary.push(`${steps[i].name}: ${val}`);
|
||||
}
|
||||
});
|
||||
|
||||
return summary.length ? summary : ["未选择任何组件"];
|
||||
}
|
||||
};
|
||||
|
||||
// 等待按键
|
||||
export async function waitKey(message = "按任意键返回") {
|
||||
export const waitKey = async (message = "按任意键返回") => {
|
||||
console.log(color.dim(`\n${message}`));
|
||||
|
||||
return new Promise(resolve => {
|
||||
initKeypress();
|
||||
onKey(() => {
|
||||
@ -38,4 +32,4 @@ export async function waitKey(message = "按任意键返回") {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user