Files
whale-town-end/docs/ai-reading/tools/setup-user-info.js
moyin 43874892b7 feat:添加 AI 代码检查用户信息配置工具
- 新增 setup-user-info.js 脚本
- 自动获取当前日期并提示输入用户名
- 生成 me.config.json 配置文件供 AI 检查步骤使用
- 简化 AI 代码检查流程的用户信息收集
2026-01-14 13:17:02 +08:00

115 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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 };