@tastekim/chat-cli
Version:
π¬Connect with developers worldwide through an interactive terminal chat experience while you code!π»
173 lines β’ 6.47 kB
JavaScript
"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;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureFlagManager = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const os = __importStar(require("os"));
class FeatureFlagManager {
constructor() {
this.configPath = path.join(os.homedir(), '.chat-cli', 'config.json');
this.config = this.loadConfig();
}
static getInstance() {
if (!FeatureFlagManager.instance) {
FeatureFlagManager.instance = new FeatureFlagManager();
}
return FeatureFlagManager.instance;
}
loadConfig() {
try {
if (fs.existsSync(this.configPath)) {
const configData = fs.readFileSync(this.configPath, 'utf8');
const parsedConfig = JSON.parse(configData);
// κΈ°λ³Έ μ€μ κ³Ό λ³ν©νμ¬ λλ½λ νλ 보μ
return {
...FeatureFlagManager.DEFAULT_CONFIG,
...parsedConfig,
lastUpdated: new Date()
};
}
}
catch (error) {
console.warn('Failed to load config, using defaults:', error);
}
return { ...FeatureFlagManager.DEFAULT_CONFIG };
}
saveConfig() {
try {
const configDir = path.dirname(this.configPath);
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true });
}
this.config.lastUpdated = new Date();
fs.writeFileSync(this.configPath, JSON.stringify(this.config, null, 2));
}
catch (error) {
console.error('Failed to save config:', error);
}
}
// κΈ°λ₯ νλκ·Έ νμΈ λ©μλλ€
isMultiRoomEnabled() {
return this.config.enableMultiRoom;
}
isPrivateRoomsEnabled() {
return this.config.enablePrivateRooms;
}
isUnreadIndicatorEnabled() {
return this.config.enableUnreadIndicator;
}
isRoomTabsEnabled() {
return this.config.enableRoomTabs;
}
getDefaultRoom() {
return this.config.defaultRoom;
}
getMaxJoinedRooms() {
return this.config.maxJoinedRooms;
}
// μ€μ μ
λ°μ΄νΈ λ©μλλ€
enableMultiRoom(enable = true) {
this.config.enableMultiRoom = enable;
// Multi-room νμ±ν μ κ΄λ ¨ κΈ°λ₯λ€λ μλ νμ±ν
if (enable) {
this.config.enableUnreadIndicator = true;
this.config.enableRoomTabs = true;
this.config.defaultRoom = 'lobby';
}
this.saveConfig();
}
enablePrivateRooms(enable = true) {
this.config.enablePrivateRooms = enable;
this.saveConfig();
}
setDefaultRoom(room) {
this.config.defaultRoom = room;
this.saveConfig();
}
setMaxJoinedRooms(max) {
this.config.maxJoinedRooms = Math.max(1, Math.min(max, 10)); // 1-10 λ²μλ‘ μ ν
this.saveConfig();
}
// μ 체 μ€μ μ‘°ν
getConfig() {
return { ...this.config };
}
// μ€μ μ΄κΈ°ν
resetToDefaults() {
this.config = { ...FeatureFlagManager.DEFAULT_CONFIG };
this.saveConfig();
}
// νκ²½λ³μ μ€λ²λΌμ΄λ μ§μ
checkEnvironmentOverrides() {
if (process.env.CHAT_CLI_MULTI_ROOM === 'true') {
this.config.enableMultiRoom = true;
this.config.enableUnreadIndicator = true;
this.config.enableRoomTabs = true;
this.config.defaultRoom = 'lobby';
}
if (process.env.CHAT_CLI_PRIVATE_ROOMS === 'true') {
this.config.enablePrivateRooms = true;
}
if (process.env.CHAT_CLI_DEFAULT_ROOM) {
this.config.defaultRoom = process.env.CHAT_CLI_DEFAULT_ROOM;
}
}
// μ€μ μν νμ
printCurrentConfig() {
console.log('π§ Current Chat-CLI Configuration:');
console.log(` Multi-Room Mode: ${this.config.enableMultiRoom ? 'β
Enabled' : 'β Disabled'}`);
console.log(` Private Rooms: ${this.config.enablePrivateRooms ? 'β
Enabled' : 'β Disabled'}`);
console.log(` Unread Indicator: ${this.config.enableUnreadIndicator ? 'β
Enabled' : 'β Disabled'}`);
console.log(` Room Tabs: ${this.config.enableRoomTabs ? 'β
Enabled' : 'β Disabled'}`);
console.log(` Default Room: ${this.config.defaultRoom}`);
console.log(` Max Joined Rooms: ${this.config.maxJoinedRooms}`);
console.log(` Config Version: ${this.config.version}`);
console.log('');
}
}
exports.FeatureFlagManager = FeatureFlagManager;
// κΈ°λ³Έ μ€μ - λͺ¨λ μ κΈ°λ₯μ κΈ°λ³Έμ μΌλ‘ λΉνμ±ν
FeatureFlagManager.DEFAULT_CONFIG = {
enableMultiRoom: false,
enablePrivateRooms: false,
enableUnreadIndicator: false,
enableRoomTabs: false,
defaultRoom: 'korean', // κΈ°μ‘΄ λμ μ μ§
maxJoinedRooms: 5,
version: '1.5.0',
lastUpdated: new Date()
};
//# sourceMappingURL=feature-flags.js.map