faj-cli
Version:
FAJ - A powerful CLI resume builder with AI enhancement and multi-format export
181 lines ⢠7.37 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MainCommand = void 0;
const chalk_1 = __importDefault(require("chalk"));
const inquirer_1 = __importDefault(require("inquirer"));
const ora_1 = __importDefault(require("ora"));
const ConfigManager_1 = require("../../core/config/ConfigManager");
const ResumeManager_1 = require("../../core/resume/ResumeManager");
const Logger_1 = require("../../utils/Logger");
const init_1 = require("./init");
const resume_1 = require("./resume");
const promises_1 = __importDefault(require("fs/promises"));
const path_1 = __importDefault(require("path"));
class MainCommand {
logger;
configManager;
resumeManager;
initCommand;
resumeCommand;
constructor() {
this.logger = new Logger_1.Logger('MainCommand');
this.configManager = ConfigManager_1.ConfigManager.getInstance();
this.resumeManager = ResumeManager_1.ResumeManager.getInstance();
this.initCommand = new init_1.InitCommand();
this.resumeCommand = new resume_1.ResumeCommand();
}
register(program) {
// Smart main command - when user just types 'faj'
program
.action(async () => {
await this.smartMain();
});
}
async smartMain() {
try {
// Check if user has existing configuration
const hasConfig = await this.checkExistingConfig();
if (!hasConfig) {
// New user - start initialization wizard
console.log(chalk_1.default.cyan.bold('\nš Welcome to FAJ!\n'));
console.log(chalk_1.default.gray('It looks like this is your first time using FAJ.'));
console.log(chalk_1.default.gray('Let\'s create your professional resume!\n'));
const { proceed } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'proceed',
message: 'Start the resume creation wizard?',
default: true
}
]);
if (proceed) {
// Run init command - need to use the proper command interface
const { Command } = require('commander');
const program = new Command();
this.initCommand.register(program);
await program.parseAsync(['node', 'faj', 'init']);
}
}
else {
// Existing user - show menu
await this.showMainMenu();
}
}
catch (error) {
this.logger.error('Smart main command failed', error);
console.error(chalk_1.default.red('Error:'), error);
}
}
async checkExistingConfig() {
try {
const configPath = path_1.default.join(process.env.HOME || '', '.faj', 'config.json');
await promises_1.default.access(configPath);
await this.configManager.load();
const profile = await this.configManager.get('profile');
return profile !== null;
}
catch {
return false;
}
}
async showMainMenu() {
// Try to load and show resume summary
try {
const resume = await this.resumeManager.get();
if (resume) {
console.log(chalk_1.default.cyan.bold('\nš Your Resume\n'));
console.log(chalk_1.default.white(`Name: ${resume.basicInfo?.name || 'Not set'}`));
console.log(chalk_1.default.white(`Email: ${resume.basicInfo?.email || 'Not set'}`));
if (resume.content?.experience?.length > 0) {
console.log(chalk_1.default.white(`Work Experience: ${resume.content.experience.length} positions`));
}
if (resume.content?.projects?.length > 0) {
console.log(chalk_1.default.white(`Projects: ${resume.content.projects.length} projects`));
}
console.log();
}
}
catch {
// Resume not found, that's okay
}
// Show interactive menu
const { action } = await inquirer_1.default.prompt([
{
type: 'list',
name: 'action',
message: 'What would you like to do?',
choices: [
{ name: 'š View full resume', value: 'view' },
{ name: 'ā Add work experience', value: 'add-work' },
{ name: 'š Add project', value: 'add-project' },
{ name: 'š¤ Export resume', value: 'export' },
{ name: 'š§ Settings', value: 'settings' },
new inquirer_1.default.Separator(),
{ name: 'ā Exit', value: 'exit' }
]
}
]);
switch (action) {
case 'view':
// Use the proper command interface
const { Command } = require('commander');
const program = new Command();
this.resumeCommand.register(program);
await program.parseAsync(['node', 'faj', 'resume', 'show']);
await this.showMainMenu(); // Return to menu
break;
case 'add-work':
console.log(chalk_1.default.cyan('\nUse: faj add work'));
break;
case 'add-project':
console.log(chalk_1.default.cyan('\nUse: faj add project <path>'));
break;
case 'export':
await this.exportResume();
await this.showMainMenu(); // Return to menu
break;
case 'settings':
console.log(chalk_1.default.cyan('\nUse: faj config'));
break;
case 'exit':
console.log(chalk_1.default.gray('Goodbye!'));
break;
}
}
async exportResume() {
const { format } = await inquirer_1.default.prompt([
{
type: 'list',
name: 'format',
message: 'Select export format:',
choices: [
{ name: 'Markdown (.md)', value: 'md' },
{ name: 'HTML (.html)', value: 'html' }
],
default: 'md'
}
]);
const { filename } = await inquirer_1.default.prompt([
{
type: 'input',
name: 'filename',
message: 'Export filename:',
default: `resume.${format}`
}
]);
const spinner = (0, ora_1.default)(`Exporting to ${filename}...`).start();
try {
const content = await this.resumeManager.export(format);
await promises_1.default.writeFile(filename, content);
spinner.succeed(`Resume exported to ${filename}`);
}
catch (error) {
spinner.fail(`Export failed: ${error.message}`);
}
}
}
exports.MainCommand = MainCommand;
//# sourceMappingURL=main.js.map
;