Skip to content

Commit

Permalink
feat(cli): allow us to generate a controller & migration at the same …
Browse files Browse the repository at this point in the history
…time (#526)
  • Loading branch information
RomainLanz authored Sep 21, 2020
1 parent 0fc3e23 commit 3d06be2
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion commands/MakeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { join } from 'path'
import { BaseCommand, args } from '@adonisjs/ace'
import { BaseCommand, args, flags } from '@adonisjs/ace'

export default class MakeModel extends BaseCommand {
public static commandName = 'make:model'
Expand All @@ -20,6 +20,26 @@ export default class MakeModel extends BaseCommand {
@args.string({ description: 'Name of the model class' })
public name: string

/**
* Defines if we generate the migration for the model.
*/
@flags.boolean({
name: 'migration',
alias: 'm',
description: 'Generate the migration for the model',
})
public migration: boolean

/**
* Defines if we generate the controller for the model.
*/
@flags.boolean({
name: 'controller',
alias: 'c',
description: 'Generate the controller for the model',
})
public controller: boolean

/**
* Execute command
*/
Expand All @@ -35,6 +55,14 @@ export default class MakeModel extends BaseCommand {
.useMustache()
.appRoot(this.application.cliCwd || this.application.appRoot)

if (this.migration) {
this.kernel.exec('make:migration', [this.name])
}

if (this.controller) {
this.kernel.exec('make:controller', [this.name, '--resource'])
}

await this.generator.run()
}
}

0 comments on commit 3d06be2

Please sign in to comment.