UNPKG

kawazu

Version:

kawazu CLI tool for real-time chat in your editor

111 lines (110 loc) 5.39 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.listRooms = listRooms; const chalk_1 = __importDefault(require("chalk")); const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); const config_1 = require("../utils/config"); async function listRooms() { try { console.log(chalk_1.default.blue('📋 ローカルのチャットファイル一覧:\n')); // 現在のディレクトリで .codechat ファイルを検索 const currentDir = process.cwd(); const files = await fs.readdir(currentDir); const codechatFiles = files.filter(file => file.endsWith('.codechat')); if (codechatFiles.length === 0) { console.log(chalk_1.default.gray(' .codechat ファイルが見つかりませんでした')); console.log(chalk_1.default.gray(' ルームに参加すると、このディレクトリに .codechat ファイルが作成されます')); return; } // ファイル情報を最新順でソートして表示 const fileInfos = []; for (const file of codechatFiles) { const filePath = path.join(currentDir, file); const stats = await fs.stat(filePath); fileInfos.push({ file, filePath, stats }); } // 最終更新時刻で降順ソート(最新が一番上) fileInfos.sort((a, b) => b.stats.mtime.getTime() - a.stats.mtime.getTime()); for (const { file, filePath, stats } of fileInfos) { const roomSlug = path.basename(file, '.codechat'); console.log(chalk_1.default.green(`📝 ${file}`)); console.log(` ルームID: ${chalk_1.default.cyan(roomSlug)}`); console.log(` 最終更新: ${chalk_1.default.gray(stats.mtime.toLocaleString('ja-JP'))}`); console.log(` サイズ: ${chalk_1.default.gray(formatFileSize(stats.size))}`); // ファイルの最初の数行を読んで情報を抽出 try { const content = await fs.readFile(filePath, 'utf8'); const lines = content.split('\n'); const roomNameLine = lines.find(line => line.startsWith('# Kawazu Chat Room:')); const usernameLine = lines.find(line => line.startsWith('# あなたのユーザー名:')); if (roomNameLine) { const roomName = roomNameLine.replace('# Kawazu Chat Room:', '').trim(); console.log(` ルーム名: ${chalk_1.default.yellow(roomName)}`); } if (usernameLine) { const username = usernameLine.replace('# あなたのユーザー名:', '').trim(); console.log(` ユーザー名: ${chalk_1.default.magenta(username)}`); } } catch (error) { // ファイル読み取りエラーは無視 } console.log(` 再参加: ${chalk_1.default.cyan(`kawazu join ${roomSlug}`)}\n`); } // 設定情報も表示 const config = await (0, config_1.loadConfig)(); console.log(chalk_1.default.blue('⚙️ 設定情報:')); console.log(` サーバーURL: ${chalk_1.default.cyan(config.server_url)}`); if (config.default_username) { console.log(` デフォルトユーザー名: ${chalk_1.default.magenta(config.default_username)}`); } } catch (error) { console.error(chalk_1.default.red(`❌ エラーが発生しました: ${error.message}`)); } } function formatFileSize(bytes) { if (bytes === 0) return '0 B'; const k = 1024; const sizes = ['B', 'KB', 'MB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]; }