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

feat: make:factory command + --factory flag to make:model #837

Merged
merged 5 commits into from
May 7, 2022

Conversation

Julien-R44
Copy link
Member

Proposed changes

  • Adds the make:factory command.
  • Adds the --factory flag to make:model
Usage: make:factory <model>

Arguments
  model                The name of the model

Flags
  --model-path string  The path to the model
  -e, --exact boolean  Create the factory with the exact name as provided 

node ace make:factory Client gives :

Destination : database/factories/ClientFactory.ts

import Client from 'App/Models/Client'
import Factory from '@ioc:Adonis/Lucid/Factory'

export default Factory.define(Client, ({ faker }) => {
  return {
    //
  }
})

In the case of a nested model ( let's stay Client model is stored in App/Models/Feature/Client, then :
node ace make:factory Feature/Client gives :

Destination: database/factories/ClientFactory.ts

import Client from 'App/Models/Test/Client'
import Factory from '@ioc:Adonis/Lucid/Factory'
...

The import path to the model used in the top of the factory stub can be customized using the --model-path flag :

node ace make:factory ClientFactory --model-path=My/Nested/Model/Client
or
node ace make:factory ClientFactory --model-path=App/Models/My/Nested/Model/Client

Gives:

import Client from 'App/Models/My/Nested/Model/Client'
import Factory from '@ioc:Adonis/Lucid/Factory'
....

node ace make:model MySuperModel -fcm
Gives :

CREATE: app\Models\MySuperModel.ts
CREATE: database\migrations\1651934462987_my_super_models.ts
CREATE: app\Controllers\Http\MySuperModelController.ts
CREATE: database\factories\MySuperModelFactory.ts

@thetutlage thetutlage self-requested a review May 7, 2022 15:16
@thetutlage thetutlage added the Type: Feature Request Request to add a new feature to the package label May 7, 2022
Copy link
Member

@thetutlage thetutlage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks polished 💅

@thetutlage thetutlage merged commit bd22c96 into adonisjs:develop May 7, 2022
@Julien-R44 Julien-R44 deleted the feat/make-factory branch May 7, 2022 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Request Request to add a new feature to the package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants