Skip to content

Commit

Permalink
Merge pull request #10 from AthennaIO/develop
Browse files Browse the repository at this point in the history
feat: add tsconfig template and update http,logger and ioc
  • Loading branch information
jlenon7 authored Apr 1, 2022
2 parents 8a81e88 + 7e308d3 commit 62370de
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 36 deletions.
40 changes: 40 additions & 0 deletions _tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
2 changes: 1 addition & 1 deletion container/HttpRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

import { Router } from '@athenna/http'

export const Route = ioc.use<Router>('Athenna/Core/HttpRoute')
export const Route = ioc.safeUse<Router>('Athenna/Core/HttpRoute')
2 changes: 1 addition & 1 deletion container/HttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

import { Http } from '@athenna/http'

export const Server = ioc.use<Http>('Athenna/Core/HttpServer')
export const Server = ioc.safeUse<Http>('Athenna/Core/HttpServer')
12 changes: 12 additions & 0 deletions container/Logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @athenna/core
*
* (c) João Lenon <[email protected]>
*
* 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<ILogger>('Athenna/Core/Logger')
52 changes: 27 additions & 25 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 14 additions & 4 deletions src/Factories/AthennaFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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}`)
})
Expand All @@ -91,8 +101,8 @@ export class AthennaFactory {
}

async http(): Promise<Http> {
const http = ioc.use<Http>('Athenna/Core/HttpServer')
const route = ioc.use<Router>('Athenna/Core/HttpRoute')
const http = ioc.safeUse<Http>('Athenna/Core/HttpServer')
const route = ioc.safeUse<Router>('Athenna/Core/HttpRoute')

http.setErrorHandler(AthennaErrorHandler.http)

Expand Down
4 changes: 2 additions & 2 deletions src/Ignite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions tests/Stubs/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],

/*
Expand Down

0 comments on commit 62370de

Please sign in to comment.