refactor(install): 优化安装脚本配置逻辑

- 提取 Nginx 检测为独立函数 isNginxInstalled
- 为 select 函数添加 defaultIndex 参数支持默认选项
- 数据库配置保留用户上次输入值作为默认值
- 运行环境和部署方式选择支持记忆上次配置
This commit is contained in:
zhang1106
2026-05-09 16:30:21 +08:00
parent 7f4602d465
commit 3f34098635
4 changed files with 20 additions and 16 deletions
+2 -2
View File
@@ -77,14 +77,14 @@ function askPassword(question) {
});
}
async function select(question, options) {
async function select(question, options, defaultIndex = 1) {
const { colors } = require('./logger');
console.log(`\n${question}`);
options.forEach((opt, idx) => {
console.log(` ${colors.cyan}${idx + 1}.${colors.reset} ${opt.label}`);
});
const answer = await ask('请选择', '1');
const answer = await ask('请选择', String(defaultIndex));
const index = parseInt(answer) - 1;
return options[index]?.value || options[0].value;