From 43874892b77fe87af8abd9b43279a07aa58138f8 Mon Sep 17 00:00:00 2001 From: moyin <244344649@qq.com> Date: Wed, 14 Jan 2026 13:17:02 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0=20AI=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A3=80=E6=9F=A5=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=85=8D=E7=BD=AE=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 setup-user-info.js 脚本 - 自动获取当前日期并提示输入用户名 - 生成 me.config.json 配置文件供 AI 检查步骤使用 - 简化 AI 代码检查流程的用户信息收集 --- docs/ai-reading/tools/setup-user-info.js | 115 +++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 docs/ai-reading/tools/setup-user-info.js diff --git a/docs/ai-reading/tools/setup-user-info.js b/docs/ai-reading/tools/setup-user-info.js new file mode 100644 index 0000000..4953346 --- /dev/null +++ b/docs/ai-reading/tools/setup-user-info.js @@ -0,0 +1,115 @@ +#!/usr/bin/env node + +/** + * AI代码检查用户信息管理脚本 + * + * 功能:获取当前日期和用户名称,保存到me.config.json供AI检查步骤使用 + * + * @author AI助手 + * @version 1.0.0 + * @since 2026-01-13 + */ + +const fs = require('fs'); +const path = require('path'); +const readline = require('readline'); + +const configPath = path.join(__dirname, '..', 'me.config.json'); + +// 获取当前日期(YYYY-MM-DD格式) +function getCurrentDate() { + const now = new Date(); + const year = now.getFullYear(); + const month = String(now.getMonth() + 1).padStart(2, '0'); + const day = String(now.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + +// 读取现有配置 +function readConfig() { + try { + if (!fs.existsSync(configPath)) { + return null; + } + return JSON.parse(fs.readFileSync(configPath, 'utf-8')); + } catch (error) { + console.error('❌ 读取配置文件失败:', error); + return null; + } +} + +// 保存配置 +function saveConfig(config) { + try { + fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8'); + console.log('✅ 配置已保存'); + } catch (error) { + console.error('❌ 保存配置失败:', error); + throw error; + } +} + +// 提示用户输入名称 +function promptUserName() { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + + return new Promise((resolve) => { + rl.question('👤 请输入您的名称或昵称: ', (name) => { + rl.close(); + resolve(name.trim()); + }); + }); +} + +// 主执行逻辑 +async function main() { + console.log('🚀 AI代码检查 - 用户信息设置'); + + const currentDate = getCurrentDate(); + console.log('📅 当前日期:', currentDate); + + const existingConfig = readConfig(); + + // 如果配置存在且日期匹配,直接返回 + if (existingConfig && existingConfig.date === currentDate) { + console.log('✅ 配置已是最新,当前用户:', existingConfig.name); + return existingConfig; + } + + // 需要更新配置 + console.log('🔄 需要更新用户信息...'); + const userName = await promptUserName(); + + if (!userName) { + console.error('❌ 用户名称不能为空'); + process.exit(1); + } + + const config = { + date: currentDate, + name: userName + }; + + saveConfig(config); + console.log('🎉 设置完成!', config); + + return config; +} + +// 导出函数供其他脚本使用 +function getConfig() { + return readConfig(); +} + +// 如果直接运行此脚本 +if (require.main === module) { + main().catch((error) => { + console.error('❌ 脚本执行失败:', error); + process.exit(1); + }); +} + +module.exports = { getConfig, getCurrentDate }; \ No newline at end of file