204 lines
7.0 KiB
JavaScript
204 lines
7.0 KiB
JavaScript
/**
|
||
* CLI - 命令行接口
|
||
*/
|
||
|
||
// 加载环境变量
|
||
require('dotenv').config();
|
||
|
||
const { Command } = require('commander');
|
||
const registry = require('./index');
|
||
const logger = require('./shared/logger');
|
||
const packageJson = require('../package.json');
|
||
|
||
const program = new Command();
|
||
|
||
// 主程序配置
|
||
program
|
||
.name('aam')
|
||
.description('Auto Account Machine - 自动化工具集')
|
||
.version(packageJson.version);
|
||
|
||
// 注册card-generator命令
|
||
const cardTool = registry.get('card-generator');
|
||
if (cardTool) {
|
||
const cardCommand = program
|
||
.command('card')
|
||
.description('生成虚拟信用卡号')
|
||
.option('-t, --type <type>', '卡类型 (unionpay, visa, mastercard, amex, discover)', 'unionpay')
|
||
.option('-n, --count <number>', '生成数量', '1')
|
||
.option('-f, --format <format>', '输出格式 (pipe, json, csv, pretty)', 'pipe')
|
||
.action((options) => {
|
||
cardTool.execute(options);
|
||
});
|
||
|
||
// 添加子命令
|
||
cardCommand
|
||
.command('list-types')
|
||
.description('列出所有支持的卡类型')
|
||
.action(() => {
|
||
cardTool.listTypes();
|
||
});
|
||
|
||
cardCommand
|
||
.command('list-formats')
|
||
.description('列出所有支持的输出格式')
|
||
.action(() => {
|
||
cardTool.listFormats();
|
||
});
|
||
}
|
||
|
||
// 注册account-register命令
|
||
const registerTool = registry.get('account-register');
|
||
if (registerTool) {
|
||
const registerCommand = program
|
||
.command('register')
|
||
.description('自动注册账号')
|
||
.option('-s, --site <site>', '网站名称 (windsurf, etc)')
|
||
.option('--dry-run', '干运行模式:只生成数据不执行注册', false)
|
||
.option('-f, --format <format>', '输出格式 (simple, json, table)', 'simple')
|
||
.option('-o, --output <file>', '保存账号数据到文件')
|
||
.option('--from-step <number>', '从第几步开始执行', '1')
|
||
.option('--to-step <number>', '执行到第几步(不指定则执行全部)')
|
||
.option('--password-strategy <strategy>', '密码策略 (email=使用邮箱, random=随机)', 'email')
|
||
.option('--keep-browser-open', '保持浏览器打开', false)
|
||
.action(async (options) => {
|
||
// 转换步骤参数为数字
|
||
if (options.fromStep) options.fromStep = parseInt(options.fromStep);
|
||
if (options.toStep) options.toStep = parseInt(options.toStep);
|
||
await registerTool.execute(options);
|
||
});
|
||
|
||
// 添加子命令
|
||
registerCommand
|
||
.command('list')
|
||
.description('列出所有支持的网站')
|
||
.action(() => {
|
||
registerTool.listSites();
|
||
});
|
||
|
||
registerCommand
|
||
.command('generate')
|
||
.description('只生成账号数据(不执行注册)')
|
||
.option('-f, --format <format>', '输出格式', 'simple')
|
||
.action((options) => {
|
||
registerTool.generate(options);
|
||
});
|
||
|
||
registerCommand
|
||
.command('list-formats')
|
||
.description('列出所有支持的输出格式')
|
||
.action(() => {
|
||
registerTool.listFormats();
|
||
});
|
||
}
|
||
|
||
// 注册automation-framework命令(新框架)
|
||
const autoTool = registry.get('automation-framework');
|
||
if (autoTool) {
|
||
const autoCommand = program
|
||
.command('auto')
|
||
.description('基于配置的自动化注册(新框架)')
|
||
.option('-s, --site <site>', '网站名称 (windsurf, etc)')
|
||
.option('-p, --profile-id <profileId>', 'AdsPower Profile ID')
|
||
.option('-o, --output <file>', '保存结果到文件')
|
||
.option('--no-validate-config', '跳过配置验证', false)
|
||
.option('--no-performance-report', '跳过性能报告', false)
|
||
.action(async (options) => {
|
||
await autoTool.execute(options);
|
||
});
|
||
|
||
// 添加子命令
|
||
autoCommand
|
||
.command('list')
|
||
.description('列出所有支持的网站')
|
||
.action(() => {
|
||
autoTool.listSites();
|
||
});
|
||
|
||
autoCommand
|
||
.command('validate <site>')
|
||
.description('验证站点配置文件')
|
||
.action((site) => {
|
||
autoTool.validateConfig(site);
|
||
});
|
||
}
|
||
|
||
// 注册account-generator命令
|
||
const accountTool = registry.get('account-generator');
|
||
if (accountTool) {
|
||
const accountCommand = program
|
||
.command('account')
|
||
.description('生成账户数据(邮箱、密码、姓名等)')
|
||
.option('-n, --count <number>', '生成数量', '1')
|
||
.option('-f, --format <format>', '输出格式 (simple, detailed, json, csv, table)', 'simple')
|
||
.option('--include-card', '包含信用卡信息')
|
||
.option('--no-include-phone', '不包含手机号')
|
||
.option('--password-strategy <strategy>', '密码策略 (email, random)', 'email')
|
||
.action((options) => {
|
||
accountTool.execute(options);
|
||
});
|
||
|
||
// 添加子命令
|
||
accountCommand
|
||
.command('list-formats')
|
||
.description('列出所有支持的输出格式')
|
||
.action(() => {
|
||
accountTool.listFormats();
|
||
});
|
||
}
|
||
|
||
// 列出所有工具
|
||
program
|
||
.command('list')
|
||
.description('列出所有可用工具')
|
||
.action(() => {
|
||
const tools = registry.getAll();
|
||
console.log('\n可用工具:\n');
|
||
tools.forEach(tool => {
|
||
const alias = tool.alias ? ` (${tool.alias})` : '';
|
||
console.log(` ${tool.name}${alias.padEnd(20)} - ${tool.description}`);
|
||
});
|
||
console.log('');
|
||
});
|
||
|
||
// 帮助信息增强
|
||
program.on('--help', () => {
|
||
console.log('');
|
||
console.log('Examples:');
|
||
console.log(' # 信用卡生成器');
|
||
console.log(' $ aam card # 生成一张默认银联卡');
|
||
console.log(' $ aam card -t visa # 生成一张Visa卡');
|
||
console.log(' $ aam card -t unionpay -n 10 # 生成10张银联卡');
|
||
console.log(' $ aam card list-types # 查看支持的卡类型');
|
||
console.log('');
|
||
console.log(' # 账户数据生成器');
|
||
console.log(' $ aam account # 生成一个账户(邮箱+密码)');
|
||
console.log(' $ aam account -n 10 # 生成10个账户');
|
||
console.log(' $ aam account -f json # JSON格式输出');
|
||
console.log(' $ aam account -f table --include-card # 表格格式,包含卡信息');
|
||
console.log(' $ aam account list-formats # 查看支持的格式');
|
||
console.log('');
|
||
console.log(' # 账号注册工具(旧框架)');
|
||
console.log(' $ aam register -s windsurf --dry-run # 生成Windsurf账号数据');
|
||
console.log(' $ aam register -s windsurf # 执行Windsurf注册');
|
||
console.log(' $ aam register list # 列出支持的网站');
|
||
console.log(' $ aam register generate # 生成通用账号数据');
|
||
console.log('');
|
||
console.log(' # 自动化框架(新框架 - 推荐)');
|
||
console.log(' $ aam auto -s windsurf -p k7g4ia4 # 使用新框架注册Windsurf');
|
||
console.log(' $ aam auto list # 列出支持的网站');
|
||
console.log(' $ aam auto validate windsurf # 验证配置文件');
|
||
console.log('');
|
||
console.log(' # 其他');
|
||
console.log(' $ aam list # 列出所有工具');
|
||
console.log('');
|
||
});
|
||
|
||
// 解析命令
|
||
program.parse(process.argv);
|
||
|
||
// 如果没有参数,显示帮助
|
||
if (!process.argv.slice(2).length) {
|
||
program.outputHelp();
|
||
}
|