kawazu
Version:
kawazu CLI tool for real-time chat in your editor
272 lines (271 loc) • 12.5 kB
JavaScript
;
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 });
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const join_1 = require("./commands/join");
const create_1 = require("./commands/create");
const list_1 = require("./commands/list");
const config_1 = require("./commands/config");
const profile_1 = require("./commands/profile");
const share_1 = require("./commands/share");
const approve_1 = require("./commands/approve");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const program = new commander_1.Command();
// package.jsonからバージョンを読み取る
const packageJsonPath = path.join(__dirname, '../package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// バージョンとメタ情報
program
.name('kawazu')
.description('エディタ上でリアルタイムチャットを行うCLIツール')
.version(packageJson.version);
// ログインコマンド
program
.command('login')
.description('アカウントにログインする')
.option('-e, --email <email>', 'メールアドレス')
.option('-p, --password <password>', 'パスワード')
.action(async (options) => {
const { loginUser } = await Promise.resolve().then(() => __importStar(require('./commands/auth')));
await loginUser(options);
});
// ログアウトコマンド
program
.command('logout')
.description('ログアウトする')
.action(async () => {
const { logoutUser } = await Promise.resolve().then(() => __importStar(require('./commands/auth')));
await logoutUser();
});
// アカウント状態確認コマンド
program
.command('whoami')
.description('現在ログイン中のユーザー情報を表示')
.action(async () => {
const { showCurrentUser } = await Promise.resolve().then(() => __importStar(require('./commands/auth')));
await showCurrentUser();
});
// プラン確認コマンド
program
.command('plan')
.description('現在のサブスクリプションプランを表示')
.action(async () => {
const { showSubscriptionPlan } = await Promise.resolve().then(() => __importStar(require('./commands/auth')));
await showSubscriptionPlan();
});
// ルーム参加コマンド
program
.command('join <roomId>')
.description('指定されたルームに参加する')
.option('-u, --username <name>', 'ユーザー名を指定')
.option('-p, --password <password>', 'プライベートルームのパスワード')
.action(async (roomId, options) => {
await (0, join_1.joinRoom)(roomId, options);
});
// ルーム作成コマンド
program
.command('create <roomName>')
.description('新しいルームを作成して参加')
.option('--private', 'プライベートルームとして作成')
.option('--password <password>', 'プライベートルーム用パスワード')
.action(async (roomName, options) => {
await (0, create_1.createRoom)(roomName, options);
});
// ルーム一覧コマンド
program
.command('list')
.description('ローカルのチャットファイル一覧を表示')
.action(async () => {
await (0, list_1.listRooms)();
});
// 設定コマンド
program
.command('config')
.description('CLI設定を管理')
.option('--server <url>', 'サーバーURLを設定')
.option('--username <name>', 'デフォルトユーザー名を設定')
.option('--show', '現在の設定を表示')
.action(async (options) => {
if (options.show) {
await (0, config_1.showConfig)();
}
else {
await (0, config_1.configureSettings)(options);
}
});
// プロフィールコマンド
program
.command('profile <username>')
.description('ユーザーのプロフィールを表示')
.option('--open', 'ブラウザでプロフィールを開く')
.action(async (username, options) => {
if (options.open) {
await (0, profile_1.openProfile)(username);
}
else {
await (0, profile_1.showProfile)(username);
}
});
// ファイル共有コマンド
program
.command('share <filePath>')
.description('ファイルを他のユーザーと共有')
.option('--room <roomId>', '対象のルームを指定')
.option('--users <usernames>', '対象ユーザーをカンマ区切りで指定(省略時は全参加者)')
.option('--permission <type>', '権限タイプ (read|write)', 'read')
.option('--expires <hours>', '有効期限(時間)', '24')
.option('--type <fileType>', 'ファイルタイプを手動指定')
.action(async (filePath, options) => {
await (0, share_1.shareFile)(filePath, options);
});
// ファイル共有承認コマンド
program
.command('approve <shareToken>')
.description('ファイル共有リクエストを承認')
.option('--reason <text>', '承認理由')
.action(async (shareToken, options) => {
await (0, approve_1.approveFileShare)(shareToken, options);
});
// ファイル共有拒否コマンド
program
.command('deny <shareToken>')
.description('ファイル共有リクエストを拒否')
.option('--reason <text>', '拒否理由')
.action(async (shareToken, options) => {
await (0, approve_1.denyFileShare)(shareToken, options);
});
// 共有ファイル一覧コマンド
program
.command('files [roomId]')
.description('共有されているファイル一覧を表示')
.action(async (roomId) => {
await (0, share_1.listSharedFiles)(roomId);
});
// ファイルダウンロードコマンド
program
.command('download <shareToken> [outputPath]')
.description('共有ファイルをダウンロード')
.action(async (shareToken, outputPath) => {
await (0, share_1.downloadSharedFile)(shareToken, outputPath);
});
// 承認待ちリクエスト一覧コマンド
program
.command('requests')
.description('承認待ちのファイル共有リクエスト一覧')
.action(async () => {
await (0, approve_1.listPendingRequests)();
});
// ファイル共有取り消しコマンド
program
.command('unshare <shareToken>')
.description('ファイル共有を取り消し')
.action(async (shareToken) => {
await (0, share_1.revokeFileShare)(shareToken);
});
// ヘルプコマンド拡張
program
.command('help-usage')
.description('詳細な使用方法を表示')
.action(() => {
console.log(chalk_1.default.blue.bold('\n📖 Kawazu CLI - 使用方法\n'));
console.log(chalk_1.default.yellow('🔐 初回セットアップ:'));
console.log(' 1. ログイン: ' + chalk_1.default.cyan('kawazu login'));
console.log(' 2. プラン確認: ' + chalk_1.default.cyan('kawazu plan'));
console.log(' 3. 設定確認: ' + chalk_1.default.cyan('kawazu config --show\n'));
console.log(chalk_1.default.yellow('🚀 基本的な使い方:'));
console.log(' 1. ルームを作成: ' + chalk_1.default.cyan('kawazu create "プロジェクト会議"'));
console.log(' 2. ルームに参加: ' + chalk_1.default.cyan('kawazu join project-meeting'));
console.log(' 3. エディタで .codechat ファイルを開く');
console.log(' 4. ファイルに書き込んでチャット開始!\n');
console.log(chalk_1.default.yellow('👤 アカウント管理:'));
console.log(' • ログイン: ' + chalk_1.default.cyan('kawazu login'));
console.log(' • ログアウト: ' + chalk_1.default.cyan('kawazu logout'));
console.log(' • ユーザー確認: ' + chalk_1.default.cyan('kawazu whoami'));
console.log(' • プラン確認: ' + chalk_1.default.cyan('kawazu plan\n'));
console.log(chalk_1.default.yellow('💡 便利なオプション:'));
console.log(' • ユーザー名指定: ' + chalk_1.default.cyan('kawazu join room-id -u username'));
console.log(' • プライベートルーム: ' + chalk_1.default.cyan('kawazu join room-id -p password'));
console.log(' • 設定確認: ' + chalk_1.default.cyan('kawazu config --show'));
console.log(' • ファイル一覧: ' + chalk_1.default.cyan('kawazu list'));
console.log(' • プロフィール表示: ' + chalk_1.default.cyan('kawazu profile username\n'));
console.log(chalk_1.default.yellow('📁 ファイル共有機能:'));
console.log(' • ファイル共有: ' + chalk_1.default.cyan('kawazu share myfile.js --users alice,bob'));
console.log(' • 共有承認: ' + chalk_1.default.cyan('kawazu approve <share-token>'));
console.log(' • 共有拒否: ' + chalk_1.default.cyan('kawazu deny <share-token>'));
console.log(' • ファイル一覧: ' + chalk_1.default.cyan('kawazu files'));
console.log(' • ファイルダウンロード: ' + chalk_1.default.cyan('kawazu download <share-token>'));
console.log(' • 承認待ち確認: ' + chalk_1.default.cyan('kawazu requests'));
console.log(' • 共有取り消し: ' + chalk_1.default.cyan('kawazu unshare <share-token>\n'));
console.log(chalk_1.default.yellow('🔧 初回設定:'));
console.log(' 設定を行う: ' + chalk_1.default.cyan('kawazu config'));
console.log(' サーバーURL設定: ' + chalk_1.default.cyan('kawazu config --server https://kawazu.onrender.com\n'));
console.log(chalk_1.default.yellow('📝 チャットファイルの使い方:'));
console.log(' • # で始まる行はシステムメッセージ(送信されません)');
console.log(' • ``` でコードブロックを作成できます');
console.log(' • ファイルを保存すると自動で送信されます');
console.log(' • Ctrl+C で終了できます\n');
console.log(chalk_1.default.gray('詳細情報: https://github.com/your-repo/kawazu'));
});
// エラーハンドリング
program.on('command:*', () => {
console.error(chalk_1.default.red(`❌ 不明なコマンドです: ${program.args.join(' ')}`));
console.log(chalk_1.default.yellow('💡 使用可能なコマンドを確認: ') + chalk_1.default.cyan('kawazu --help'));
process.exit(1);
});
// 引数がない場合はヘルプを表示
if (process.argv.length === 2) {
program.outputHelp();
console.log(chalk_1.default.blue('\n💡 詳細な使用方法: ') + chalk_1.default.cyan('kawazu help-usage'));
console.log(chalk_1.default.yellow('\n🔐 初回利用の場合: ') + chalk_1.default.cyan('kawazu login'));
}
// プログラム実行
program.parse();
// 未処理の例外をキャッチ
process.on('uncaughtException', (error) => {
console.error(chalk_1.default.red('❌ 予期しないエラーが発生しました:'));
console.error(error);
process.exit(1);
});
process.on('unhandledRejection', (reason) => {
console.error(chalk_1.default.red('❌ 未処理の Promise エラー:'));
console.error(reason);
process.exit(1);
});