@diagramers/cli
Version:
Diagramers CLI - Command-line tools for managing Diagramers projects
82 lines • 4.28 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.extendCommand = extendCommand;
const project_extender_1 = require("../services/project-extender");
const chalk_1 = __importDefault(require("chalk"));
function extendCommand(program) {
program
.command('extend')
.description('Extend project with additional features and modules')
.option('-f, --feature <feature>', 'Feature to add (auth, email, socket, etc.)')
.option('-m, --module <module>', 'Generate new module with full CRUD operations')
.option('-t, --table <table>', 'Generate database table/collection')
.option('-r, --relation <relation>', 'Generate database relations')
.option('-l, --list', 'List available features and templates')
.option('--crud', 'Generate full CRUD operations for module')
.option('--fields <fields>', 'Comma-separated list of fields for module/table')
.option('--type <type>', 'Database type (mongodb, mysql, postgres)')
.action(async (options) => {
try {
if (options.list) {
const extender = new project_extender_1.ProjectExtender();
await extender.listFeatures();
return;
}
const extender = new project_extender_1.ProjectExtender();
// Generate new module
if (options.module) {
console.log(chalk_1.default.blue(`🔧 Generating module: ${options.module}`));
await extender.generateModule(options.module, {
crud: options.crud,
fields: options.fields?.split(','),
type: options.type || 'mongodb'
});
console.log(chalk_1.default.green(`✅ Module ${options.module} generated successfully!`));
return;
}
// Generate database table
if (options.table) {
console.log(chalk_1.default.blue(`🗄️ Generating table: ${options.table}`));
await extender.generateTable(options.table, {
fields: options.fields?.split(','),
type: options.type || 'mongodb'
});
console.log(chalk_1.default.green(`✅ Table ${options.table} generated successfully!`));
return;
}
// Generate database relations
if (options.relation) {
console.log(chalk_1.default.blue(`🔗 Generating relations for: ${options.relation}`));
// Parse relation parameters (format: table1-table2:type)
const relationParts = options.relation.split(':');
const tables = relationParts[0].split('-');
const relationType = relationParts[1] || 'one-to-one';
if (tables.length !== 2) {
throw new Error('Relation format should be: table1-table2:type (e.g., user-posts:one-to-many)');
}
const [table1, table2] = tables;
// Import and call the relation generator
const { generateRelation } = require('../services/relation-generator');
await generateRelation(table1, table2, relationType);
}
// Add feature (legacy support)
if (options.feature) {
console.log(chalk_1.default.blue(`🔧 Adding feature: ${options.feature}`));
await extender.addFeature(options.feature);
console.log(chalk_1.default.green(`✅ Feature ${options.feature} added successfully!`));
return;
}
console.log(chalk_1.default.red('❌ Please specify what to generate: --module, --table, --relation, or --feature'));
console.log(chalk_1.default.yellow('💡 Use --list to see available options'));
process.exit(1);
}
catch (error) {
console.error(chalk_1.default.red(`❌ Failed to extend project: ${error.message}`));
process.exit(1);
}
});
}
//# sourceMappingURL=extend.js.map