Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 2 additions & 68 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"mongoose-lean-getters": "^1.1.0",
"mongoose-lean-virtuals": "^0.9.1",
"multer": "^1.4.5-lts.1",
"nest-commander": "^3.15.0",
"nestjs-dynamic-providers": "^0.3.4",
"nestjs-i18n": "^10.4.0",
"nodemailer": "^6.9.13",
Expand Down
30 changes: 28 additions & 2 deletions api/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,43 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import { NestFactory } from '@nestjs/core';
import moduleAlias from 'module-alias';
import { CommandFactory } from 'nest-commander';

moduleAlias.addAliases({
'@': __dirname,
});

import { HexabotModule } from './app.module';
import { LoggerService } from './logger/logger.service';
import { MigrationCommand } from './migration/migration.command';

const ALLOWED_COMMANDS = ['migration'];

async function bootstrap() {
await CommandFactory.run(HexabotModule);
const [command, ...restArgs] = process.argv.slice(2);
const appContext = await NestFactory.createApplicationContext(HexabotModule, {
logger: false,
});
const logger = await appContext.resolve(LoggerService);

if (!ALLOWED_COMMANDS.includes(command)) {
if (!command) {
logger.error('No command provided.');
} else {
logger.error(`Unknown command '${command}'`);
}
process.exit(1);
} else if (command === 'migration') {
const migrationCommand = appContext.get(MigrationCommand);
try {
await migrationCommand.run(restArgs);
} catch (error) {
logger.error(`Migration command failed: ${error.message}`);
process.exit(1);
}
}
await appContext.close();
}

bootstrap();
17 changes: 5 additions & 12 deletions api/src/migration/migration.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,17 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import { Command, CommandRunner } from 'nest-commander';
import { Inject } from '@nestjs/common';

import { LoggerService } from '@/logger/logger.service';

import { MigrationService } from './migration.service';
import { MigrationAction } from './types';

@Command({
name: 'migration',
description: 'Manage Mongodb Migrations',
})
export class MigrationCommand extends CommandRunner {
constructor(
private readonly logger: LoggerService,
private readonly migrationService: MigrationService,
) {
super();
}
export class MigrationCommand {
@Inject(LoggerService) logger: LoggerService;

@Inject(MigrationService) migrationService: MigrationService;

async run(passedParam: string[]): Promise<void> {
const [subcommand] = passedParam;
Expand Down