doclyft
Version:
CLI for DocLyft - Interactive documentation generator with hosted documentation support
84 lines (83 loc) • 2.41 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const conf_1 = __importDefault(require("conf"));
const path_1 = __importDefault(require("path"));
const os_1 = __importDefault(require("os"));
const fs_1 = __importDefault(require("fs"));
const schema = {
token: {
type: 'string',
description: 'API token for DocLyft',
},
repo: {
type: 'string',
description: 'Default repository for the project',
},
branch: {
type: 'string',
description: 'Default branch for the project',
},
user_id: {
type: 'string',
description: 'User ID from DocLyft authentication',
},
user_email: {
type: 'string',
description: 'User email from DocLyft authentication',
},
github_token: {
type: 'string',
description: 'GitHub personal access token',
},
last_analysis_id: {
type: 'string',
description: 'ID of the last repository analysis',
},
last_repo_name: {
type: 'string',
description: 'Name of the last analyzed repository',
},
};
class ConfigService {
constructor() {
try {
// Ensure the config directory exists
const configDir = path_1.default.join(os_1.default.homedir(), '.doclyft');
if (!fs_1.default.existsSync(configDir)) {
fs_1.default.mkdirSync(configDir, { recursive: true });
}
this.config = new conf_1.default({
projectName: 'doclyft',
schema,
cwd: configDir, // Explicitly set the config directory
});
}
catch (error) {
console.error('Error initializing config:', error);
// Fallback to default Conf behavior
this.config = new conf_1.default({
projectName: 'doclyft',
schema,
});
}
}
get(key) {
return this.config.get(key);
}
set(key, value) {
this.config.set(key, value);
}
delete(key) {
this.config.delete(key);
}
clear() {
this.config.clear();
}
getAll() {
return this.config.store;
}
}
exports.default = new ConfigService();