From 7e308d38f1858464dc5cd402c254875151e30f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Fri, 1 Apr 2022 00:32:10 -0300 Subject: [PATCH] feat: add tsconfig template and update http,logger and ioc --- _tsconfig.json | 40 +++++++++++++++++++++++++ container/HttpRoute.ts | 2 +- container/HttpServer.ts | 2 +- container/Logger.ts | 12 ++++++++ package-lock.json | 52 +++++++++++++++++---------------- package.json | 6 ++-- src/Factories/AthennaFactory.ts | 18 +++++++++--- src/Ignite.ts | 4 +-- tests/Stubs/config/app.ts | 1 + 9 files changed, 101 insertions(+), 36 deletions(-) create mode 100644 _tsconfig.json create mode 100644 container/Logger.ts diff --git a/_tsconfig.json b/_tsconfig.json new file mode 100644 index 0000000..cd24079 --- /dev/null +++ b/_tsconfig.json @@ -0,0 +1,40 @@ +{ + "compilerOptions": { + "outDir": "../../../dist", + "rootDir": "../../../.", + "baseUrl": "../../../.", + "target": "es2020", + "module": "commonjs", + "lib": ["es2020"], + "moduleResolution": "node", + "declaration": true, + "strictNullChecks": true, + "noImplicitAny": false, + "removeComments": false, + "noUnusedLocals": true, + "noUnusedParameters": true, + "esModuleInterop": true, + "skipLibCheck": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "paths": { + "app/*": ["app/*"], + "bootstrap/*": ["bootstrap/*"], + "config/*": ["config/*"], + "database/*": ["database/*"], + "lang/*": ["lang/*"], + "providers/*": ["providers/*"], + "routes/*": ["routes/*"], + "storage/*": ["storage/*"], + "../../../tests/*": ["../../../tests/*"] + }, + "forceConsistentCasingInFileNames": true + }, + "include": ["../../../*.ts", "../../../**/*.ts"], + "exclude": [ + "../../../node_modules", + "../../../build", + "../../../dist", + "../../../tests" + ] +} diff --git a/container/HttpRoute.ts b/container/HttpRoute.ts index 62cada2..550d3f1 100644 --- a/container/HttpRoute.ts +++ b/container/HttpRoute.ts @@ -9,4 +9,4 @@ import { Router } from '@athenna/http' -export const Route = ioc.use('Athenna/Core/HttpRoute') +export const Route = ioc.safeUse('Athenna/Core/HttpRoute') diff --git a/container/HttpServer.ts b/container/HttpServer.ts index 0510143..eaa540c 100644 --- a/container/HttpServer.ts +++ b/container/HttpServer.ts @@ -9,4 +9,4 @@ import { Http } from '@athenna/http' -export const Server = ioc.use('Athenna/Core/HttpServer') +export const Server = ioc.safeUse('Athenna/Core/HttpServer') diff --git a/container/Logger.ts b/container/Logger.ts new file mode 100644 index 0000000..28565f7 --- /dev/null +++ b/container/Logger.ts @@ -0,0 +1,12 @@ +/** + * @athenna/core + * + * (c) João Lenon + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { Logger as ILogger } from '@athenna/logger' + +export const Logger = ioc.safeUse('Athenna/Core/Logger') diff --git a/package-lock.json b/package-lock.json index d5b829b..b75d97c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "@athenna/core", - "version": "1.0.6", + "version": "1.0.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@athenna/core", - "version": "1.0.6", + "version": "1.0.8", "license": "MIT", "dependencies": { "@athenna/config": "1.0.5", - "@athenna/http": "1.0.8", - "@athenna/ioc": "1.0.6", - "@athenna/logger": "1.0.4", + "@athenna/http": "1.0.9", + "@athenna/ioc": "1.0.7", + "@athenna/logger": "1.0.5", "@secjs/utils": "1.8.0", "reflect-metadata": "0.1.13", "tscpaths": "0.0.9" @@ -71,12 +71,12 @@ } }, "node_modules/@athenna/http": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/@athenna/http/-/http-1.0.8.tgz", - "integrity": "sha512-iqBI/0JZVMNrtCvCNsL3O/SRfxjhAXsU0fTVSkq8RlH7kykdK8PPJjMyfwbSnc+lWku27whbVRvDKTJ7R5R3jA==", + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@athenna/http/-/http-1.0.9.tgz", + "integrity": "sha512-FORd7BR0HD31IpOYpo9C7+HDJEQjYVMEU56OOoMvEhAXxxXixuWZc1ftL/RHSJ/uUXeNDKXaVQgYfuiyYKmnnA==", "dependencies": { "@athenna/config": "1.0.5", - "@athenna/ioc": "1.0.6", + "@athenna/ioc": "1.0.7", "@secjs/utils": "1.8.0", "fastify": "3.27.4", "reflect-metadata": "0.1.13", @@ -84,9 +84,9 @@ } }, "node_modules/@athenna/ioc": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@athenna/ioc/-/ioc-1.0.6.tgz", - "integrity": "sha512-vNlk7+penNKd61eFIHk7OSjor6HM1CO5c9ggUPcO37qvim9w7ZAyMmuMDJ1pSfgtwKsysOgxkMFyWtbpvkGWpA==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@athenna/ioc/-/ioc-1.0.7.tgz", + "integrity": "sha512-FpryJ1/IdoWa4ApfAtji62jUSjKOLSOsrUAhOU5dFVg65Zd5OtyIqn5DNuaRjSLDkBSLtm1H/8JmhvZDDCO/cA==", "dependencies": { "@secjs/utils": "1.7.8", "awilix": "7.0.0", @@ -201,10 +201,11 @@ } }, "node_modules/@athenna/logger": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@athenna/logger/-/logger-1.0.4.tgz", - "integrity": "sha512-m+8qSYzoCUFP0GwbIywaOheXJNbinAn5DIsngI3GT3T0dvY3AYjQ6Vx8qEDSeiNL31fFODpcVX61L9wp+ub93g==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@athenna/logger/-/logger-1.0.5.tgz", + "integrity": "sha512-dtG0pggRrUiIRjfwhQhEX0LthooUTDBnp657w/uL89BteqzLcrtLe464JZUO3uqmW9dTaPrzUaO0DoL4a1knqA==", "dependencies": { + "@athenna/ioc": "1.0.7", "@secjs/utils": "1.8.0", "reflect-metadata": "0.1.13", "tscpaths": "0.0.9" @@ -13504,12 +13505,12 @@ } }, "@athenna/http": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/@athenna/http/-/http-1.0.8.tgz", - "integrity": "sha512-iqBI/0JZVMNrtCvCNsL3O/SRfxjhAXsU0fTVSkq8RlH7kykdK8PPJjMyfwbSnc+lWku27whbVRvDKTJ7R5R3jA==", + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@athenna/http/-/http-1.0.9.tgz", + "integrity": "sha512-FORd7BR0HD31IpOYpo9C7+HDJEQjYVMEU56OOoMvEhAXxxXixuWZc1ftL/RHSJ/uUXeNDKXaVQgYfuiyYKmnnA==", "requires": { "@athenna/config": "1.0.5", - "@athenna/ioc": "1.0.6", + "@athenna/ioc": "1.0.7", "@secjs/utils": "1.8.0", "fastify": "3.27.4", "reflect-metadata": "0.1.13", @@ -13517,9 +13518,9 @@ } }, "@athenna/ioc": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@athenna/ioc/-/ioc-1.0.6.tgz", - "integrity": "sha512-vNlk7+penNKd61eFIHk7OSjor6HM1CO5c9ggUPcO37qvim9w7ZAyMmuMDJ1pSfgtwKsysOgxkMFyWtbpvkGWpA==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@athenna/ioc/-/ioc-1.0.7.tgz", + "integrity": "sha512-FpryJ1/IdoWa4ApfAtji62jUSjKOLSOsrUAhOU5dFVg65Zd5OtyIqn5DNuaRjSLDkBSLtm1H/8JmhvZDDCO/cA==", "requires": { "@secjs/utils": "1.7.8", "awilix": "7.0.0", @@ -13609,10 +13610,11 @@ } }, "@athenna/logger": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@athenna/logger/-/logger-1.0.4.tgz", - "integrity": "sha512-m+8qSYzoCUFP0GwbIywaOheXJNbinAn5DIsngI3GT3T0dvY3AYjQ6Vx8qEDSeiNL31fFODpcVX61L9wp+ub93g==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@athenna/logger/-/logger-1.0.5.tgz", + "integrity": "sha512-dtG0pggRrUiIRjfwhQhEX0LthooUTDBnp657w/uL89BteqzLcrtLe464JZUO3uqmW9dTaPrzUaO0DoL4a1knqA==", "requires": { + "@athenna/ioc": "1.0.7", "@secjs/utils": "1.8.0", "reflect-metadata": "0.1.13", "tscpaths": "0.0.9" diff --git a/package.json b/package.json index eb6973f..4d25cbb 100644 --- a/package.json +++ b/package.json @@ -162,9 +162,9 @@ }, "dependencies": { "@athenna/config": "1.0.5", - "@athenna/ioc": "1.0.6", - "@athenna/logger": "1.0.4", - "@athenna/http": "1.0.8", + "@athenna/ioc": "1.0.7", + "@athenna/logger": "1.0.5", + "@athenna/http": "1.0.9", "@secjs/utils": "1.8.0", "reflect-metadata": "0.1.13", "tscpaths": "0.0.9" diff --git a/src/Factories/AthennaFactory.ts b/src/Factories/AthennaFactory.ts index e8cab7d..b01cf89 100644 --- a/src/Factories/AthennaFactory.ts +++ b/src/Factories/AthennaFactory.ts @@ -17,7 +17,7 @@ import { ResolveClassExport } from 'src/Utils/ResolveClassExport' import { AthennaErrorHandler } from 'src/Utils/AthennaErrorHandler' export class AthennaFactory { - private static logger: Logger + private static logger: any private static extension: '.js' | '.ts' constructor(fileName: string) { @@ -38,6 +38,16 @@ export class AthennaFactory { }, }) + if ( + !Env('APP_DEBUG') && + (Env('NODE_ENV') === 'test' || Env('NODE_ENV') === 'testing') + ) { + AthennaFactory.logger = { + log: () => {}, + error: () => {}, + } + } + const providers = AthennaFactory.getProviders() AthennaFactory.registerProviders(providers) @@ -75,7 +85,7 @@ export class AthennaFactory { preload = normalize(preload) const { dir, name } = parse(Path.config(preload)) - AthennaFactory.logger.log(`Preloading ${preload} file`) + AthennaFactory.logger.log(`Preloading ${name} file`) require(`${dir}/${name}${this.extension}`) }) @@ -91,8 +101,8 @@ export class AthennaFactory { } async http(): Promise { - const http = ioc.use('Athenna/Core/HttpServer') - const route = ioc.use('Athenna/Core/HttpRoute') + const http = ioc.safeUse('Athenna/Core/HttpServer') + const route = ioc.safeUse('Athenna/Core/HttpRoute') http.setErrorHandler(AthennaErrorHandler.http) diff --git a/src/Ignite.ts b/src/Ignite.ts index 5bae0a2..399fc20 100644 --- a/src/Ignite.ts +++ b/src/Ignite.ts @@ -8,9 +8,9 @@ */ /** - * Importing global file to add Env function - * and Config class to global module of Node.js + * Importing global files to be added to global module of Node.js */ +import '@athenna/ioc' import '@athenna/config/src/Utils/global' import { Http } from '@athenna/http' diff --git a/tests/Stubs/config/app.ts b/tests/Stubs/config/app.ts index f10146b..2a41d49 100644 --- a/tests/Stubs/config/app.ts +++ b/tests/Stubs/config/app.ts @@ -158,6 +158,7 @@ export default { providers: [ require('@athenna/http/src/Providers/HttpServerProvider'), require('@athenna/http/src/Providers/HttpRouteProvider'), + require('@athenna/logger/src/Providers/LoggerProvider'), ], /*