list-accounts.mjs
760 Bytes
// 列出所有账号用户名(不打印哈希,哈希不可用于登录,仅作存在性核对)。
// 用法: pnpm --filter @hm/server list:accounts
import { existsSync, readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
const here = path.dirname(fileURLToPath(import.meta.url));
const ACCOUNTS_PATH = path.resolve(here, '../data/accounts.json');
if (!existsSync(ACCOUNTS_PATH)) {
console.log('(无账号文件)');
process.exit(0);
}
const accounts = JSON.parse(readFileSync(ACCOUNTS_PATH, 'utf-8'));
if (!accounts.length) {
console.log('(无账号)');
process.exit(0);
}
console.log(`共 ${accounts.length} 个账号:`);
for (const a of accounts) console.log(` - ${a.username}`);