This commit is contained in:
Yassine 2025-06-26 08:18:08 +01:00 committed by GitHub
commit f0fe59f069
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 83 deletions

70
api/package-lock.json generated
View File

@ -41,7 +41,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",
@ -3634,18 +3633,6 @@
"integrity": "sha512-59SgoZ3EXbkfSX7b63tsou/SDGzwUEK6MuB5sKqgVK1/XE0fxmpsOb9DQI8LXW3KfGnAjImCGhhEb7uPPAUVNA==",
"dev": true
},
"node_modules/@golevelup/nestjs-discovery": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@golevelup/nestjs-discovery/-/nestjs-discovery-4.0.1.tgz",
"integrity": "sha512-HFXBJayEkYcU/bbxOztozONdWaZR34ZeJ2zRbZIWY8d5K26oPZQTvJ4L0STW3XVRGWtoE0WBpmx2YPNgYvcmJQ==",
"dependencies": {
"lodash": "^4.17.21"
},
"peerDependencies": {
"@nestjs/common": "^10.x",
"@nestjs/core": "^10.x"
}
},
"node_modules/@humanwhocodes/config-array": {
"version": "0.11.13",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz",
@ -6346,16 +6333,6 @@
"integrity": "sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==",
"dev": true
},
"node_modules/@types/inquirer": {
"version": "8.2.10",
"resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-8.2.10.tgz",
"integrity": "sha512-IdD5NmHyVjWM8SHWo/kPBgtzXatwPkfwzyP3fN1jF2g9BWt5WO+8hL2F4o2GKIYsU40PpqeevuUWvkS/roXJkA==",
"peer": true,
"dependencies": {
"@types/through": "*",
"rxjs": "^7.2.0"
}
},
"node_modules/@types/istanbul-lib-coverage": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz",
@ -6600,15 +6577,6 @@
"@types/superagent": "*"
}
},
"node_modules/@types/through": {
"version": "0.0.33",
"resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.33.tgz",
"integrity": "sha512-HsJ+z3QuETzP3cswwtzt2vEIiHBk/dCcHGhbmG5X3ecnwFD/lPrMpliGXxSCg03L9AhrdwA4Oz/qfspkDW+xGQ==",
"peer": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/uid-safe": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@types/uid-safe/-/uid-safe-2.1.5.tgz",
@ -8725,6 +8693,7 @@
"version": "8.3.6",
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz",
"integrity": "sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==",
"dev": true,
"dependencies": {
"import-fresh": "^3.3.0",
"js-yaml": "^4.1.0",
@ -15311,42 +15280,6 @@
"resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz",
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw=="
},
"node_modules/nest-commander": {
"version": "3.15.0",
"resolved": "https://registry.npmjs.org/nest-commander/-/nest-commander-3.15.0.tgz",
"integrity": "sha512-o9VEfFj/w2nm+hQi6fnkxL1GAFZW/KmuGcIE7/B/TX0gwm0QVy8svAF75EQm8wrDjcvWS7Cx/ArnkFn2C+iM2w==",
"dependencies": {
"@fig/complete-commander": "^3.0.0",
"@golevelup/nestjs-discovery": "4.0.1",
"commander": "11.1.0",
"cosmiconfig": "8.3.6",
"inquirer": "8.2.6"
},
"peerDependencies": {
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
"@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0",
"@types/inquirer": "^8.1.3"
}
},
"node_modules/nest-commander/node_modules/@fig/complete-commander": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/@fig/complete-commander/-/complete-commander-3.2.0.tgz",
"integrity": "sha512-1Holl3XtRiANVKURZwgpjCnPuV4RsHp+XC0MhgvyAX/avQwj7F2HUItYOvGi/bXjJCkEzgBZmVfCr0HBA+q+Bw==",
"dependencies": {
"prettier": "^3.2.5"
},
"peerDependencies": {
"commander": "^11.1.0"
}
},
"node_modules/nest-commander/node_modules/commander": {
"version": "11.1.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz",
"integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==",
"engines": {
"node": ">=16"
}
},
"node_modules/nestjs-dynamic-providers": {
"version": "0.3.4",
"resolved": "https://registry.npmjs.org/nestjs-dynamic-providers/-/nestjs-dynamic-providers-0.3.4.tgz",
@ -16212,6 +16145,7 @@
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz",
"integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==",
"dev": true,
"engines": {
"node": ">=8"
}

View File

@ -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",

View File

@ -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();

View File

@ -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;