build-in-public-bot
Version:
AI-powered CLI bot for automating build-in-public tweets with code screenshots
258 lines • 9.17 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 });
exports.configCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const config_1 = require("../../services/config");
const errors_1 = require("../../utils/errors");
const fs = __importStar(require("fs/promises"));
const yaml = __importStar(require("yaml"));
exports.configCommand = new commander_1.Command('config')
.description('Manage configuration')
.option('--json', 'Output in JSON format')
.action(async () => {
exports.configCommand.outputHelp();
});
exports.configCommand
.command('show')
.description('Show current configuration')
.option('--reveal-secrets', 'Show sensitive values (API keys, etc.)')
.action(async (options) => {
try {
const configService = config_1.ConfigService.getInstance();
const config = await configService.load();
const displayConfig = JSON.parse(JSON.stringify(config));
if (!options.revealSecrets) {
if (displayConfig.ai?.apiKey) {
displayConfig.ai.apiKey = displayConfig.ai.apiKey.substring(0, 8) + '...';
}
if (displayConfig.twitter?.sessionData) {
displayConfig.twitter.sessionData = '[HIDDEN]';
}
}
if (options.parent.json) {
console.log(JSON.stringify(displayConfig, null, 2));
}
else {
console.log(chalk_1.default.cyan('Current Configuration:'));
console.log(yaml.stringify(displayConfig));
}
}
catch (error) {
(0, errors_1.handleError)(error);
}
});
exports.configCommand
.command('get <key>')
.description('Get a specific configuration value')
.action(async (key) => {
try {
const configService = config_1.ConfigService.getInstance();
const config = await configService.load();
const value = key.split('.').reduce((obj, prop) => obj?.[prop], config);
if (value === undefined) {
console.error(chalk_1.default.red(`Configuration key '${key}' not found`));
process.exit(1);
}
if (exports.configCommand.opts().json) {
console.log(JSON.stringify(value));
}
else {
console.log(value);
}
}
catch (error) {
(0, errors_1.handleError)(error);
}
});
exports.configCommand
.command('set <key> <value>')
.description('Set a configuration value')
.action(async (key, value) => {
try {
const configService = config_1.ConfigService.getInstance();
const config = await configService.load();
let parsedValue = value;
if (value.startsWith('{') || value.startsWith('[') || value === 'true' || value === 'false') {
try {
parsedValue = JSON.parse(value);
}
catch {
}
}
else if (!isNaN(Number(value))) {
parsedValue = Number(value);
}
const keys = key.split('.');
const lastKey = keys.pop();
const target = keys.reduce((obj, prop) => {
if (!obj[prop])
obj[prop] = {};
return obj[prop];
}, config);
target[lastKey] = parsedValue;
await configService.save(config);
console.log(chalk_1.default.green(`✓ Set ${key} = ${JSON.stringify(parsedValue)}`));
}
catch (error) {
(0, errors_1.handleError)(error);
}
});
exports.configCommand
.command('validate')
.description('Validate current configuration')
.action(async () => {
try {
const configService = config_1.ConfigService.getInstance();
const validation = await configService.validate();
if (validation.valid) {
console.log(chalk_1.default.green('✓ Configuration is valid'));
}
else {
console.log(chalk_1.default.red('✗ Configuration validation failed:'));
validation.errors.forEach(error => {
console.log(chalk_1.default.yellow(` - ${error}`));
});
process.exit(1);
}
}
catch (error) {
(0, errors_1.handleError)(error);
}
});
exports.configCommand
.command('export [file]')
.description('Export configuration to file')
.option('--format <format>', 'Output format (yaml, json)', 'yaml')
.action(async (file, options) => {
try {
const configService = config_1.ConfigService.getInstance();
const config = await configService.load();
let output;
if (options.format === 'json') {
output = JSON.stringify(config, null, 2);
}
else {
output = yaml.stringify(config);
}
if (file) {
await fs.writeFile(file, output);
console.log(chalk_1.default.green(`✓ Configuration exported to ${file}`));
}
else {
console.log(output);
}
}
catch (error) {
(0, errors_1.handleError)(error);
}
});
exports.configCommand
.command('import <file>')
.description('Import configuration from file')
.option('--merge', 'Merge with existing config instead of replacing')
.action(async (file, options) => {
try {
const configService = config_1.ConfigService.getInstance();
const fileContent = await fs.readFile(file, 'utf-8');
let importedConfig;
if (file.endsWith('.json')) {
importedConfig = JSON.parse(fileContent);
}
else {
importedConfig = yaml.parse(fileContent);
}
if (options.merge) {
const currentConfig = await configService.load();
const mergedConfig = deepMerge(currentConfig, importedConfig);
await configService.save(mergedConfig);
console.log(chalk_1.default.green('✓ Configuration merged successfully'));
}
else {
await configService.save(importedConfig);
console.log(chalk_1.default.green('✓ Configuration imported successfully'));
}
}
catch (error) {
(0, errors_1.handleError)(error);
}
});
exports.configCommand
.command('reset')
.description('Reset configuration to defaults')
.option('--force', 'Skip confirmation')
.action(async (options) => {
try {
if (!options.force) {
console.log(chalk_1.default.yellow('⚠️ This will reset all configuration to defaults.'));
console.log(chalk_1.default.yellow(' Use --force to skip this confirmation.'));
process.exit(1);
}
const configService = config_1.ConfigService.getInstance();
await configService.reset();
console.log(chalk_1.default.green('✓ Configuration reset to defaults'));
}
catch (error) {
(0, errors_1.handleError)(error);
}
});
function deepMerge(target, source) {
const output = { ...target };
if (isObject(target) && isObject(source)) {
Object.keys(source).forEach(key => {
if (isObject(source[key])) {
if (!(key in target)) {
output[key] = source[key];
}
else {
output[key] = deepMerge(target[key], source[key]);
}
}
else {
output[key] = source[key];
}
});
}
return output;
}
function isObject(item) {
return item && typeof item === 'object' && !Array.isArray(item);
}
exports.default = exports.configCommand;
//# sourceMappingURL=index.js.map
;