diff --git a/package-lock.json b/package-lock.json index 01e9a83..682d3a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@athenna/http", - "version": "4.17.0", + "version": "4.18.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/http", - "version": "4.17.0", + "version": "4.18.0", "license": "MIT", "devDependencies": { - "@athenna/artisan": "^4.28.0", + "@athenna/artisan": "^4.30.0", "@athenna/common": "^4.27.0", "@athenna/config": "^4.12.0", "@athenna/ioc": "^4.13.0", @@ -70,9 +70,9 @@ "dev": true }, "node_modules/@athenna/artisan": { - "version": "4.28.0", - "resolved": "https://registry.npmjs.org/@athenna/artisan/-/artisan-4.28.0.tgz", - "integrity": "sha512-TnmFTSs+JbKIvPe0+NVSlQ+LgnDCiOE8mR6b7GwR8GPq5QRTKwCVDprfufHfhmUd4TzDTOUFVTFT8KdFvK/lJA==", + "version": "4.30.0", + "resolved": "https://registry.npmjs.org/@athenna/artisan/-/artisan-4.30.0.tgz", + "integrity": "sha512-BBL4lJYmcDp7oqYCIkWiakA6Ww7P5Pi26IM1yQ5SnrXTwUF9yOCJSspxZCKYN4jDE6OhEExuntnOJyYIrwEpvA==", "dev": true, "dependencies": { "chalk-rainbow": "^1.0.0", diff --git a/package.json b/package.json index c6ae9ef..308a916 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/http", - "version": "4.17.0", + "version": "4.18.0", "description": "The Athenna Http server. Built on top of fastify.", "license": "MIT", "author": "João Lenon ", @@ -72,7 +72,7 @@ "#tests": "./tests/index.js" }, "devDependencies": { - "@athenna/artisan": "^4.28.0", + "@athenna/artisan": "^4.30.0", "@athenna/common": "^4.27.0", "@athenna/config": "^4.12.0", "@athenna/ioc": "^4.13.0", diff --git a/src/commands/MakeControllerCommand.ts b/src/commands/MakeControllerCommand.ts index 18dfc62..92813bb 100644 --- a/src/commands/MakeControllerCommand.ts +++ b/src/commands/MakeControllerCommand.ts @@ -8,7 +8,6 @@ */ import { Path } from '@athenna/common' -import { sep, resolve, isAbsolute } from 'node:path' import { BaseCommand, Argument } from '@athenna/artisan' export class MakeControllerCommand extends BaseCommand { @@ -28,8 +27,14 @@ export class MakeControllerCommand extends BaseCommand { public async handle(): Promise { this.logger.simple('({bold,green} [ MAKING CONTROLLER ])\n') + const destination = Config.get( + 'rc.commands.make:controller.destination', + Path.controllers() + ) + const file = await this.generator - .path(this.getFilePath()) + .fileName(this.name) + .destination(destination) .template('controller') .setNameProperties(true) .make() @@ -38,7 +43,7 @@ export class MakeControllerCommand extends BaseCommand { `Controller ({yellow} "${file.name}") successfully created.` ) - const importPath = this.getImportPath(file.name) + const importPath = this.generator.getImportPath() await this.rc.pushTo('controllers', importPath).save() @@ -46,39 +51,4 @@ export class MakeControllerCommand extends BaseCommand { `Athenna RC updated: ({dim,yellow} [ controllers += "${importPath}" ])` ) } - - /** - * Get the file path where it will be generated. - */ - private getFilePath(): string { - return this.getDestinationPath().concat(`${sep}${this.name}.${Path.ext()}`) - } - - /** - * Get the destination path for the file that will be generated. - */ - private getDestinationPath(): string { - let destination = Config.get( - 'rc.commands.make:controller.destination', - Path.controllers() - ) - - if (!isAbsolute(destination)) { - destination = resolve(Path.pwd(), destination) - } - - return destination - } - - /** - * Get the import path that should be registered in RC file. - */ - private getImportPath(fileName: string): string { - const destination = this.getDestinationPath() - - return `${destination - .replace(Path.pwd(), '') - .replace(/\\/g, '/') - .replace('/', '#')}/${fileName}` - } } diff --git a/src/commands/MakeInterceptorCommand.ts b/src/commands/MakeInterceptorCommand.ts index e51e93f..71bdac4 100644 --- a/src/commands/MakeInterceptorCommand.ts +++ b/src/commands/MakeInterceptorCommand.ts @@ -8,7 +8,6 @@ */ import { Path } from '@athenna/common' -import { sep, resolve, isAbsolute } from 'node:path' import { BaseCommand, Argument } from '@athenna/artisan' export class MakeInterceptorCommand extends BaseCommand { @@ -28,8 +27,14 @@ export class MakeInterceptorCommand extends BaseCommand { public async handle(): Promise { this.logger.simple('({bold,green} [ MAKING INTERCEPTOR ])\n') + const destination = Config.get( + 'rc.commands.make:interceptor.destination', + Path.interceptors() + ) + const file = await this.generator - .path(this.getFilePath()) + .fileName(this.name) + .destination(destination) .template('interceptor') .setNameProperties(true) .make() @@ -38,7 +43,7 @@ export class MakeInterceptorCommand extends BaseCommand { `Interceptor ({yellow} "${file.name}") successfully created.` ) - const importPath = this.getImportPath(file.name) + const importPath = this.generator.getImportPath() await this.rc.pushTo('middlewares', importPath).save() @@ -46,39 +51,4 @@ export class MakeInterceptorCommand extends BaseCommand { `Athenna RC updated: ({dim,yellow} [ middlewares += "${importPath}" ])` ) } - - /** - * Get the file path where it will be generated. - */ - private getFilePath(): string { - return this.getDestinationPath().concat(`${sep}${this.name}.${Path.ext()}`) - } - - /** - * Get the destination path for the file that will be generated. - */ - private getDestinationPath(): string { - let destination = Config.get( - 'rc.commands.make:interceptor.destination', - Path.interceptors() - ) - - if (!isAbsolute(destination)) { - destination = resolve(Path.pwd(), destination) - } - - return destination - } - - /** - * Get the import path that should be registered in RC file. - */ - private getImportPath(fileName: string): string { - const destination = this.getDestinationPath() - - return `${destination - .replace(Path.pwd(), '') - .replace(/\\/g, '/') - .replace('/', '#')}/${fileName}` - } } diff --git a/src/commands/MakeMiddlewareCommand.ts b/src/commands/MakeMiddlewareCommand.ts index 23e3449..a897e69 100644 --- a/src/commands/MakeMiddlewareCommand.ts +++ b/src/commands/MakeMiddlewareCommand.ts @@ -8,7 +8,6 @@ */ import { Path } from '@athenna/common' -import { sep, resolve, isAbsolute } from 'node:path' import { BaseCommand, Argument } from '@athenna/artisan' export class MakeMiddlewareCommand extends BaseCommand { @@ -28,8 +27,14 @@ export class MakeMiddlewareCommand extends BaseCommand { public async handle(): Promise { this.logger.simple('({bold,green} [ MAKING MIDDLEWARE ])\n') + const destination = Config.get( + 'rc.commands.make:middleware.destination', + Path.middlewares() + ) + const file = await this.generator - .path(this.getFilePath()) + .fileName(this.name) + .destination(destination) .template('middleware') .setNameProperties(true) .make() @@ -38,7 +43,7 @@ export class MakeMiddlewareCommand extends BaseCommand { `Middleware ({yellow} "${file.name}") successfully created.` ) - const importPath = this.getImportPath(file.name) + const importPath = this.generator.getImportPath() await this.rc.pushTo('middlewares', importPath).save() @@ -46,39 +51,4 @@ export class MakeMiddlewareCommand extends BaseCommand { `Athenna RC updated: ({dim,yellow} [ middlewares += "${importPath}" ])` ) } - - /** - * Get the file path where it will be generated. - */ - private getFilePath(): string { - return this.getDestinationPath().concat(`${sep}${this.name}.${Path.ext()}`) - } - - /** - * Get the destination path for the file that will be generated. - */ - private getDestinationPath(): string { - let destination = Config.get( - 'rc.commands.make:middleware.destination', - Path.middlewares() - ) - - if (!isAbsolute(destination)) { - destination = resolve(Path.pwd(), destination) - } - - return destination - } - - /** - * Get the import path that should be registered in RC file. - */ - private getImportPath(fileName: string): string { - const destination = this.getDestinationPath() - - return `${destination - .replace(Path.pwd(), '') - .replace(/\\/g, '/') - .replace('/', '#')}/${fileName}` - } } diff --git a/src/commands/MakeTerminatorCommand.ts b/src/commands/MakeTerminatorCommand.ts index 9a38563..e4a5d57 100644 --- a/src/commands/MakeTerminatorCommand.ts +++ b/src/commands/MakeTerminatorCommand.ts @@ -8,7 +8,6 @@ */ import { Path } from '@athenna/common' -import { sep, resolve, isAbsolute } from 'node:path' import { BaseCommand, Argument } from '@athenna/artisan' export class MakeTerminatorCommand extends BaseCommand { @@ -28,8 +27,14 @@ export class MakeTerminatorCommand extends BaseCommand { public async handle(): Promise { this.logger.simple('({bold,green} [ MAKING TERMINATOR ])\n') + const destination = Config.get( + 'rc.commands.make:terminator.destination', + Path.terminators() + ) + const file = await this.generator - .path(this.getFilePath()) + .fileName(this.name) + .destination(destination) .template('terminator') .setNameProperties(true) .make() @@ -38,7 +43,7 @@ export class MakeTerminatorCommand extends BaseCommand { `Terminator ({yellow} "${file.name}") successfully created.` ) - const importPath = this.getImportPath(file.name) + const importPath = this.generator.getImportPath() await this.rc.pushTo('middlewares', importPath).save() @@ -46,39 +51,4 @@ export class MakeTerminatorCommand extends BaseCommand { `Athenna RC updated: ({dim,yellow} [ middlewares += "${importPath}" ])` ) } - - /** - * Get the file path where it will be generated. - */ - private getFilePath(): string { - return this.getDestinationPath().concat(`${sep}${this.name}.${Path.ext()}`) - } - - /** - * Get the destination path for the file that will be generated. - */ - private getDestinationPath(): string { - let destination = Config.get( - 'rc.commands.make:terminator.destination', - Path.terminators() - ) - - if (!isAbsolute(destination)) { - destination = resolve(Path.pwd(), destination) - } - - return destination - } - - /** - * Get the import path that should be registered in RC file. - */ - private getImportPath(fileName: string): string { - const destination = this.getDestinationPath() - - return `${destination - .replace(Path.pwd(), '') - .replace(/\\/g, '/') - .replace('/', '#')}/${fileName}` - } }