diff --git a/package-lock.json b/package-lock.json index aa50eb6..c890f82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,22 +1,22 @@ { "name": "@athenna/core", - "version": "4.23.0", + "version": "4.24.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/core", - "version": "4.23.0", + "version": "4.24.0", "license": "MIT", "dependencies": { "pretty-repl": "^3.1.2", "semver": "^7.5.4" }, "devDependencies": { - "@athenna/artisan": "^4.28.0", + "@athenna/artisan": "^4.29.0", "@athenna/common": "^4.27.0", "@athenna/config": "^4.12.0", - "@athenna/http": "^4.17.0", + "@athenna/http": "^4.18.0", "@athenna/ioc": "^4.13.0", "@athenna/logger": "^4.14.0", "@athenna/test": "^4.18.0", @@ -97,9 +97,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", @@ -184,9 +184,9 @@ } }, "node_modules/@athenna/http": { - "version": "4.17.0", - "resolved": "https://registry.npmjs.org/@athenna/http/-/http-4.17.0.tgz", - "integrity": "sha512-F5774jY8PERvkaF+WoWjNzxYYxLdJhqgGoLJIs8dqS19dIJPmyjC57AalqCpGVZNun/o/37vXSRAWHGDoeLVpg==", + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@athenna/http/-/http-4.18.0.tgz", + "integrity": "sha512-IzThVntL8n/oUXRRO0eXG/PH1kbZo5Rs88P7goAxL1c006D5Fno1mlsi8M/5CuX+o4owNc7hCwzUPs2Q5RSoSg==", "dev": true, "engines": { "node": ">=20.0.0" diff --git a/package.json b/package.json index bcb8558..f7f03a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/core", - "version": "4.23.0", + "version": "4.24.0", "description": "The plug and play Node.js framework.", "license": "MIT", "author": "João Lenon ", @@ -76,10 +76,10 @@ "semver": "^7.5.4" }, "devDependencies": { - "@athenna/artisan": "^4.28.0", + "@athenna/artisan": "^4.29.0", "@athenna/common": "^4.27.0", "@athenna/config": "^4.12.0", - "@athenna/http": "^4.17.0", + "@athenna/http": "^4.18.0", "@athenna/ioc": "^4.13.0", "@athenna/logger": "^4.14.0", "@athenna/test": "^4.18.0", diff --git a/src/commands/MakeExceptionCommand.ts b/src/commands/MakeExceptionCommand.ts index 4e801b9..e06111e 100644 --- a/src/commands/MakeExceptionCommand.ts +++ b/src/commands/MakeExceptionCommand.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 MakeExceptionCommand extends BaseCommand { @@ -28,8 +27,13 @@ export class MakeExceptionCommand extends BaseCommand { public async handle(): Promise { this.logger.simple('({bold,green} [ MAKING EXCEPTION ])\n') + const destination = Config.get( + 'rc.commands.make:exception.destination', + Path.exceptions() + ) const file = await this.generator - .path(this.getFilePath()) + .fileName(this.name) + .destination(destination) .template('exception') .setNameProperties(true) .make() @@ -38,27 +42,4 @@ export class MakeExceptionCommand extends BaseCommand { `Exception ({yellow} "${file.name}") successfully created.` ) } - - /** - * 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:exception.destination', - Path.exceptions() - ) - - if (!isAbsolute(destination)) { - destination = resolve(Path.pwd(), destination) - } - - return destination - } } diff --git a/src/commands/MakeFacadeCommand.ts b/src/commands/MakeFacadeCommand.ts index 435605e..cfedd43 100644 --- a/src/commands/MakeFacadeCommand.ts +++ b/src/commands/MakeFacadeCommand.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 MakeFacadeCommand extends BaseCommand { @@ -28,8 +27,13 @@ export class MakeFacadeCommand extends BaseCommand { public async handle(): Promise { this.logger.simple('({bold,green} [ MAKING FACADE ])\n') + const destination = Config.get( + 'rc.commands.make:facade.destination', + Path.facades() + ) const file = await this.generator - .path(this.getFilePath()) + .fileName(this.name) + .destination(destination) .template('facade') .setNameProperties(true) .make() @@ -38,27 +42,4 @@ export class MakeFacadeCommand extends BaseCommand { `Facade ({yellow} "${file.name}") successfully created.` ) } - - /** - * 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:facade.destination', - Path.facades() - ) - - if (!isAbsolute(destination)) { - destination = resolve(Path.pwd(), destination) - } - - return destination - } } diff --git a/src/commands/MakeProviderCommand.ts b/src/commands/MakeProviderCommand.ts index 635d173..8899338 100644 --- a/src/commands/MakeProviderCommand.ts +++ b/src/commands/MakeProviderCommand.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 MakeProviderCommand extends BaseCommand { @@ -28,8 +27,13 @@ export class MakeProviderCommand extends BaseCommand { public async handle(): Promise { this.logger.simple('({bold,green} [ MAKING PROVIDER ])\n') + const destination = Config.get( + 'rc.commands.make:provider.destination', + Path.providers() + ) const file = await this.generator - .path(this.getFilePath()) + .fileName(this.name) + .destination(destination) .template('provider') .setNameProperties(true) .make() @@ -38,7 +42,7 @@ export class MakeProviderCommand extends BaseCommand { `Provider ({yellow} "${file.name}") successfully created.` ) - const importPath = this.getImportPath(file.name) + const importPath = this.generator.getImportPath() await this.rc.pushTo('providers', importPath).save() @@ -46,39 +50,4 @@ export class MakeProviderCommand extends BaseCommand { `Athenna RC updated: ({dim,yellow} [ providers += "${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:provider.destination', - Path.providers() - ) - - 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/MakeServiceCommand.ts b/src/commands/MakeServiceCommand.ts index fcf6bf2..d6645ff 100644 --- a/src/commands/MakeServiceCommand.ts +++ b/src/commands/MakeServiceCommand.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 MakeServiceCommand extends BaseCommand { @@ -28,8 +27,13 @@ export class MakeServiceCommand extends BaseCommand { public async handle(): Promise { this.logger.simple('({bold,green} [ MAKING SERVICE ])\n') + const destination = Config.get( + 'rc.commands.make:service.destination', + Path.services() + ) const file = await this.generator - .path(this.getFilePath()) + .fileName(this.name) + .destination(destination) .template('service') .setNameProperties(true) .make() @@ -38,7 +42,7 @@ export class MakeServiceCommand extends BaseCommand { `Service ({yellow} "${file.name}") successfully created.` ) - const importPath = this.getImportPath(file.name) + const importPath = this.generator.getImportPath() await this.rc.pushTo('services', importPath).save() @@ -46,39 +50,4 @@ export class MakeServiceCommand extends BaseCommand { `Athenna RC updated: ({dim,yellow} [ services += "${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:service.destination', - Path.services() - ) - - 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/MakeTestCommand.ts b/src/commands/MakeTestCommand.ts index 2f83170..c78258a 100644 --- a/src/commands/MakeTestCommand.ts +++ b/src/commands/MakeTestCommand.ts @@ -8,7 +8,6 @@ */ import { Path } from '@athenna/common' -import { sep, resolve, isAbsolute } from 'node:path' import { BaseCommand, Argument, Option } from '@athenna/artisan' export class MakeTestCommand extends BaseCommand { @@ -66,35 +65,17 @@ export class MakeTestCommand extends BaseCommand { template = 'test-fn' } + const destination = Config.get( + 'rc.commands.make:test.destination', + this.isUnit ? Path.tests('unit') : Path.tests('e2e') + ) const file = await this.generator - .path(this.getFilePath()) + .fileName(this.name) + .destination(destination) .template(template) .setNameProperties(true) .make() this.logger.success(`Test ({yellow} "${file.name}") successfully created.`) } - - /** - * 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:test.destination', - this.isUnit ? Path.tests('unit') : Path.tests('e2e') - ) - - if (!isAbsolute(destination)) { - destination = resolve(Path.pwd(), destination) - } - - return destination - } } diff --git a/src/commands/ReplCommand.ts b/src/commands/ReplCommand.ts index ac40738..24ea539 100644 --- a/src/commands/ReplCommand.ts +++ b/src/commands/ReplCommand.ts @@ -8,12 +8,9 @@ */ import { Module } from '@athenna/common' -import { BaseCommand, Option } from '@athenna/artisan' +import { BaseCommand } from '@athenna/artisan' export class ReplCommand extends BaseCommand { - @Option({ isFromGlobal: true, signature: '--env ' }) - public env: string - public static signature(): string { return 'repl' } @@ -23,9 +20,6 @@ export class ReplCommand extends BaseCommand { } public async handle(): Promise { - process.env.APP_ENV = this.env - process.env.NODE_ENV = this.env - const entrypoint = Config.get( 'rc.commands.repl.entrypoint', Path.bootstrap(`repl.${Path.ext()}`) diff --git a/src/commands/ServeCommand.ts b/src/commands/ServeCommand.ts index 5e699ee..dd25c82 100644 --- a/src/commands/ServeCommand.ts +++ b/src/commands/ServeCommand.ts @@ -13,9 +13,6 @@ import { Module } from '@athenna/common' import { BaseCommand, Option } from '@athenna/artisan' export class ServeCommand extends BaseCommand { - @Option({ isFromGlobal: true, signature: '--env ' }) - public env: string - @Option({ signature: '-w, --watch', description: 'Use nodemon to watch the application and restart on changes.', @@ -32,9 +29,6 @@ export class ServeCommand extends BaseCommand { } public async handle(): Promise { - process.env.APP_ENV = this.env - process.env.NODE_ENV = this.env - const entrypoint = Config.get( 'rc.commands.serve.entrypoint', Path.bootstrap(`main.${Path.ext()}`) diff --git a/src/commands/TestCommand.ts b/src/commands/TestCommand.ts index 240198f..1a013d4 100644 --- a/src/commands/TestCommand.ts +++ b/src/commands/TestCommand.ts @@ -8,12 +8,9 @@ */ import { Module } from '@athenna/common' -import { Option, BaseCommand, Commander } from '@athenna/artisan' +import { BaseCommand, Commander } from '@athenna/artisan' export class TestCommand extends BaseCommand { - @Option({ signature: '--env ' }) - public env: string - public static signature(): string { return 'test' } @@ -43,9 +40,6 @@ export class TestCommand extends BaseCommand { } public async handle(): Promise { - process.env.APP_ENV = this.env || 'test' - process.env.NODE_ENV = this.env || 'test' - const entrypoint = Config.get( 'rc.commands.test.entrypoint', Path.bootstrap(`test.${Path.ext()}`) diff --git a/templates/exception.edge b/templates/exception.edge index c0cd4e2..0197c62 100644 --- a/templates/exception.edge +++ b/templates/exception.edge @@ -4,8 +4,10 @@ export class {{ namePascal }} extends Exception { public constructor(message: string) { const status = 500 const help = undefined + const details = [] + const otherInfos = {} const code = 'E_{{ namePascalUpperCase }}' - super({ code, help, status, message }) + super({ code, help, status, message, details, otherInfos }) } } diff --git a/tests/unit/commands/ReplCommandTest.ts b/tests/unit/commands/ReplCommandTest.ts index 38bfe8f..edf087d 100644 --- a/tests/unit/commands/ReplCommandTest.ts +++ b/tests/unit/commands/ReplCommandTest.ts @@ -19,15 +19,6 @@ export default class ReplCommandTest extends BaseCommandTest { output.assertLogged('Hello from #bin/repl!') } - @Test() - public async shouldBeAbleToExecuteReplCommandWithADifferentEnv({ command }: Context) { - const output = await command.run('repl --env=test-hello') - - output.assertSucceeded() - output.assertLogged('Hello from #bin/repl!') - output.assertLogged('test-hello\ntest-hello') - } - @Test() public async shouldBeAbleToExecuteReplCommandUsingAImportAliasPathEntry({ command }: Context) { const output = await command.run('repl', { diff --git a/tests/unit/commands/ServeCommandTest.ts b/tests/unit/commands/ServeCommandTest.ts index 0c13957..724c381 100644 --- a/tests/unit/commands/ServeCommandTest.ts +++ b/tests/unit/commands/ServeCommandTest.ts @@ -19,15 +19,6 @@ export default class ServeCommandTest extends BaseCommandTest { output.assertLogged('Hello from #bin/main!') } - @Test() - public async shouldBeAbleToExecuteServeCommandWithADifferentEnv({ command }: Context) { - const output = await command.run('serve --env=test-hello') - - output.assertSucceeded() - output.assertLogged('Hello from #bin/main!') - output.assertLogged('test-hello\ntest-hello') - } - @Test() public async shouldBeAbleToExecuteServeCommandUsingAImportAliasPathEntry({ command }: Context) { const output = await command.run('serve', { diff --git a/tests/unit/commands/TestCommandTest.ts b/tests/unit/commands/TestCommandTest.ts index e206573..ce1a043 100644 --- a/tests/unit/commands/TestCommandTest.ts +++ b/tests/unit/commands/TestCommandTest.ts @@ -19,15 +19,6 @@ export default class TestCommandTest extends BaseCommandTest { output.assertLogged('Hello from #bin/test!') } - @Test() - public async shouldBeAbleToExecuteTestCommandWithADifferentEnv({ command }: Context) { - const output = await command.run('test --cmd --env=test-hello') - - output.assertSucceeded() - output.assertLogged('Hello from #bin/test!') - output.assertLogged('test-hello\ntest-hello') - } - @Test() public async shouldBeAbleToExecuteTestCommandAndSetJapaArgs({ command }: Context) { const output = await command.run(