From e7120c8fd95c14aa280893056cb4809231398a0a Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Fri, 5 Jan 2024 23:50:00 +0000 Subject: [PATCH] feat(commands): use env flag from global --- package-lock.json | 12 ++++++------ package.json | 4 ++-- src/commands/ReplCommand.ts | 12 +++--------- src/commands/ServeCommand.ts | 12 +++--------- src/commands/TestCommand.ts | 12 +++--------- src/ignite/Ignite.ts | 3 +++ 6 files changed, 20 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index dcc35f2..3ce8447 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,19 @@ { "name": "@athenna/core", - "version": "4.16.0", + "version": "4.17.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/core", - "version": "4.16.0", + "version": "4.17.0", "license": "MIT", "dependencies": { "pretty-repl": "^3.1.2", "semver": "^7.5.4" }, "devDependencies": { - "@athenna/artisan": "^4.21.0", + "@athenna/artisan": "^4.24.0", "@athenna/common": "^4.24.0", "@athenna/config": "^4.10.0", "@athenna/http": "^4.15.0", @@ -97,9 +97,9 @@ "dev": true }, "node_modules/@athenna/artisan": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@athenna/artisan/-/artisan-4.21.0.tgz", - "integrity": "sha512-mJzT7cL5jKzAUOs3NABwSf9hJ74XZQbOfC0NYCTdHLhpw5vuI+uKY3VOPKLffvQg47UUgeBV8s76/Ae6WDy/6Q==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@athenna/artisan/-/artisan-4.24.0.tgz", + "integrity": "sha512-bp5uU/DvviGAfQcKWPwmFhsl5/CrX+ONNXz0Jt9VGxIzKwtEaaDNZBV3LsVzWY2x7XWnKSLt22vKXRO/CL/jqg==", "dev": true, "dependencies": { "chalk-rainbow": "^1.0.0", diff --git a/package.json b/package.json index 5dbc5da..1fd2021 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/core", - "version": "4.16.0", + "version": "4.17.0", "description": "The plug and play Node.js framework.", "license": "MIT", "author": "João Lenon ", @@ -76,7 +76,7 @@ "semver": "^7.5.4" }, "devDependencies": { - "@athenna/artisan": "^4.21.0", + "@athenna/artisan": "^4.24.0", "@athenna/common": "^4.24.0", "@athenna/config": "^4.10.0", "@athenna/http": "^4.15.0", diff --git a/src/commands/ReplCommand.ts b/src/commands/ReplCommand.ts index 9da900d..ac40738 100644 --- a/src/commands/ReplCommand.ts +++ b/src/commands/ReplCommand.ts @@ -11,11 +11,7 @@ import { Module } from '@athenna/common' import { BaseCommand, Option } from '@athenna/artisan' export class ReplCommand extends BaseCommand { - @Option({ - signature: '-e, --env ', - description: 'Change the environment where the application will run.', - default: '' - }) + @Option({ isFromGlobal: true, signature: '--env ' }) public env: string public static signature(): string { @@ -27,10 +23,8 @@ export class ReplCommand extends BaseCommand { } public async handle(): Promise { - if (this.env !== '') { - process.env.APP_ENV = this.env - process.env.NODE_ENV = this.env - } + process.env.APP_ENV = this.env + process.env.NODE_ENV = this.env const entrypoint = Config.get( 'rc.commands.repl.entrypoint', diff --git a/src/commands/ServeCommand.ts b/src/commands/ServeCommand.ts index c79bf9d..5e699ee 100644 --- a/src/commands/ServeCommand.ts +++ b/src/commands/ServeCommand.ts @@ -13,11 +13,7 @@ import { Module } from '@athenna/common' import { BaseCommand, Option } from '@athenna/artisan' export class ServeCommand extends BaseCommand { - @Option({ - signature: '-e, --env ', - description: 'Change the environment where the application will run.', - default: '' - }) + @Option({ isFromGlobal: true, signature: '--env ' }) public env: string @Option({ @@ -36,10 +32,8 @@ export class ServeCommand extends BaseCommand { } public async handle(): Promise { - if (this.env !== '') { - process.env.APP_ENV = this.env - process.env.NODE_ENV = this.env - } + process.env.APP_ENV = this.env + process.env.NODE_ENV = this.env const entrypoint = Config.get( 'rc.commands.serve.entrypoint', diff --git a/src/commands/TestCommand.ts b/src/commands/TestCommand.ts index 20b25c2..240198f 100644 --- a/src/commands/TestCommand.ts +++ b/src/commands/TestCommand.ts @@ -11,11 +11,7 @@ import { Module } from '@athenna/common' import { Option, BaseCommand, Commander } from '@athenna/artisan' export class TestCommand extends BaseCommand { - @Option({ - signature: '-e, --env ', - description: 'Change the environment where your tests wil run.', - default: 'test' - }) + @Option({ signature: '--env ' }) public env: string public static signature(): string { @@ -47,10 +43,8 @@ export class TestCommand extends BaseCommand { } public async handle(): Promise { - if (this.env !== '') { - process.env.APP_ENV = this.env - process.env.NODE_ENV = this.env - } + process.env.APP_ENV = this.env || 'test' + process.env.NODE_ENV = this.env || 'test' const entrypoint = Config.get( 'rc.commands.test.entrypoint', diff --git a/src/ignite/Ignite.ts b/src/ignite/Ignite.ts index 9b73e0f..7dae38c 100644 --- a/src/ignite/Ignite.ts +++ b/src/ignite/Ignite.ts @@ -20,6 +20,7 @@ import { EnvHelper, Rc } from '@athenna/config' import { isAbsolute, resolve } from 'node:path' import type { ReplImpl } from '#src/repl/ReplImpl' import { Console } from '#src/applications/Console' +import { CommanderHandler } from '@athenna/artisan' import { LoadHelper } from '#src/helpers/LoadHelper' import { Log, LoggerProvider } from '@athenna/logger' import { Repl as ReplApp } from '#src/applications/Repl' @@ -82,6 +83,8 @@ export class Ignite { this.registerItselfToTheContainer() this.setApplicationSignals() + CommanderHandler.reconstruct() + return this } catch (err) { await this.handleError(err)