generated from AthennaIO/Template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add middleware command and lint option
- Loading branch information
Showing
8 changed files
with
228 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @athenna/cli | ||
* | ||
* (c) Victor Tesoura Júnior <txsoura@athenna.io> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import ora from 'ora' | ||
import { promisify } from 'util' | ||
import { NodeExecException } from '../Exceptions/NodeExecException' | ||
|
||
const exec = promisify(require('child_process').exec) | ||
|
||
export async function runCommand(command: string, log?: string) { | ||
const spinner = ora(log) | ||
|
||
if (log) { | ||
spinner.color = 'yellow' | ||
|
||
spinner.start() | ||
} | ||
|
||
try { | ||
await exec(command) | ||
|
||
if (log) spinner.succeed(log) | ||
} catch (err) { | ||
// console.log(err) | ||
if (log) spinner.fail(log) | ||
|
||
throw new NodeExecException(command) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { MiddlewareContract } from '@athenna/http' | ||
|
||
export class <%= namePascal %>Middleware implements MiddlewareContract { | ||
/** | ||
* Use the constructor to resolve any dependency of the Ioc container | ||
* | ||
* @param container | ||
* @return <%= namePascal %>Middleware | ||
*/ | ||
constructor(_container) {} | ||
|
||
/** | ||
* Handle method is executed before the request gets in your controller. | ||
* | ||
* @param ctx | ||
* @return any | ||
*/ | ||
async handle({ next }) { | ||
next() | ||
} | ||
|
||
/** | ||
* Intercept method is executed before the response has been sent. | ||
* | ||
* @param ctx | ||
* @return any | ||
*/ | ||
async intercept({ body }) { | ||
body.intercepted = true | ||
|
||
return body | ||
} | ||
|
||
/** | ||
* Terminate method is executed after the response has been sent. | ||
* | ||
* @param ctx | ||
* @return any | ||
*/ | ||
async terminate({ next }) { | ||
next() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
HandleContextContract, | ||
InterceptContextContract, | ||
TerminateContextContract, | ||
MiddlewareContract, | ||
} from '@athenna/http' | ||
|
||
import { Container } from 'providers/Container' | ||
|
||
export class <%= namePascal %>Middleware implements MiddlewareContract { | ||
/** | ||
* Use the constructor to resolve any dependency of the Ioc container | ||
* | ||
* @param container | ||
* @return <%= namePascal %>Middleware | ||
*/ | ||
constructor(_container: Container) {} | ||
|
||
/** | ||
* Handle method is executed before the request gets in your controller. | ||
* | ||
* @param ctx | ||
* @return any | ||
*/ | ||
async handle({ next }: HandleContextContract) { | ||
next() | ||
} | ||
|
||
/** | ||
* Intercept method is executed before the response has been sent. | ||
* | ||
* @param ctx | ||
* @return any | ||
*/ | ||
async intercept({ body }: InterceptContextContract) { | ||
body.intercepted = true | ||
|
||
return body | ||
} | ||
|
||
/** | ||
* Terminate method is executed after the response has been sent. | ||
* | ||
* @param ctx | ||
* @return any | ||
*/ | ||
async terminate({ next }: TerminateContextContract) { | ||
next() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters