Initial Commit ...
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
// src/index.ts
|
||||
import chalk from 'chalk';
|
||||
import { join } from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
import { Command } from 'commander';
|
||||
import { registerGenerateCommand } from './commands/generate';
|
||||
import { registerProjectCommand } from './commands/project';
|
||||
import { registerManifestCommand } from './commands/manifest';
|
||||
import { registerAddCommand } from './commands/add';
|
||||
import { registerConfigCommand } from './commands/config';
|
||||
import { registerDoctorCommand } from './commands/doctor';
|
||||
import { registerNewCommand } from './commands/new';
|
||||
// import { registerAddCommand } from './commands/add';
|
||||
// import { registerBuildCommand } from './commands/build';
|
||||
// import { registerConfigCommand } from './commands/config';
|
||||
// import { registerDoctorCommand } from './commands/doctor';
|
||||
// import { registerGenerateCommand } from './commands/generate';
|
||||
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(join(__dirname, '..', 'package.json'), 'utf-8')
|
||||
);
|
||||
|
||||
const program = new Command();
|
||||
program
|
||||
.name('xcli')
|
||||
.description('CLI for xFramework application scaffolding & management')
|
||||
.version(pkg.version, '-v, --version', 'output the current version');
|
||||
|
||||
// ثبت زیردستورات
|
||||
registerGenerateCommand(program);
|
||||
registerProjectCommand(program);
|
||||
registerManifestCommand(program);
|
||||
registerAddCommand(program);
|
||||
registerConfigCommand(program);
|
||||
registerNewCommand(program);
|
||||
registerDoctorCommand(program);
|
||||
// registerGenerateCommand(program);
|
||||
// registerAddCommand(program);
|
||||
// registerConfigCommand(program);
|
||||
// registerBuildCommand(program);
|
||||
// registerDoctorCommand(program);
|
||||
|
||||
// دستور پیشفرض
|
||||
program
|
||||
.command('help [command]')
|
||||
.description('display help for xcli or a specific command')
|
||||
.action((cmd) => {
|
||||
if (cmd) {
|
||||
const sub = program.commands.find((c) => c.name() === cmd);
|
||||
if (sub) {
|
||||
sub.help();
|
||||
} else {
|
||||
console.log(chalk.red(`Unknown command: ${cmd}`));
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
program.help();
|
||||
}
|
||||
});
|
||||
|
||||
// مدیریت خطاها
|
||||
process.on('unhandledRejection', (err: any) => {
|
||||
console.error(chalk.red('\n💥 Unexpected error:'), err?.message || err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// پارس آرگومانها
|
||||
program.parseAsync(process.argv).catch((err) => {
|
||||
console.error(chalk.red(err.message));
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user