Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(npm): update dependencies #140

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down Expand Up @@ -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",
Expand Down
53 changes: 15 additions & 38 deletions src/commands/MakeMigrationCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -17,8 +17,6 @@ export class MakeMigrationCommand extends BaseCommand {
})
public name: string

public tableName: string

public static signature(): string {
return 'make:migration'
}
Expand All @@ -37,23 +35,34 @@ 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,
namePlural,
namePascal,
namePluralCamel,
namePluralPascal,
tableName: this.tableName
tableName
})
.template('migration')
.make()
Expand All @@ -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
}
}
45 changes: 7 additions & 38 deletions src/commands/MakeModelCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,55 +27,25 @@ 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()

this.logger.success(
`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}`
}
}
34 changes: 7 additions & 27 deletions src/commands/MakeSeederCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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
}
}
2 changes: 2 additions & 0 deletions tests/unit/commands/MakeMigrationCommandTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]')
Expand Down
Loading