alnilam-cli
Version:
Git-native AI career coach that converts multi-year ambitions into weekly execution
186 lines (185 loc) ⢠7.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.configCommand = void 0;
const commander_1 = require("commander");
const config_js_1 = require("../lib/config.js");
const configCommand = new commander_1.Command('config');
exports.configCommand = configCommand;
// Status command to display current configuration
const statusCommand = new commander_1.Command('status');
statusCommand
.description('Display current configuration status and environment detection')
.option('--json', 'Output as JSON')
.action(async (options) => {
try {
if (options.json) {
const config = (0, config_js_1.getConfigWithDebug)();
console.log(JSON.stringify({
environment: config.environment,
supabaseUrl: config.supabaseUrl,
isProduction: config.isProduction,
envVarsUsed: config.envVarsUsed,
globalConfigLoaded: config.globalConfigLoaded,
globalConfigFile: config.globalConfigFile,
configLoaded: true
}, null, 2));
}
else {
(0, config_js_1.displayConfigStatus)();
}
}
catch (error) {
if (options.json) {
console.log(JSON.stringify({
error: error.message,
configLoaded: false
}));
}
else {
console.error(`ā Configuration Error: ${error.message}`);
}
process.exit(1);
}
});
// Validate command to check configuration
const validateCommand = new commander_1.Command('validate');
validateCommand
.description('Validate current configuration and environment setup')
.option('--json', 'Output as JSON')
.action(async (options) => {
try {
const config = (0, config_js_1.getConfigWithDebug)();
const validationResults = {
supabaseUrlValid: config.supabaseUrl.startsWith('http'),
supabaseKeyValid: config.supabaseAnonKey.startsWith('eyJ'),
environmentDetected: config.environment !== 'auto',
isProduction: config.isProduction
};
const allValid = Object.values(validationResults).every(Boolean);
if (options.json) {
console.log(JSON.stringify({
valid: allValid,
...validationResults,
environment: config.environment,
supabaseUrl: config.supabaseUrl
}, null, 2));
}
else {
console.log('š Configuration Validation');
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāā');
console.log(`Supabase URL: ${validationResults.supabaseUrlValid ? 'ā
' : 'ā'} ${config.supabaseUrl}`);
console.log(`Supabase Key: ${validationResults.supabaseKeyValid ? 'ā
' : 'ā'} ${validationResults.supabaseKeyValid ? 'Valid JWT format' : 'Invalid format'}`);
console.log(`Environment: ${validationResults.environmentDetected ? 'ā
' : 'ā ļø'} ${config.environment}`);
console.log(`Production Mode: ${config.isProduction ? 'ā
Yes' : 'š ļø No (Development)'}`);
if (allValid) {
console.log('\nā
All configuration checks passed!');
}
else {
console.log('\nā Some configuration issues detected');
console.log('š” Check your .env.production file or environment variables');
}
}
if (!allValid) {
process.exit(1);
}
}
catch (error) {
if (options.json) {
console.log(JSON.stringify({
error: error.message,
valid: false
}));
}
else {
console.error(`ā Validation Error: ${error.message}`);
}
process.exit(1);
}
});
// Set command to configure global settings
const setCommand = new commander_1.Command('set');
setCommand
.description('Set global configuration values')
.argument('<key>', 'Configuration key (supabase-url, supabase-key, test-email, environment)')
.argument('<value>', 'Configuration value')
.option('--json', 'Output as JSON')
.action(async (key, value, options) => {
try {
// Map user-friendly keys to config keys
const keyMap = {
'supabase-url': 'supabaseUrl',
'supabase-key': 'supabaseAnonKey',
'test-email': 'testEmail',
'environment': 'environment'
};
const configKey = keyMap[key];
if (!configKey) {
const validKeys = Object.keys(keyMap).join(', ');
if (options.json) {
console.log(JSON.stringify({
error: `Invalid configuration key: ${key}`,
validKeys
}));
}
else {
console.error(`ā Invalid configuration key: ${key}`);
console.error(`š” Valid keys: ${validKeys}`);
}
process.exit(1);
}
// Validate environment value
if (configKey === 'environment' && !['development', 'production'].includes(value)) {
if (options.json) {
console.log(JSON.stringify({
error: 'Environment must be either "development" or "production"'
}));
}
else {
console.error('ā Environment must be either "development" or "production"');
}
process.exit(1);
}
// Validate URL format for supabase-url
if (configKey === 'supabaseUrl' && !value.startsWith('http')) {
if (options.json) {
console.log(JSON.stringify({
error: 'Supabase URL must start with http:// or https://'
}));
}
else {
console.error('ā Supabase URL must start with http:// or https://');
}
process.exit(1);
}
// Set the configuration value
(0, config_js_1.setGlobalConfigValue)(configKey, value);
if (options.json) {
console.log(JSON.stringify({
success: true,
key: configKey,
value,
message: `Configuration ${key} set successfully`
}));
}
else {
console.log(`ā
Configuration ${key} set successfully`);
console.log(`š§ Value: ${value}`);
console.log('š” Run "alnl config status" to see updated configuration');
}
}
catch (error) {
if (options.json) {
console.log(JSON.stringify({
error: error.message
}));
}
else {
console.error(`ā Set configuration error: ${error.message}`);
}
process.exit(1);
}
});
// Add subcommands
configCommand.addCommand(statusCommand);
configCommand.addCommand(validateCommand);
configCommand.addCommand(setCommand);