basics-courses-mcp
Version:
Interactive programming courses from Basics - MCP server for Cursor
61 lines • 1.81 kB
JavaScript
import fs from 'fs';
import path from 'path';
import os from 'os';
const configDir = path.join(os.homedir(), '.basicsu');
const configFile = path.join(configDir, 'config.json');
export function loadConfig() {
try {
if (!fs.existsSync(configFile)) {
return {};
}
const data = fs.readFileSync(configFile, 'utf8');
return JSON.parse(data);
}
catch (error) {
// Failed to load config
return {};
}
}
export function saveConfig(config) {
try {
// Ensure config directory exists
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true });
}
// Load existing config and merge
const existing = loadConfig();
const merged = { ...existing, ...config };
fs.writeFileSync(configFile, JSON.stringify(merged, null, 2));
}
catch (error) {
// Failed to save config
throw error;
}
}
export function hasValidAuth() {
const config = loadConfig();
return !!(config.userEmail && config.deviceToken);
}
export function clearAuth() {
try {
// Load existing config
const config = loadConfig();
// Remove auth fields but keep other settings
delete config.userEmail;
delete config.deviceToken;
// Save the updated config
if (Object.keys(config).length > 0) {
fs.writeFileSync(configFile, JSON.stringify(config, null, 2));
}
else {
// If no other settings, remove the file entirely
if (fs.existsSync(configFile)) {
fs.unlinkSync(configFile);
}
}
}
catch (error) {
throw new Error(`Failed to clear authentication: ${error}`);
}
}
//# sourceMappingURL=config.js.map