From f185359a6307e10cefff673a974122a695a5d16c Mon Sep 17 00:00:00 2001
From: jlenon7 <lenonSec7@gmail.com>
Date: Tue, 16 Jan 2024 00:10:08 +0000
Subject: [PATCH] chore(npm): update dependencies

---
 package-lock.json                             | 12 ++---
 package.json                                  |  4 +-
 src/commands/MakeMigrationCommand.ts          | 53 ++++++-------------
 src/commands/MakeModelCommand.ts              | 45 +++-------------
 src/commands/MakeSeederCommand.ts             | 34 +++---------
 .../unit/commands/MakeMigrationCommandTest.ts |  2 +
 6 files changed, 39 insertions(+), 111 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index ffce954..b1117cf 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,19 +1,19 @@
 {
   "name": "@athenna/database",
-  "version": "4.31.0",
+  "version": "4.33.0",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "@athenna/database",
-      "version": "4.31.0",
+      "version": "4.33.0",
       "license": "MIT",
       "dependencies": {
         "@faker-js/faker": "^8.3.0",
         "fast-deep-equal": "^3.1.3"
       },
       "devDependencies": {
-        "@athenna/artisan": "^4.28.0",
+        "@athenna/artisan": "^4.30.0",
         "@athenna/common": "^4.27.0",
         "@athenna/config": "^4.12.0",
         "@athenna/ioc": "^4.13.0",
@@ -84,9 +84,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",
diff --git a/package.json b/package.json
index bc55a43..ea62ae0 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@athenna/database",
-  "version": "4.32.0",
+  "version": "4.33.0",
   "description": "The Athenna database handler for SQL/NoSQL.",
   "license": "MIT",
   "author": "João Lenon <lenon@athenna.io>",
@@ -73,7 +73,7 @@
     "fast-deep-equal": "^3.1.3"
   },
   "devDependencies": {
-    "@athenna/artisan": "^4.28.0",
+    "@athenna/artisan": "^4.30.0",
     "@athenna/common": "^4.27.0",
     "@athenna/config": "^4.12.0",
     "@athenna/ioc": "^4.13.0",
diff --git a/src/commands/MakeMigrationCommand.ts b/src/commands/MakeMigrationCommand.ts
index 2a7eb5c..5cd0cb1 100644
--- a/src/commands/MakeMigrationCommand.ts
+++ b/src/commands/MakeMigrationCommand.ts
@@ -7,8 +7,8 @@
  * file that was distributed with this source code.
  */
 
+import { sep } from 'node:path'
 import { Path, String } from '@athenna/common'
-import { sep, resolve, isAbsolute } from 'node:path'
 import { BaseCommand, Argument } from '@athenna/artisan'
 
 export class MakeMigrationCommand extends BaseCommand {
@@ -17,8 +17,6 @@ export class MakeMigrationCommand extends BaseCommand {
   })
   public name: string
 
-  public tableName: string
-
   public static signature(): string {
     return 'make:migration'
   }
@@ -37,15 +35,26 @@ export class MakeMigrationCommand extends BaseCommand {
     const namePluralCamel = String.toCamelCase(String.pluralize(this.name))
     const namePluralPascal = String.toPascalCase(String.pluralize(this.name))
 
-    this.tableName = String.pluralize(
+    const destination = Config.get(
+      'rc.commands.make:migration.destination',
+      Path.migrations()
+    )
+
+    const tableName = String.pluralize(
       namePascal
         .replace('Migration', '')
         .replace('Migrations', '')
         .toLowerCase()
     )
 
+    let [date, time] = new Date().toISOString().split('T')
+
+    date = date.replace(/-/g, '_')
+    time = time.split('.')[0].replace(/:/g, '')
+
     const file = await this.generator
-      .path(this.getFilePath())
+      .fileName(`${sep}${date}_${time}_create_${tableName}_table`)
+      .destination(destination)
       .properties({
         nameUp,
         nameCamel,
@@ -53,7 +62,7 @@ export class MakeMigrationCommand extends BaseCommand {
         namePascal,
         namePluralCamel,
         namePluralPascal,
-        tableName: this.tableName
+        tableName
       })
       .template('migration')
       .make()
@@ -62,36 +71,4 @@ export class MakeMigrationCommand extends BaseCommand {
       `Migration ({yellow} "${file.name}") successfully created.`
     )
   }
-
-  /**
-   * Get the file path where it will be generated.
-   */
-  private getFilePath(): string {
-    let [date, time] = new Date().toISOString().split('T')
-
-    date = date.replace(/-/g, '_')
-    time = time.split('.')[0].replace(/:/g, '')
-
-    const name = `${sep}${date}_${time}_create_${
-      this.tableName
-    }_table.${Path.ext()}`
-
-    return this.getDestinationPath().concat(name)
-  }
-
-  /**
-   * Get the destination path for the file that will be generated.
-   */
-  private getDestinationPath(): string {
-    let destination = Config.get(
-      'rc.commands.make:migration.destination',
-      Path.migrations()
-    )
-
-    if (!isAbsolute(destination)) {
-      destination = resolve(Path.pwd(), destination)
-    }
-
-    return destination
-  }
 }
diff --git a/src/commands/MakeModelCommand.ts b/src/commands/MakeModelCommand.ts
index 19edd57..2b955bd 100644
--- a/src/commands/MakeModelCommand.ts
+++ b/src/commands/MakeModelCommand.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 MakeModelCommand extends BaseCommand {
@@ -28,15 +27,20 @@ export class MakeModelCommand extends BaseCommand {
   public async handle(): Promise<void> {
     this.logger.simple('({bold,green} [ MAKING MODEL ])\n')
 
+    const destination = Config.get(
+      'rc.commands.make:model.destination',
+      Path.models()
+    )
     const file = await this.generator
-      .path(this.getFilePath())
+      .fileName(this.name)
+      .destination(destination)
       .template('model')
       .setNameProperties(true)
       .make()
 
     this.logger.success(`Model ({yellow} "${file.name}") successfully created.`)
 
-    const importPath = this.getImportPath(file.name)
+    const importPath = this.generator.getImportPath()
 
     await this.rc.pushTo('models', importPath).save()
 
@@ -44,39 +48,4 @@ export class MakeModelCommand extends BaseCommand {
       `Athenna RC updated: ({dim,yellow} [ models += "${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:model.destination',
-      Path.models()
-    )
-
-    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/MakeSeederCommand.ts b/src/commands/MakeSeederCommand.ts
index 9d858f6..e0b501f 100644
--- a/src/commands/MakeSeederCommand.ts
+++ b/src/commands/MakeSeederCommand.ts
@@ -7,8 +7,7 @@
  * file that was distributed with this source code.
  */
 
-import { Path, String } from '@athenna/common'
-import { sep, resolve, isAbsolute } from 'node:path'
+import { Path } from '@athenna/common'
 import { BaseCommand, Argument } from '@athenna/artisan'
 
 export class MakeSeederCommand extends BaseCommand {
@@ -28,9 +27,13 @@ export class MakeSeederCommand extends BaseCommand {
   public async handle(): Promise<void> {
     this.logger.simple('({bold,green} [ MAKING SEEDER ])\n')
 
+    const destination = Config.get(
+      'rc.commands.make:seeder.destination',
+      Path.seeders()
+    )
     const file = await this.generator
-      .path(this.getFilePath())
-      .properties({ nameTable: String.pluralize(this.name) })
+      .fileName(this.name)
+      .destination(destination)
       .template('seeder')
       .setNameProperties(true)
       .make()
@@ -39,27 +42,4 @@ export class MakeSeederCommand extends BaseCommand {
       `Seeder ({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:seeder.destination',
-      Path.seeders()
-    )
-
-    if (!isAbsolute(destination)) {
-      destination = resolve(Path.pwd(), destination)
-    }
-
-    return destination
-  }
 }
diff --git a/tests/unit/commands/MakeMigrationCommandTest.ts b/tests/unit/commands/MakeMigrationCommandTest.ts
index fb98df6..f5ed898 100644
--- a/tests/unit/commands/MakeMigrationCommandTest.ts
+++ b/tests/unit/commands/MakeMigrationCommandTest.ts
@@ -17,6 +17,8 @@ export default class MakeMigrationCommandTest extends BaseCommandTest {
     const output = await command.run('make:migration TestMigration')
     const file = new Folder(Path.fixtures('storage/database/migrations')).loadSync().files[0]
 
+    console.log(output.output)
+
     output.assertSucceeded()
     assert.isTrue(file.fileExists)
     output.assertLogged('[ MAKING MIGRATION ]')